Ale*_*dro 26 javascript reactjs jestjs
我有一个像这样的测试文件:(我正在使用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();
})
Run Code Online (Sandbox Code Playgroud)
和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"
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行"jest --updateSnapshot"时,我得到:
command not found: jest
Run Code Online (Sandbox Code Playgroud)
但是安装了jest.
Cap*_*ion 43
Jest
已安装,但可能在您的./node_modules/.bin
目录中.您可以将它附加到您的命令./node_modules/.bin/jest --updateSnapshot
.既然你已经拥有jest
了一个scripts
命令,你package.json
也可以运行它npm test -- --updateSnapshot
.npm会自动添加./node_modules/.bin
到您的路径中.
El *_*mza 16
你需要以这种方式运行它:
./node_modules/.bin/jest
Run Code Online (Sandbox Code Playgroud)
或跑 npm test
Wil*_*ana 13
解决该错误的一种方法是使用“npx”命令。
npx jest --version
npx jest --init
Run Code Online (Sandbox Code Playgroud)
小智 8
尝试使用命令
npx jest <folder>
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题。我尝试了多种解决方案并且有效。
我还安装了 jest CLI
您可以在 shell 中使用此命令来安装它
npm install --save-dev jest-cli
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题。我通过在全球范围内安装笑话来修复它。
npm install -g jest
Run Code Online (Sandbox Code Playgroud)
安装Jest命令行界面(Jest CLI):
npm install --save-dev jest-cli
Run Code Online (Sandbox Code Playgroud)
然后运行jest命令。在Windows 10上由docker在Linux实例中为我工作。
归档时间: |
|
查看次数: |
26083 次 |
最近记录: |