Skip to content

Commit

Permalink
need to use a predicate since there are multiple console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Nov 27, 2022
1 parent 510ba27 commit df1b4be
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,21 +608,32 @@ test.describe('Load', () => {

if (process.env.DEV) {
test('using window.fetch causes a warning', async ({ page, baseURL }) => {
const [msg0] = await Promise.all([
page.waitForEvent('console'),
page.goto('/load/window-fetch/incorrect')
await Promise.all([
page.goto('/load/window-fetch/incorrect'),
page.waitForEvent('console', {
predicate: (message) => {
return (
message.text() ===
`Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests`
);
},
timeout: 3_000
})
]);
expect(await page.textContent('h1')).toBe('42');
expect(msg0.text()).toBe(
`Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests`
);

const [msg1] = await Promise.all([
page.waitForEvent('console'),
page.goto('/load/window-fetch/correct')
]);
/** @type {string[]} */
const warnings = [];
page.on('console', (msg) => {
if (msg.type() === 'warning') {
warnings.push(msg.text());
}
});

await page.goto('/load/window-fetch/correct');
expect(await page.textContent('h1')).toBe('42');
expect(msg1.text()).toBe(

expect(warnings).not.toContain(
`Loading ${baseURL}/load/window-fetch/data.json using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests`
);
});
Expand Down

0 comments on commit df1b4be

Please sign in to comment.