2016-08-01 63 views
0
- TypeError: Cannot read property 'addStyleRule' of undefined 
    at Object.<anonymous> (node_modules/plotly.js/build/plotcss.js:61:15) 
    at Object.<anonymous> (node_modules/plotly.js/src/plotly.js:30:1) 
    at Object.<anonymous> (node_modules/plotly.js/src/core.js:15:14) 
    at Object.<anonymous> (node_modules/plotly.js/lib/core.js:9:18) 
    at Object.<anonymous> (node_modules/plotly.js/lib/index.js:15:12) 

    at emitTwo (events.js:106:13) 
    at process.emit (events.js:191:7) 
    at process.nextTick (internal/child_process.js:719:12) 
    at _combinedTickCallback (internal/process/next_tick.js:67:7) 
    at process._tickCallback (internal/process/next_tick.js:98:9) 

我反应过来的项目使用plotly并运行一个玩笑测试时,它是有plotly麻烦Plotly错误运行开玩笑测试时反应

我测试的代码看起来像这样:

import React from 'react' 
import ReactDOM from 'react-dom' 
import TestUtils from 'react-addons-test-utils' 

import AppBar from "./index" 
import Navigation from "../navigation/" 

// Use real modules for testing. 
jest.unmock("./index") 
jest.unmock("./brand") 

describe("AppBar",() => { 
    let component = <AppBar /> 
    let element = TestUtils.renderIntoDocument(component) 
    let node = ReactDOM.findDOMNode(element) 

    it("renders the navigation to screen",() => { 
    let el = TestUtils.findRenderedComponentWithType(element, Navigation) 
    expect(el).toBeDefined() 
    }) 
}) 

我这个嘲讽剧情与未定义错误的addStyleRule有关,但我还没有完全停止针对使用外部库的这种特殊情况需要嘲笑/取消锁定

回答

0

我结束了解密剧情库。警告它会让你的测试运行非常缓慢,因为它现在实际上正在渲染。

加成:覆盖部件道具

import Plotly from 'plotly.js' 
    import MyComponent from "./index"; 

    // Use real modules for testing. 
    jest.unmock("plotly.js"); 
    jest.unmock("./index"); 

    describe("My component does something",() => { 
    let params = { 
     display: true 
    }; 

    let ComponentMock = class extends MyComponent { 
     constructor(props) { 
     super(props); 
     this.actions = { 
      myAction: null 
     } 
     } 
    }; 
    let el = <ComponentMock params={params}/> 
    });