Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Testing Meteor React Component which is using withTracker in Container (meteor/react-meteor-data)

I am testing component using withTracker in its container.

An error happens:

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

I think I haven't mock the react-meteor-data/withTracker yet. Can someone tell me how to mock it? Or is there any solution for this?

like image 886
Long Đặng Avatar asked Oct 28 '22 22:10

Long Đặng


1 Answers

Inspired by How is Meteor's withTracker function executed differently than the former reactive container function createContainer? I managed to upgrade the tests from createContainer to withTracker using the following:

In your mocked react-meteor-data.js file.

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

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

Then export withTracker instead of createContainer.

like image 67
Abido Avatar answered Nov 09 '22 11:11

Abido