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

Handle 'no-unused-expressions' violations due to use of Chai expect #3

Closed
ianwalter opened this issue Jan 11, 2018 · 7 comments
Closed
Assignees

Comments

@ianwalter
Copy link

ianwalter commented Jan 11, 2018

Using a Chai expect expression in a test with the StandardJS ESLint config will throw the ESLint error:

error  Expected an assignment or function call and instead saw an expression  no-unused-expressions

Since Chai is bundled with Cypress I think it only makes sense that eslint-plugin-cypress handle this without the user having to install a separate plugin to handle Chai expressions.

@jennifer-shehane
Copy link
Member

Can you give a short example of the test with expression you wrote that errored so we can test this?

@ianwalter
Copy link
Author

Sure:

const onRequest = ({ request }) => {
  expect(request.body.email.billingUpdate).to.be.true
  expect(request.body.phone.documentUpdate).to.be.false
}

@Strajk
Copy link
Contributor

Strajk commented Feb 5, 2018

👋Here's discussion about this topic eslint/eslint#2102

@jennifer-shehane
Copy link
Member

Eslint decided to not address this issue as it is library specific. It seems that the best fix for this would be to add the eslint-plugin-chai-friendly plugin to our eslint config or some similar configuration to ignore chai's no-unused-expressions. @chrisbreiding thoughts?

@corysimmons
Copy link

@jennifer-shehane Just tested this out. Works great and still catches errors not related to Cypress/Chai. 👍

@chrisbreiding
Copy link
Contributor

Because of the way ESLint plugins work, we can't bundle a plugin with our plugin and have it "just work". The user still needs to install the chai plugin manually as their own dependency. If we include the rule and a user doesn't install the plugin (which they might not even need if they're not using the no-unused-expressions rule), they'll get an error saying there's an unknown rule in their configuration.

So instead, I'm going to document this in the README.

@bmulholland
Copy link

Resurrecting an old issue, but there is now a way to bundle plugins together: https://www.npmjs.com/package/@rushstack/eslint-patch

As used by airbnb, for example: https://github.com/vuejs/eslint-config-airbnb/blob/main/packages/eslint-config-airbnb/CHANGELOG.md#700

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

6 participants