React-BootstrapをMocha、Chai、およびEnzymeで使用するコンポーネントをテストする際に、いくつかの問題があります。 うまくいけば、誰かが私が間違っていることを私に知らせることができます。問題React-Bootstrapコンポーネントのテスト
React-Bootstrapを使用しないコンポーネントをテストすると、React-Bootstrapをテストするときのraw html()の出力がraw html()ではなくコンポーネントを返すことに気付きました。これは、テストしようとすると大きな頭痛を引き起こしています。これは、shallow、mount、renderを使用すると発生します。
誰かが私が生のHTMLを得ることができない理由についての手掛かりを持っていれば、それは大いに評価されるでしょう! 私が話していることを示すためにいくつかのコードが含まれています。
ReactTest.jsx
import React from 'react';
const ReactTest =() => (
<div>
<button>ReactTest</button>
</div>
);
export default ReactTest;
ReactBootstrapTest.jsx
import React from 'react';
import { Button } from 'react-bootstrap';
const ReactBootstrapTest =() => (
<div>
<Button>ReactBootstrapTest</Button>
</div>
);
export default ReactBootstrapTest;
reactTest.js
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import ReactTest from '../../../../../../components/ReactTest';
import ReactBootstrapTest from '../../../../../../components/ReactBootstrapTest';
const reactTestEnzymeWrapper =() => (
shallow(<ReactTest />)
);
const reactBootstrapTestEnzymeWrapper =() => (
shallow(<ReactBootstrapTest />)
);
describe.only('ReactTest',() => {
it('should output debug',() => {
const reactTest = reactTestEnzymeWrapper();
console.log('ReactTest', reactTest.debug());
});
it('should find the <button>',() => {
const reactButton = reactTestEnzymeWrapper().find('button');
expect(reactButton.at(0).text()).to.equal('ReactTest');
});
});
describe.only('ReactBootstrapTest',() => {
it('should output debug',() => {
const reactBootstrapTest = reactBootstrapTestEnzymeWrapper();
console.log('ReactBootstrapTest', reactBootstrapTest.debug());
});
it('should find the <button>',() => {
const bootstrapButton = reactBootstrapTestEnzymeWrapper().find('button');
expect(bootstrapButton.at(0).text()).to.equal('ReactBoostrapTest');
});
})
テストから実際の出力を投稿できますか? –