fix: ensure fireEvent is exported
Overview
#328 moved exports from pure.js to index.js and switched everything to wildcard exports:
https://github.com/testing-library/svelte-testing-library/blob/0593819ca0e083eadf536d20d9d61944d594fb91/src/index.js#L15-L16
If two wildcard exports emit the same export, neither will be included.
There is also
export * from "mod", although there's noimport * from "mod". This re-exports all named exports frommodas the named exports of the current module, but the default export ofmodis not re-exported. If there are two wildcard exports statements that implicitly re-export the same name, neither one is re-exported.
This means the current release on next is not exporting fireEvent. This PR moves the STL exports back to named exports to resolve the bug
Observing the bug
pnpm add -D svelte @testing-library/svelte@next
node
> const stl = await import('@testing-library/svelte')
> stl.fireEvent
undefined
Why didn't tests catch this?
Vite/Vitest appears to resolve exports differently from local files compared to node_modules. Since the test suite imports directly from src/index.js, the behavior is slightly different:
- The conflicting wildcard export of
fireEventis available - It is set to whatever the last export was
In our case, since export * from '@testing-library/dom' is listed second, that means the tests are running with the vanilla fireEvent, and coincidentally passing because a no-op await in the test was enough of a wait for Svelte to flush pending changes.
Without a more sophisticated test suite that packs and installs the library into example projects (which is a good long term idea!) this particular problem is hard to guard against with unit tests.
Change log
- Update exports, with comments so we don't forget that the explicit named exports are important
- Update the tests to ensure
fireEventis returning a Promise - Fix import/export sorting lint errors in files I was touching and looking at