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
/** type {ChaiPlugin} */exportdefaultasyncfunction(chai,utils){const{ use }=awaitimport('chai')use(jestSnapshotPlugin())}
This appears to work but I'm not sure if making the plugin function async is exactly supported. And there may always be the risk of importing wrong chai in case of duplicate resolutions
Ah, gotcha. Of course that's an option but I try to avoid adding chai as a dependency to plugins. Especially now, that plugins should work no problem with both v4 and v5
Activity
43081j commentedon Sep 25, 2024
Probably makes sense to avoid weird situations with multiple versions of chai (since if you didn't care about that, you would just import
use?)Let's see what @keithamus or @koddsson thinks though
tpluscode commentedon Sep 25, 2024
This appears to work but I'm not sure if making the plugin function async is exactly supported. And there may always be the risk of importing wrong chai in case of duplicate resolutions
43081j commentedon Sep 25, 2024
Yep, it would be a lot cleaner if you wrote your plugin as esm of course too
I think you're right though and we should add this
tpluscode commentedon Sep 25, 2024
The plugin is esm. But it includes another to use the extra assertions and I called
useinside so that end user does not have to43081j commentedon Sep 25, 2024
What I mean is if you did import
use, you could just do it normally in a regular import statement (rather than a dynamic import)That would be pretty clean code but wouldn't work well if for some reason there's two chai running at once
tpluscode commentedon Sep 25, 2024
Ah, gotcha. Of course that's an option but I try to avoid adding chai as a dependency to plugins. Especially now, that plugins should work no problem with both v4 and v5