Skip to content

Commit

Permalink
test: add all the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed May 23, 2024
1 parent 363a54d commit 6b30a73
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/qwik/src/core/components/prefetch.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,67 @@ describe('PrefetchServiceWorker', () => {
});
expect(output.html).to.contain('<script nonce="1234" q:key="prefetch-service-worker">');
});
it('should render script with a scope', async () => {
const output = await renderToString(
<PrefetchServiceWorker base="/build/en/" scope="/en/" />,
{
containerTagName: 'div',
}
);
// eslint-disable-next-line no-console
console.log('>>>>', output.html);
expect(output.html).to.includes('scope: "/en/"');
expect(output.html).to.includes('"/build/en/qwik-prefetch-service-worker.js"');
});
it('should render script with a base', async () => {
const output = await renderToString(<PrefetchServiceWorker base="/build/en/" />, {
containerTagName: 'div',
});
// eslint-disable-next-line no-console
console.log('>>>>', output.html);
expect(output.html).to.includes('scope: "/"');
expect(output.html).to.includes('"/build/en/qwik-prefetch-service-worker.js"');
});
it('should render script with a custom service-worker path', async () => {
const output = await renderToString(
<PrefetchServiceWorker path="patrickjs-service-worker.js" />,
{
containerTagName: 'div',
}
);
// eslint-disable-next-line no-console
console.log('>>>>', output.html);
expect(output.html).to.includes('scope: "/"');
expect(output.html).to.includes('"/patrickjs-service-worker.js"');
});
it('should render script with a custom service-worker path with different base', async () => {
const output = await renderToString(
<PrefetchServiceWorker path="patrickjs-service-worker.js" base="/build/" />,
{
containerTagName: 'div',
}
);
// eslint-disable-next-line no-console
console.log('>>>>', output.html);
expect(output.html).to.includes('scope: "/"');
expect(output.html).to.includes('"/build/patrickjs-service-worker.js"');
});
it('should render script with a custom path', async () => {
const output = await renderToString(
<PrefetchServiceWorker
path="/build/patrickjs-service-worker.js"
scope="/"
base="/build/en/" // should be ignored
/>,
{
containerTagName: 'div',
}
);
// eslint-disable-next-line no-console
console.log('>>>>', output.html);
expect(output.html).to.includes('scope: "/"');
expect(output.html).to.includes('"/build/patrickjs-service-worker.js"');
});
});
});

Expand Down

0 comments on commit 6b30a73

Please sign in to comment.