klioop for iOS

Jest, nodeJS test tool 본문

nodejs

Jest, nodeJS test tool

klioop2@gmail.com 2021. 2. 28. 22:33

Jest is a testing framework for javascript libarary such as react and nodeJS. It's like pytest in python.

Fisrt thing to do to use jest is, of course, install it. On terminal or command line, enter following  

 

> npm install jest

 

After jest is installed, whenever you have files named like xxx.test.js, jest will find them for testing.

For executing tests, enter on your terminal

 

> npm test

 

To use jest, unlike other modules, you don't need to import or require it.

Jest provides test functions as a global in the test suite files.

 

When test functions are called with the name of the functions, jest executes callback functions in that test function.

If the callback function throws an error, then the test is considered a failure.

If the callback function do not throw an error, the test is considered a success.

 

const addTwoNumber = (a, b) {
    return a + b
    }

test("Should add two integer numbers", () => {
    const result = addTwoNumber(1, 2)
    expect(result).toBe(3)
    })

// The above test will not throw an error, so that the test is a success.

'nodejs' 카테고리의 다른 글

unit test 의 필요성  (0) 2021.03.01