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

Standard not working in tests #1147

Closed
amaurymartiny opened this issue Jun 6, 2018 · 2 comments

Comments

@amaurymartiny
Copy link

commented Jun 6, 2018

What version of standard?

11.0.1

What operating system, Node.js, and npm version?

macOs High Sierra
node v10.1.0
npm v6.1.0

What did you expect to happen?

Following #122 (comment), I would expect that , by putting "env": [ "mocha" ] to the package.json, I could use standard to lint my test files.

What actually happened?

$ yarn lint
yarn run v1.7.0
$ standard src/main.test.js
standard: Use JavaScript Standard Style (https://standardjs.com)
  /Users/amaurymartiny/Workspace/standard-in-tests/src/main.test.js:2:3: 'expect' is not defined.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is a small demo repo: https://github.com/amaurymartiny/standard-in-test.

@LinusU

This comment has been minimized.

Copy link
Member

commented Jun 8, 2018

As far as I know, expect is not part of mocha. Setting env: mocha adds describe and it, which seems to work for you.

@Flet

This comment has been minimized.

Copy link
Member

commented Jun 12, 2018

Yep!

eslint uses the globals package to get the mocha globals and I don't see expect listed there :)
https://github.com/sindresorhus/globals/blob/master/globals.json#L1024

If you're using some assertion library that has expect as a global, you can tell standard to ignore it using one of these ways:

  1. put this at the top of the JS file that references expect: /* global expect */

  2. add this to package.json:

 "standard": {
    "globals": [ "myVar1", "myVar2" ]
  }

Hope this helps! I'm closing this issue, but feel free to reply if you have other questions!

@Flet Flet closed this Jun 12, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Sep 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.