Skip to content

Getting Started Jest

Yongku cho edited this page Aug 6, 2018 · 2 revisions
npm install --save-dev jest

sum.js

export function sum (a, b) {
    return a + b
}

sum.spec.js

import { sum } from './sum'

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3)
})

package.json

testEnvironment는 기본값으로 jsdom인데, node로 설정하지 않으면 SecurityError: localStorage is not available for opaque origins 에러가 발생한다.

{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "testEnvironment": "node"
  }
}
Clone this wiki locally