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

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.

主站蜘蛛池模板: 临邑县| 上饶市| 利川市| 岗巴县| 钟山县| 乌审旗| 临潭县| 安岳县| 南川市| 娄底市| 成都市| 娄底市| 上犹县| 伊川县| 阳谷县| 土默特左旗| 兴安盟| 哈密市| 大荔县| 炎陵县| 丹东市| 基隆市| 德庆县| 岑溪市| 上饶县| 二连浩特市| 和林格尔县| 扎囊县| 祁东县| 镇坪县| 宁安市| 恩平市| 多伦县| 崇左市| 兴海县| 突泉县| 虎林市| 新蔡县| 建瓯市| 南宁市| 顺义区|