Overview
One very important part of software development is test automation since it creates an automatic process for one or multiple types of tests to run without the need for manual intervention.
Testing helps a large community of developers (or even a single developer) keep a piece of software evolving in the right direction. Without tests, it's easy to break existing code, introduce unexpected bugs, or ignore important edge cases.
On my application ag-ssg I have used tools for automating my tests when working on a JavaScript/TypeScript codebase is JEST.
Jest is one of Facebook's open-source projects that is both under very active development and is also being used to ship code to everybody on Facebook.com.
Learned from this lab
- general concepts and terminology of software testing
- unit testing and integration testing
Set Up a Testing Framework
To get Started with JEST.
npm install --save-dev jest
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a sum.js file:
function sum(a, b) {
return a + b;
}
module.exports = sum;
Then, create a file named sum.test.js. This will contain our actual test:
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Add the following section to your package.json:
{
"scripts": {
"test": "jest"
}
}
Finally, run yarn test
or npm test
and Jest will print this message if your code has passed all the implemented test
This is the first time when i have used the JEST to test my code. I have learned alot that how we cannot use the import
statement when we are creating the .test.js
file it will give us the syntax error we manually need to configure JEST
so that it can work with the import
statement in the code.
Why to use Jest
List feature of jest
- Simple and fast, ideal for prototyping.
- It allows the generation of code coverage reports simply by adding the argument —-coverage to the command line.
- Error reporting during test execution is rich and valuable.
- Documentation and the community around the tool are really good.
Thanks
Top comments (0)