Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/siddhesh-coder/jest-unit-testing-


https://github.com/siddhesh-coder/jest-unit-testing-

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

![](/Screenshot%20(176).png)

# a) To check the version of Node.js, open a command prompt or terminal and run:

node --version

If Node.js is not available or needs to be installed or updated, follow these steps:

Go to Node.js official website in a web browser.
1 Click the "Windows Installer" button to download the latest default version.
2 Run the installation.
3 Accept the terms and conditions.
4 Set up the path.
5 Select the default components to be installed.
6 Start the installation.
7 You can verify that Node.js has been successfully installed by opening the command prompt and typing node -v.

# b) To check the version of npm, run:

npm --version

Make sure that your npm version is up-to-date. If not, you can update it using:

npm install -g npm@latest

# c) To check the version of Jest, run:

jest --version
If Jest is not available, you can install it globally by running:

npm install -g jest
Alternatively, you can set up Jest for your project locally by following the steps you provided. This involves initializing a package.json file, installing Jest as a development dependency, and configuring the "test" script to use Jest.

Create a Test File (e.g., addition.test.js):

You can create a test file for your JavaScript code. The content of the addition.test.js file will depend on what you want to test. Jest is a popular testing framework for JavaScript, and you can write test cases using its syntax. Here's a simple example of a test file:

javascript
Copy code
// addition.js
function add(a, b) {
return a + b;
}

module.exports = add;

// addition.test.js
const { default: TestRunner } = require("jest-runner");
const add = require(`./addition`); //requiring file which when to test (give file path)

test(`returns the addition of both`,()=>{
expect(add(2,3)).toBe(5);
})
In this example, we have a function add in addition.js, and we are testing it in addition.test.js using Jest's test and expect functions.

Ensure that you have the necessary project structure and files in place to run your tests successfully.