Skip to content

Bun 의 테스트 러너는 .toMatchSnapshot() 을 통한 Jest 스타일의 스냅샷 테스트를 지원합니다.

ts
import { test, expect } from "bun:test";

test("스냅샷", () => {
  expect({ foo: "bar" }).toMatchSnapshot();
});

이 테스트가 처음 실행될 때 Bun 은 __snapshots__ 라는 디렉터리에 스냅샷 파일을 테스트 파일과 함께 디스크에 씁니다.

txt
test
├── __snapshots__
│   └── snap.test.ts.snap
└── snap.test.ts

스냅샷을 재생성하려면 --update-snapshots 플래그를 사용하세요.

sh
bun test --update-snapshots
txt
test/snap.test.ts:
✓ snapshot [0.86ms]

 1 pass
 0 fail
 snapshots: +1 added # 스냅샷이 재생성되었습니다
 1 expect() calls
Ran 1 tests across 1 files. [102.00ms]

Bun 테스트 러너로 스냅샷에 대한 전체 문서는 문서 > 테스트 러너 > 스냅샷 을 참조하세요.

Bun by www.bunjs.com.cn 편집