我有一种特殊的情况已经发生。我一直在用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');
});
在我的本地机器上运行正常。当我的测试在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
如果情况确实如此,为什么我的本地机器没有失败,我感到非常困惑。我很乐意帮助我解决这个问题。
我目前使用的软件版本:
"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