Open ndrewr opened 7 years ago
I am hitting the same problem in a Jest test.
sorry for lately reply, I'll do some investigation.
I think I found a workaround, enzyme
and enzyme-to-json
After getting the same error, I tried this method and it worked (<PayrollReport>
uses React Bootstrap Table)
import React from 'react';
import toJson from 'enzyme-to-json';
import {shallow} from 'enzyme';
import PayrollReport from '.';
import data from './__testData__/testData';
test('PayrollReport Renders Correctly', () => {
const wrapper = shallow(<PayrollReport data={data} />);
expect(toJson(wrapper)).toMatchSnapshot();
});
The workaround didn't really help in my case, because I got snapshots only containing
My workaround uses nothing but Jest!
module.exports = 'tableHeaderColumnMock';
"jest": {
…
"moduleNameMapper": {
"TableHeaderColumn": "<rootDir>/tests/__mocks__/tableHeaderColumnMock.js"
},
…
}
Jest will be replacing all TableHeaderColumn components by tableHeaderColumnMock then, successfully rendering a reasonably well representation of the page.
First off kudos for this rather fun-to-use component :)
OK so the issue I am bumping into happens when I set up a snapshot test with Jest and react-test-renderer.
The test file is essentially:
(Note the
Table
component is just a wrapper that defines some basic BootstrapTable props.)And when running tests, I am alerted to this (partial stack trace):
which points back to this line in
TableHeaderColumn / ComponentDidMount
:Anyone else encounter this?
Am I doing something wrong? Apologies if should I be asking somewhere else on this; have been bouncing around Jest and React repos as well as here.