Jest With Enzyme

The Enzyme package, from Airbnb, appears to solve some of the problems I ran into when using plain Jest.

“Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components’ output”.

For example, with Enzyme, I was able to use a .click method much like RSpec offers.

const mockCallBack = jest.fn();
const page = shallow((<Headlines articles={[myArticle]} djiaValue={decimalValue} djiaChange={decimalValue} refreshTime={new Date()} refreshHeadlines={mockCallback} userLocale={myUser.locale}/>));
page.find('[title="Refresh headlines"]').simulate('click');
expect(mockCallBack.mock.calls.length).toEqual(1);

 

Posted in JavaScript, Testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.