-- 시각에 따라 결과가 달라지는 함수를 시각을 정해 놓고 테스트한다purchase :: Time -> Resultpurchase t | openHours t = Success | otherwise = ErrorbeforeEach useFakeTimers -- Date · setTimeout 등을 가짜로 (vi / jest 같은 이름)afterEach useRealTimersit "영업시간" (setSystemTime (date 2000 1 1 13) >> purchase' `shouldBe` Success)it "영업시간 외" (setSystemTime (date 2000 1 1 19) >> purchase' `shouldBe` Error)-- 둘 다 @sinonjs/fake-timers 기반
-- vi.mocked 는 타입만 붙인다 — 구현은 없다mocked :: a -> Mocked amocked = unsafeCoerce -- "Just returns the object that was passed"(mocked useSize).mockImplementation -- undefined: 원래 함수는 mock 이 아니다-- 구현은 vi.hoisted 로 먼저 만들어 vi.mock 에 넘긴다mockUseSize = hoisted fnmock "ahooks" { useSize = mockUseSize }beforeEach (mockImplementation mockUseSize (const { width = 100, height = 20 }))-- DOM 측정값은 getter 를 바꾸고 뒤에서 복원beforeEach (defineProperty htmlElementPrototype "scrollWidth" { configurable = True, get = 150 })-- 측정이 복잡하면 Playwright·Cypress 통합 테스트로