- typeerror: cannot read property 'addstylerule' of undefined @ object.<anonymous> (node_modules/plotly.js/build/plotcss.js:61:15) @ object.<anonymous> (node_modules/plotly.js/src/plotly.js:30:1) @ object.<anonymous> (node_modules/plotly.js/src/core.js:15:14) @ object.<anonymous> (node_modules/plotly.js/lib/core.js:9:18) @ object.<anonymous> (node_modules/plotly.js/lib/index.js:15:12) @ emittwo (events.js:106:13) @ process.emit (events.js:191:7) @ process.nexttick (internal/child_process.js:719:12) @ _combinedtickcallback (internal/process/next_tick.js:67:7) @ process._tickcallback (internal/process/next_tick.js:98:9)
my react project uses plotly , having trouble plotly when running jest test
my test code looks such:
import react 'react' import reactdom 'react-dom' import testutils 'react-addons-test-utils' import appbar "./index" import navigation "../navigation/" // use real modules testing. jest.unmock("./index") jest.unmock("./brand") describe("appbar", () => { let component = <appbar /> let element = testutils.renderintodocument(component) let node = reactdom.finddomnode(element) it("renders navigation screen", () => { let el = testutils.findrenderedcomponentwithtype(element, navigation) expect(el).tobedefined() }) })
i figure mocking plotly has addstylerule of undefined error haven't quite pinned down needs mocked/unmocked particular case of using external library
i ended unmocking plotly library. warning makes test run extremely slow since rendering.
bonus: overriding component props
import plotly 'plotly.js' import mycomponent "./index"; // use real modules testing. jest.unmock("plotly.js"); jest.unmock("./index"); describe("my component something", () => { let params = { display: true }; let componentmock = class extends mycomponent { constructor(props) { super(props); this.actions = { myaction: null } } }; let el = <componentmock params={params}/> });
Comments
Post a Comment