Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation about loading chai in browser is wrong #1624

Open
cpcallen opened this issue Jun 10, 2024 · 3 comments
Open

Documentation about loading chai in browser is wrong #1624

cpcallen opened this issue Jun 10, 2024 · 3 comments

Comments

@cpcallen
Copy link

The documentation on the chai website says:

Include the chai browser build in your testing suite.

<script src="chai.js" type="text/javascript"></script>

This will provide chai as a global object, or define it if you are using AMD.

and the documentation in this repository's README says:

Browsers

You can also use it within the browser; install via npm and use the chai.js file found within the download. For example:

<script src="./node_modules/chai/chai.js"></script>

… but in both cases following this instruction will not set the chai global variable but instead will cause the browser to issue the following error message:

SyntaxError: Unexpected token 'export' (at chai.js:3768:1)

It is unclear what the correct instructions for v5.0.0 and later should be.

One viable workaround is:

<script type="module">
  import * as chai from './node_modules/chai/chai.js';
  globalThis.chai = chai;
</script>
@43081j
Copy link
Contributor

43081j commented Jun 10, 2024

good catch!

it should probably be something like this (depending on which interface):

<script src="./node_modules/chai/register-should.js" type="module"></script>

if you want expect/assert, i'd recommend importing it rather than making it global

@programmersRuleTheWorld

This repo is broken at ^5.0.
I'm trying to do tests on a Chrome extension and the incorrect documentation leaves me with an annoyed feeling about Chai.
I am making a product people will be paying for and I need to make sure it works correctly.
If I make a library for others to use for free, I will make sure it works and is updated or else what's the point?
Please fix this.

@43081j
Copy link
Contributor

43081j commented Jun 17, 2024

Can you be clear about what exactly is broken?

Did you try what I mentioned in my last comment? If that works for you, it is just a miss in docs and we can update

We could have done better with updating the docs when we released 5.x, given it is a fairly big breaking change (esm only). We are doing what we can to update but could do with clearer issues than telling us the repo is broken - so we can help out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants