- Mastering React Test:Driven Development
- Daniel Irvine
- 192字
- 2021-06-24 14:45:02
Bringing in React and Babel
Let's install React. That's actually two packages:
npm install --save react react-dom
React makes heavy use of JavaScript XML (JSX), which we need Babel to transpile for us. Babel also transpiles our modern ES6 and ES7 constructs for us.
Thankfully, Jest already includes Babel, so we just need to install presets and plugins:
npm install --save-dev @babel/preset-env @babel/preset-react
npm install --save-dev @babel/plugin-transform-runtime
npm install --save @babel/runtime
A Babel preset is a set of plugins. Each plugin enables a specific feature of the ECMAScript standards, or a preprocessor such as JSX.
The env preset brings in essentially everything possible. It should really be configured with target execution environments. See the Further reading section at the end of this chapter for more information.
We need to enable the packages we've just installed. Create a new file, .babelrc, and add the following:
{
"presets": ["@babel/env", "@babel/react"],
"plugins": ["@babel/transform-runtime"]
}
With that, you're all set to write some tests. You may wish to check in at this point.
- Boost.Asio C++ Network Programming(Second Edition)
- JavaScript百煉成仙
- FuelPHP Application Development Blueprints
- HTML5 Mobile Development Cookbook
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Multithreading in C# 5.0 Cookbook
- C和C++游戲趣味編程
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- 軟件測(cè)試實(shí)用教程
- iOS自動(dòng)化測(cè)試實(shí)戰(zhàn):基于Appium、Python與Pytest
- Learning Node.js for .NET Developers
- Apache Camel Developer's Cookbook
- Troubleshooting Citrix XenApp?
- Managing Microsoft Hybrid Clouds
- QPanda量子計(jì)算編程