官术网_书友最值得收藏!

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.

The following information is accurate for Babel 7. If you're using a later version, you may need to adjust the installation instructions accordingly.

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.

主站蜘蛛池模板: 德格县| 拜泉县| 阳春市| 丘北县| 菏泽市| 罗定市| 师宗县| 上高县| 喀什市| 子洲县| 阿克| 扎赉特旗| 衡阳市| 长顺县| 大冶市| 西乌珠穆沁旗| 威海市| 昌宁县| 福泉市| 丰县| 德阳市| 毕节市| 隆安县| 泸西县| 丰宁| 福贡县| 巩义市| 克拉玛依市| 马山县| 盘锦市| 岳阳市| 福贡县| 张家口市| 合作市| 临泉县| 尖扎县| 伽师县| 哈密市| 武乡县| 凤山市| 大同县|