找不到命令:开玩笑 [英] command not found: jest

查看:418
本文介绍了找不到命令:开玩笑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的测试文件:(我正在使用create-react-app)

I have a test file like so: (I am using create-react-app)

import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/Calculator';

import { getAction, getResult } from './actions/'

import {shallow} from 'enzyme';
import toJson from 'enzyme-to-json';

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

it('renders without crashing', () => {
  const wrapper = shallow(<App />)
  expect(toJson(wrapper)).toMatchSnapshot();
});

it('displays the choosen operator', () => {
  const action = {
      type: 'GET_ACTION',
      operator: '+'
    };
  expect(getAction("+")).toEqual(action)
})

it('displays the typed digit', () => {
  const action = {
    type: 'GET_RESULT',
    n: 3
  };
  expect(getResult(3)).toEqual(action);
})

it('checks that the clickevent for getNumber is called',() => {
  const clickEvent = jest.fn();
  const p = shallow(<p data-n="1" onClick={clickEvent}>1</p>)
  p.simulate('click')
  expect(clickEvent).toBeCalled();
})

和一个packaje.json:

and a packaje.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    // "test": "react-scripts test --env=jsdom",
    "test": "jest",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "enzyme-to-json": "^3.3.3",
    "jest": "^22.4.3"
  }
}

当我运行"jest --updateSnapshot"时,我得到:

when I run "jest --updateSnapshot" I get:

command not found: jest

但是安装了笑话.

推荐答案

Jest已安装,但可能在您的./node_modules/.bin目录中.您可以将其附加到命令./node_modules/.bin/jest --updateSnapshot.由于您已经在package.json中将jest作为scripts命令,因此您也可以使用npm test -- --updateSnapshot运行它. npm自动将./node_modules/.bin添加到您的路径.

Jest is installed, but is likely in your ./node_modules/.bin directory. You can append that to your command ./node_modules/.bin/jest --updateSnapshot. Since you already have jest as a scripts command in your package.json you can also run it with npm test -- --updateSnapshot. npm automatically adds ./node_modules/.bin to your path.

这篇关于找不到命令:开玩笑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆