我在嘗試對使用react-highcharts
的React組件進行一些基本的煙霧測試時遇到了問題。我的基本玩笑典型的方法產生一個錯誤:React Highcharts Jest測試錯誤:`InvalidCharacterError`
it('renders without crashing',() => {
const div = document.createElement('div');
render(<MyComponent {...props} />, div);
});
—>
InvalidCharacterError
at exports.name (node_modules/jest-environmentjsdom/node_modules/jsdom/lib/jsdom/living/helpers/validate-names.js:10:11)
at a.createElement (node_modules/highcharts/highcharts.js:17:221)
at Object.a.svg.z.init (node_modules/highcharts/highcharts.js:92:155)
at Object.z.createElement (node_modules/highcharts/highcharts.js:63:3)
at Object.a.svg.z.createElement (node_modules/highcharts/highcharts.js:107:525)
at Object.a.svg.z.init (node_modules/highcharts/highcharts.js:101:44)
at Object.a.svg.a.VMLRenderer.B (node_modules/highcharts/highcharts.js:109:320)
at Object.N.getContainer (node_modules/highcharts/highcharts.js:252:329)
從一些interwebs偵探,似乎這是渲染<ReactHighcharts />
作爲子組件的固有問題。如何避免重組我的組件或使測試複雜化?
爲什麼不在這裏使用reactTestUtils? 'const myComponent = ReactTestUtils.renderIntoDocument( );'這種方式你有組件的引用。 aka ..'myComponent.state'將是該組件的狀態 –