Created
February 22, 2018 22:26
-
-
Save herbowicz/2d2c698b5683248408404e61137d4264 to your computer and use it in GitHub Desktop.
Jest and Enzyme - shallow rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const Bar = (props) => ( | |
<div className="hi"> | |
This is Bar | |
</div> | |
); | |
export default Bar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Bar from './Bar'; | |
const Foo = (props) => ( | |
<div className="hi"> | |
<Bar/> | |
</div> | |
); | |
export default Foo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {mount, shallow} from 'enzyme'; | |
import Foo from '../Foo'; | |
import Bar from '../Bar'; | |
describe('A suite', function() { | |
it('has one child component', function() { | |
expect(mount(<Foo/>).children.length).toEqual(1); | |
}); | |
it('has one class "hi"', function() { | |
expect(mount(<Foo/>).find('.hi').length).toBe(1); // test fails with mount | |
}); | |
it('has one class "hi"', function() { | |
expect(shallow(<Foo/>).find('.hi').length).toBe(1); // test passed with shallow rendering | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment