-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handler delay not being respected (#49)
* fix: handler delay not being respected * chore: use waitUntil instead
- Loading branch information
Showing
3 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { expect, test } from '../test'; | ||
import { rest } from 'msw'; | ||
|
||
test.describe.parallel('delay', () => { | ||
test('should send mock response after specified delay in the handler', async ({ | ||
page, | ||
worker, | ||
}) => { | ||
await worker.use( | ||
rest.get('/api/users', (_, response, context) => | ||
response( | ||
context.delay(500), | ||
context.json([ | ||
{ | ||
id: 'fake', | ||
firstName: 'Delayed', | ||
lastName: 'Response', | ||
}, | ||
]) | ||
) | ||
) | ||
); | ||
|
||
await page.goto('/users'); | ||
|
||
// Assert that loading text is still visible at 200ms | ||
await page.waitForTimeout(200); | ||
await expect(page.locator('text="Loading..."')).toBeVisible({ timeout: 0 }); | ||
|
||
// Assert that loading text is still visible at 400ms | ||
await page.waitForTimeout(200); | ||
await expect(page.locator('text="Loading..."')).toBeVisible({ timeout: 0 }); | ||
|
||
// Assert that the query has resolved by the 600ms mark (> 500ms delay) | ||
await page.waitForTimeout(200); | ||
await expect(page.locator('text="Delayed Response"')).toBeVisible({ | ||
timeout: 0, | ||
}); | ||
}); | ||
|
||
test('should send mock response straight away if no delay has been specified in the handler', async ({ | ||
page, | ||
worker, | ||
}) => { | ||
await worker.use( | ||
rest.get('/api/users', (_, response, context) => | ||
response( | ||
context.json([ | ||
{ | ||
id: 'fake', | ||
firstName: 'Instant', | ||
lastName: 'Response', | ||
}, | ||
]) | ||
) | ||
) | ||
); | ||
|
||
await page.goto('/users', { waitUntil: 'networkidle' }); | ||
await expect(page.locator('text="Instant Response"')).toBeVisible({ | ||
timeout: 0, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters