open-wc / open-wc

Open Web Components: guides, tools and libraries for developing web components.
https://open-wc.org/
MIT License
2.28k stars 425 forks source link

[testing] document use of chai with karma-esm and @open-wc/testing #1238

Open bennypowers opened 4 years ago

bennypowers commented 4 years ago

When importing from @open-wc/testing, chai is automatically configured for karma-esm But if a user wants to apply their own chai plugins, they can experience failure in a few different ways:

  1. since there's no chai member exported from @open-wc/testing, if they try to import it and chai.use(myPlugin), it will fail. They will have to window.chai.use(myPlugin) instead.
  2. if they load a chai-plugin module which registers itself on window.chai, but they import that module before importing @open-wc/testing, it will fail.

I think the solution here is simply to document those things on https://open-wc.org/testing/testing.html#chai so that users who do want to use their own plugins will have some recourse.

We could also reconsider exporting chai from @open-wc/testing

jpzwarte commented 1 year ago

@bennypowers this issue can be closed? From my @open-wc/testing/index.js:

import chai, { expect, should, assert } from '@esm-bundle/chai';
import './register-chai-plugins.js';

export { chai, expect, should, assert };