- 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.
- Advanced Machine Learning with Python
- Learning Bayesian Models with R
- Internet of Things with Intel Galileo
- Functional Kotlin
- Learning Python by Building Games
- 程序設計基礎教程:C語言
- Mastering openFrameworks:Creative Coding Demystified
- C/C++程序員面試指南
- Unity 2017 Mobile Game Development
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- 案例式C語言程序設計實驗指導
- Programming Microsoft Dynamics? NAV 2015
- Python機器學習與量化投資
- AngularJS UI Development
- Python程序設計:基礎與實踐