I am having some difficulties when testing components that use React-Bootstrap with Mocha, Chai, and Enzyme. Hopefully someone can key me into what I am doing wrong.
When testing components that do not use React-Bootstrap, I notice that the output is raw html() where as when testing React-Bootstrap I am only getting back the component and not raw html (). This is causing a huge headache when trying to test. This happens if I use shallow, mount, and render.
If anyone has a clue as to why I cannot get raw html when testing that would be greatly appreciated! I have included some code to show what I am talking about.
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');
});
})