Cannot call use inside use any more
I found that in v5 this is no longer possible
/** type {ChaiPlugin} */
export default function(chai, utils) {
chai.use(anotherPlugin)
}
use is no longer included in the argument. Can we add it to match what was possible with v4?
export function use(fn) {
const exports = {
+ use,
AssertionError,
util,
config,
expect,
assert,
Assertion,
...should
};
if (!~used.indexOf(fn)) {
fn(exports, util);
used.push(fn);
}
return exports;
};
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
/** type {ChaiPlugin} */
export default async function(chai, utils) {
const { use } = await import('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
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
The plugin is esm. But it includes another to use the extra assertions and I called use inside so that end user does not have to
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
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