【问题标题】:Jest in Meteor?在流星中开玩笑?
【发布时间】:2017-12-19 11:18:07
【问题描述】:

我想在 Meteor 客户端应用程序中运行 Jest 测试用例以对 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 不是函数

我不知道如何选择开玩笑的expect 版本来使用toMatchSnapshot 方法

请帮忙

【问题讨论】:

  • 你的笑话版本是什么?为了能够使用 toMatchSnapshot,它必须至少是 14 版。
  • "jest": "^20.0.4"

标签: reactjs meteor mocha.js chai jestjs


【解决方案1】:

您无法使用 practicalmeteor:mocha 驱动程序包运行 Jest 测试。该软件包使用 Mocha 运行您的测试(而 Mocha 无法识别 .toMatchSnapshot()

通过安装 Jest cli,我在运行 Jest 测试方面取得了名义上的成功...

npm i -g jest

...并在不通过 Meteor 的情况下从命令行运行测试。

当然,您需要模拟 Meteor 的依赖项。为此,我使用了jest-meteor-stubs,但事实证明,手动 stub 是一种抑制。

在有人为 Meteor 编写官方 Jest 驱动程序包之前,最好还是坚持使用 Mocha。

【讨论】:

    猜你喜欢
    • 2017-01-25
    • 2019-04-19
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 1970-01-01
    • 2021-06-20
    • 1970-01-01
    相关资源
    最近更新 更多