是在流星吗?
Jest in Meteor?
我想 运行 在我的 Meteor 客户端应用程序中测试 React 组件的快照测试用例。
安装包:
npm i --save-dev jest react-test-renderer
我只是简单地写了这样的东西:
import React from 'react';
import renderer from 'react-test-renderer';
import { expect } from 'meteor/practicalmeteor:chai';
import CoolComponent from '../some/where';
if (Meteor.isClient) {
it('renders correctly', () => {
const tree = renderer.create(<CoolComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
}
运行 测试用例:
meteor test --driver-package practicalmeteor:mocha
并得到这个错误:
TypeError: expect(...).toMatchSnapshot is not a function
我不确定如何选择 expect
的笑话版本来使用 toMatchSnapshot
方法
请帮忙
您不能 运行 使用 practicalmeteor:mocha
驱动程序包进行 Jest 测试。该包 运行 是您使用 Mocha 进行的测试(而 Mocha 无法识别 .toMatchSnapshot()
。
我通过安装 Jest 客户端进行了 Jest 测试,取得了名义上的成功 运行...
npm i -g jest
...和 运行 从命令行进行测试而不通过 Meteor。
当然,您需要模拟 Meteor 的依赖项。为此,我使用了 jest-meteor-stubs
,但事实证明,手动对所有内容进行存根是有抑制作用的。
在有人为 Meteor 编写官方 Jest 驱动程序包之前,您最好还是坚持使用 Mocha。
我想 运行 在我的 Meteor 客户端应用程序中测试 React 组件的快照测试用例。
安装包:
npm i --save-dev jest react-test-renderer
我只是简单地写了这样的东西:
import React from 'react';
import renderer from 'react-test-renderer';
import { expect } from 'meteor/practicalmeteor:chai';
import CoolComponent from '../some/where';
if (Meteor.isClient) {
it('renders correctly', () => {
const tree = renderer.create(<CoolComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
}
运行 测试用例:
meteor test --driver-package practicalmeteor:mocha
并得到这个错误:
TypeError: expect(...).toMatchSnapshot is not a function
我不确定如何选择 expect
的笑话版本来使用 toMatchSnapshot
方法
请帮忙
您不能 运行 使用 practicalmeteor:mocha
驱动程序包进行 Jest 测试。该包 运行 是您使用 Mocha 进行的测试(而 Mocha 无法识别 .toMatchSnapshot()
。
我通过安装 Jest 客户端进行了 Jest 测试,取得了名义上的成功 运行...
npm i -g jest
...和 运行 从命令行进行测试而不通过 Meteor。
当然,您需要模拟 Meteor 的依赖项。为此,我使用了 jest-meteor-stubs
,但事实证明,手动对所有内容进行存根是有抑制作用的。
在有人为 Meteor 编写官方 Jest 驱动程序包之前,您最好还是坚持使用 Mocha。