简体   繁体   English

npm 错误! 缺少脚本:茉莉花

[英]npm ERR! missing script: jasmine

I want to use Jasmine library to test my code, but I get an error message saying that I don't have jasmine added in the script part of package.json.我想使用 Jasmine 库来测试我的代码,但是我收到一条错误消息,说我没有在 package.json 的脚本部分添加 jasmine。 I would like to know what I need to add in the script part of package.json.我想知道我需要在 package.json 的脚本部分添加什么。

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "jest --watch",
    "cover": "jest --coverage",
    "eject": "react-scripts eject",
    "update-swagger-d-ts": "./node_modules/.bin/dtsgen src/swagger.json -o src/types/swagger.d.ts",
    "typecheck": "tsc",
    "jasmine": ""
  }

There is actually a full tutorial when it comes to working with React, and it is available as part of the official Jasmine documentation .实际上有一个关于使用 React 的完整教程,它作为Jasmine 官方文档的一部分提供。

Mimally, you will need to install ( npm install --save-dev ) the following dev depencencies,最简单的是,您需要安装( npm install --save-dev )以下开发依赖项,

  • cross-env跨环境
  • enzyme (for shallow/mount rendering)酶(用于浅层/装载渲染)
  • enzyme-adapter-react-16酶接头反应 16
  • jasmine-enzyme茉莉酵素
  • jsdom (to emulate browser within the node.js environment) jsdom(在 node.js 环境中模拟浏览器)
  • And most importantly, jasmine最重要的是,茉莉

Then you initialise jasmine by running然后你通过运行初始化茉莉花

jasmine init

The other steps regarding the configurations are available on the above tutorial, so please do look through them.上面的教程中提供了有关配置的其他步骤,因此请仔细阅读它们。

Last but not least, you may set up the test script on your package.json,最后但并非最不重要的是,您可以在 package.json 上设置测试脚本,

"scripts": {
    "jasmine": "cross-env NODE_ENV=test jasmine",
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM