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

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.

主站蜘蛛池模板: 兰坪| 开封县| 长白| 承德县| 会东县| 阿瓦提县| 藁城市| 无棣县| 庆安县| 尚义县| 大英县| 安多县| 安岳县| 利津县| 太仆寺旗| 东乌| 阿城市| 沁水县| 西昌市| 曲阜市| 同德县| 宜都市| 攀枝花市| 许昌县| 息烽县| 长寿区| 兴山县| 宝应县| 依兰县| 明光市| 富裕县| 青海省| 瑞丽市| 桑日县| 名山县| 普陀区| 台中市| 丘北县| 上虞市| 陵川县| 慈利县|