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

Document allowing mocha root plugins in the browser #4639

Closed
IanVS opened this issue May 26, 2021 · 3 comments · Fixed by #4755
Closed

Document allowing mocha root plugins in the browser #4639

IanVS opened this issue May 26, 2021 · 3 comments · Fixed by #4755
Labels
area: browser browser-specific area: documentation anything involving docs or mochajs.org

Comments

@IanVS
Copy link

IanVS commented May 26, 2021

Is your feature request related to a problem or a nice-to-have?? Please describe.

I am using @web/test-runner, which uses mocha in the browser. I need a way to call cleanup from '@testing-library/react' after every test, which seems like the perfect thing for a root plugin.

However, plugins need to be added with --require, which I can't use since I'm in the browser.

Describe the solution you'd like
I think a new option should be added to mocha.setup(), to allow specifying mochaHooks directly.

Describe alternatives you've considered
I've tried using root hooks, loaded in a <script> after mocha is set up, and that was working for firefox and chrome, but fails in safari which seems to try to run it before mocha is finished being added to the global scope. Also, the docs recommend root hook plugins instead, and I'd like to avoid an approach which might be deprecated.

Additional context
Add any other context or screenshots about the feature request here.

@IanVS IanVS added the type: feature enhancement proposal label May 26, 2021
@IanVS IanVS changed the title Allow mocha root plugins in the browser Document allowing mocha root plugins in the browser May 26, 2021
@IanVS
Copy link
Author

IanVS commented May 26, 2021

After looking into it more, it seems that rootHooks is indeed available to use on mocha.setup(). So I've changed this ticket to documenting it, because it definitely wasn't clear that it was possible to do.

@gushogg-blake
Copy link

@IanVS how did you get this working? I tried adding a config option to the setup call but it didn't work (setup("bdd", { rootHooks: ... });). Searching for setup in the code doesn't turn anything up either... Cheers!

@gushogg-blake
Copy link

Found it - setup takes an options object or a string, in which case the string is used as the ui option ("bdd" etc):

mocha.setup = function(opts) {

@juergba juergba added area: documentation anything involving docs or mochajs.org and removed type: feature enhancement proposal labels Sep 24, 2021
@juergba juergba added the area: browser browser-specific label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: browser browser-specific area: documentation anything involving docs or mochajs.org
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants