Member-only story
What is jest and Enzyme. How it can help us writing test cases for our react js component.
Recently i started working on React, As we follow TDD , i have to learn jest and Enzyme to write my first unit test case.
Jest is a javascript testing framework , created by developers who created react. Jest is not limited to react framework, it is general purpose javascript testing framework. but as it is from react developers more inclination is there. Enzyme is another framework which is specifically designed to test react components. Enzyme, created by Airbnb, adds some great additional utility methods for rendering a component (or multiple components), finding elements, and interacting with elements.
So to test your react app or write your first test , you have to learn jest and Enzyme.
Jest is a simple framework. it has two global object knows as describe and it . As name suggest describe , describe about the test and it is used to test.
Simple example of one test is
describe('Testing sum and minus', () => {function sum(a,b){
return a+b;
}
function minus (a,b){
return a-b;
}
it('Testing sum',()=>{
expect(sum(2,2)).toBe(4);
})it('Testing minus' ,() => {
expect(minus(5,2)).toBe(3);
});});
here sum and minus are two function which we are testing. so describe is helping us to group set of test case , defining functions and prerequisite and…