javascript – Jest测试Meteor React组件,它在容器中使用withTracker(流星/反应流星数据)

我正在其容器中使用withTracker测试组件.

发生错误:

TypeError: (0 , _reactMeteorData.withTracker) is not a function.

我想我还没有嘲笑react-meteor-data / withTracker.有人能告诉我如何嘲笑它吗?或者有什么解决方案吗?

最佳答案 受到
How is Meteor’s withTracker function executed differently than the former reactive container function createContainer?的启发

我设法使用以下方法将测试从createContainer升级到withTracker:

在你的模拟react-meteor-data.js文件中.

const createContainer = jest.fn((options = {}, component) => component );

const withTracker = jest.fn(Op => jest.fn(C => createContainer(Op, C)));

然后导出withTracker而不是createContainer.

点赞