test files have .test.js or .spec.js suffix
add test file and code together under /src folder
//temp.js
function hello()
{
console.log("Hello World!");
}
function sum(a, b)
{
return a+b;
}
export {hello, sum};
//temp.test.js
import {hello, sum} from "./temp.js"
it('hello test', () => {
hello();
});
it('sums numbers', () => {
expect(sum(1, 2)).toEqual(3);
expect(sum(2, 2)).toEqual(4);
});
npm test // under the root directory of the project
Directly copy a project created by create-react-app will cause launching errors
$ npm install -g npm@latest # or, npm install -g npm@latest --prefix "C:\Program Files\nodejs"
$ rm -rf node_modules # or, `cmd /c rmdir /s /q node_modules` on Windows
$ npm install