gpt4 book ai didi

javascript - '命令未找到 : jest'

转载 作者:行者123 更新时间:2023-12-03 12:59:54 25 4
gpt4 key购买 nike

我有一个像这样的测试文件:(我正在使用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();
})

和一个package.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时,我得到:

command not found: jest

enter image description here

但是 jest 已安装。

最佳答案

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

更新:较新版本的yarn将解析节点模块bin脚本,因此您也可以只运行yarn jest {cmd},它应该可以工作。

关于javascript - '命令未找到 : jest',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50138532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com