You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is perhaps a silly question, but it's something I ran into at work.
We have a couple of components which are using JS libraries to defer the displaying of some content within our written articles and blogs.
There is also a unit test, broken down to it's very basic pieces, you get something that looks like this:
// special.svelte
<script>
// Other code here
</script>
<svelte:head>
<script>
// some required args for the librarywindow.SOME_LIBRARY= { disable_autoload:true };</script>
<!-- not the actual library, but to show the point that something has to load here -->
<scriptsrc="https://code.jquery.com/jquery-3.7.1.slim.min.js"defer></script>
</svelte:head>
<!-- other HTML here -->
In practice, this works fine when testing on a browser, but someone well before I got there created a test that looks something like this
import{render}from'@testing-library/svelte';import{describe,expect,it}from'vitest';importSpecialfrom'./special.svelte';describe('Special',()=>{it('Does its special thing',async()=>{render(Special);expect((windowasany).SOME_LIBRARY).toBeDefined();expect(document.head.querySelector('script[src="https://code.jquery.com/jquery-3.7.1.slim.min.js"]',),).toBeInTheDocument();});});
Which fails, and writing the entire DOM to the console shows me
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This is perhaps a silly question, but it's something I ran into at work.
We have a couple of components which are using JS libraries to defer the displaying of some content within our written articles and blogs.
There is also a unit test, broken down to it's very basic pieces, you get something that looks like this:
In practice, this works fine when testing on a browser, but someone well before I got there created a test that looks something like this
Which fails, and writing the entire DOM to the console shows me
It seems that in svelte 5 (I haven't been able to test on svelte 4) the
<svelte:head>
contents are not being applied in test environments.Anyone got any ideas how I can fix this?
Beta Was this translation helpful? Give feedback.
All reactions