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

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.

主站蜘蛛池模板: 财经| 林甸县| 合作市| 突泉县| 长治市| 察雅县| 惠东县| 宣城市| 牟定县| 安达市| 阿拉尔市| 余干县| 开原市| 大足县| 津南区| 安徽省| 泸溪县| 西盟| 淅川县| 那曲县| 石楼县| 汤原县| 永修县| 万全县| 宜兰县| 东海县| 铜梁县| 涟源市| 达州市| 渝中区| 贺兰县| 温泉县| 明星| 惠水县| 合川市| 枞阳县| 华亭县| 古蔺县| 水城县| 博白县| 洪洞县|