Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.92 KB

File metadata and controls

56 lines (38 loc) · 1.92 KB

Unit tests

Running tests

yarn install
yarn test

Expected behaviour

  • 4 passing tests

Explanation

yarn test refers to the test script that is defined in package.json. This is equivalent to running ./node_modules/.bin/jest from the command line.

Jest

Jest is a JavaScript testing framework. It defines how tests are defined (describe, beforeEach, test), how they are run and what the output looks like.

jest can be configured in jest.config.js.

Jest allows you to check that values meet certain conditions. expect function gives you access to various "matchers" that let you assert something about a value.

Tests

Check out test/PureFunctionsTests.js for example tests. It also demonstrates how beforeEach can be use to extract common setup code.

Continuous testing

Jest can be run in watch mode to run tests any time files change. This can be useful to get feedback faster. The test:watch script is defined in package.json for convenience.

transform-object-rest-spread plugin

ES6 defines spread syntax for arrays [...myArray, newElem], but does not do so for objects. Object.assign can be used to create a new object with an additional property (Object.assign({}, myObj, {newKey: newValue}), but it is rather verbose for such a common operation.

@babel/plugin-proposal-object-rest-spread babel plugin enables {...myObj, newKey: newValue} syntax.