I have a React view that communicates with a store. I've successfully tested views and stores separately, but not in combination.
I followed the structure documented here but received a TypeError. It looks like Jest is trying to register the store 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've included what I believe is the relevant code below, but can provide it in its entirety if necessary.
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 =
// Tried both lines with same effect.
// require('../../../../src/app/scripts/components/View.react.js');
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 you!