Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/browser/third-party/fake-timers.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { http, HttpResponse } from 'msw'
import { setupWorker } from 'msw/browser'

const worker = setupWorker(
http.get('/resource', () => {
return HttpResponse.text('hello world')
}),
)

worker.start()
17 changes: 17 additions & 0 deletions test/browser/third-party/fake-timers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '../playwright.extend'

test('mocks responses when using fake timers in tests', async ({
loadExample,
page,
fetch,
}) => {
await loadExample(new URL('./fake-timers.mock.js', import.meta.url))

await page.evaluate(() => {
Date.now = () => 0
})

const response = await fetch('/resource')

await expect(response.text()).resolves.toBe('hello world')
})
Loading