I am trying to run an unit test for React JS - using jest / enzyme.
The test is failing at the moment.Not really sure why, maybe i am not calling the expect(wrapper.find) correctly. Here is part of my test:
File.test.js
it('renders modal when open flag is true', () => {
const props = { isOpen: true };
const wrapper = mount(
<div id="root">
<Component {...props} />
</div>
);
wrapper.update();
expect(toJson(wrapper)).toMatchSnapshot();
expect(wrapper.find('.loa-download-header').exists()).toEqual(true);
expect(wrapper.text()).toContain(' Please enter a password.');
});
});
Here is part of File.js Shows a piece of the code that I am trying to test as an example.
render() {
return (
<Modal
<div title="Close Window" className="add-custom-field-close" onClick={() => {this.closeModal()}}><FontAwesome name='xbutton' className='fa-times' /></div>
</div>
</div>
<div className='loa-download-header-wrapper'>
<div className='loa-download-header'>
Please enter a password.
</div>
Error: expect(received).toEqual(expected)
Expected value to equal:
true
Received:
false
Any corrections on the code would be extremely helpful Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…