테스트/단위 테스트 (Vue)
단위 테스트 - Jest Globals
IT Blue
2021. 9. 3. 04:09
단위 테스트 - Jest Globals
/* example.test.js */
import { double } from './example'
// describe(테스트 그룹의 이름, 콜백 - test())
describe('그룹1', () => {
// 그룹 안에 있는 모든 테스트가 시작하기 전에 단 1번만 실행
beforeAll(() => {
console.log('beforeAll')
})
// 그룹 안에 있는 모든 테스트가 끝난 다음에 단 1번만 실행
afterAll(() => {
console.log('agterAll')
})
// 그룹 안에 있는 각각의 테스트가 시작하기 전에 실행
beforeEach(() => {
console.log('beforeEach')
})
// 그룹 안에 있는 각각의 테스트가 끝난 다음에 실행
afterEach(() => {
console.log('afterEach')
})
// test(테스트의 이름, 콜백 - 실제 테스트를 진행)
test('첫 테스트', () => {
console.log('첫 테스트')
expect(123).toBe(123)
})
test('인수가 숫자 데이터', () => {
console.log('인수가 숫자 데이터')
expect(double(3)).toBe(6)
expect(double(10)).toBe(20)
})
test('인수가 없습니다', () => {
console.log('인수가 없습니다')
expect(double()).toBe(0)
})
})
결과
참고
Globals · Jest
In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them. However, if you prefer explicit imports, you can do import {describe, expect, test} from '@jest/globals'.
jestjs.io