I have a React view that interacts with the repository . I have successfully tested views and stores separately, but not in combination.
I followed the structure described here , but got a TypeError . It seems that Jest is trying to register the repository as a component, even if I use dontMock.
Using Jest CLI v0.2.0
PASS __tests__/unit/spec/stores/ViewStore-spec.js (0.248s)
FAIL __tests__/unit/spec/components/View-spec.react.js (0.942s)
undefined
● View › it defaults to zero unread
- TypeError: /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/components/View.react.js: /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/stores/ViewStore.js: Cannot call method 'register' of undefined
at /Users/matnorri/dev/projects/matnorri/web-client/src/app/scripts/stores/ViewStore.js:43:31
at Object.runContentWithLocalBindings (/Users/matnorri/dev/projects/matnorri/web-client/node_modules/jest-cli/src/lib/utils.js:357:17)
...
I have included what, in my opinion, is the corresponding code below, but if necessary can provide it in full.
View Jest Test
jest.dontMock('../../../../src/app/scripts/components/View.react');
jest.dontMock('../../../../src/app/scripts/stores/ViewStore');
describe('View', function() {
var React;
var TestUtils;
var ViewComponent;
var View;
beforeEach(function() {
React = require('react/addons');
TestUtils = React.addons.TestUtils;
ViewComponent =
require('../../../../src/app/scripts/components/View.react');
View = TestUtils.renderIntoDocument(<ViewComponent />);
});
it('defaults to zero unread', function() {
View._toString = jest.genMockFunction();
View._onChange();
expect(View.state.unread).toBe(0);
});
});
Thank!