酶不将上下文传递给Travis上的渲染组件

ski*_*iff 5 travis-ci reactjs react-router enzyme

我有一个特殊的情况,一直在发生.我一直在用Mocha,Enzyme,Chai和nyc测试我的React应用程序.

在我的机器上,一切都完美地完成了我的所有6次测试的6次测试.其中2个测试是从酶调用mount的测试:

it('Should contain my name in the text', () => {
    const context = { router: { } };
    const footer = mount(<Footer />, context);
    console.log(footer);
    expect(footer.text()).to.contain('Myname');
  });
  it('Should contain a link to the copyright page', () => {
    const footer = mount(<Footer />);
    expect(footer.find('a').prop('href')).to.equal('/Copyright');
  });
Run Code Online (Sandbox Code Playgroud)

在我的本地机器上运行正常.当我的测试在Travis-ci上运行时,这两个测试失败的原因如下:

Warning: Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`.
in Link (created by Unknown)
in footer (created by Unknown)
in Unknown (created by Unknown)
in Unknown
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,我很困惑,为什么在我的本地机器上没有失败.我很乐意帮助我解决这个问题.

我目前使用的软件版本:

"chai": "^3.5.0",
"enzyme": "^2.6.0",
"mocha": "^3.1.0",
"react-dom": "15.4.0",
"react": "15.4.0",
"react-router": "next" #this is version v4
Run Code Online (Sandbox Code Playgroud)