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

[no-standalone-expect] allow specifying what to consider a test block via an option #354

Closed
G-Rath opened this issue Jul 27, 2019 · 4 comments · Fixed by #585
Closed

[no-standalone-expect] allow specifying what to consider a test block via an option #354

G-Rath opened this issue Jul 27, 2019 · 4 comments · Fixed by #585
Labels

Comments

@G-Rath
Copy link
Collaborator

G-Rath commented Jul 27, 2019

This is pretty much the equivalent of expect-expect's assertFunctionNames option: We should support consuming an array of arbitrary strings of which we should consider as "test blocks".

This would allow extensions to work nicely with this rule, such as jest-each.

It's probably best to just to make the default value the current blocks we test for, in the same way expect-expect has expect as it's default.

@yairkukielka
Copy link

If you're using jest-each and jest >=22, see this answer.

@Lusito
Copy link

Lusito commented May 17, 2020

I'd like to see this too, since I've extended the describe.each and it.each functions with some additional properties.

@zwang180
Copy link

Just run into a situation where this would be really helpful:

In the project that I'm working on, we are leveraging Next.js's environment variables feature to control the app's behavior, and we are trying to create unit tests coverage for those behaviors. Essentially we are doing something like:

// test-utils.js
export const testIfA = process.env.MY_VAR === 'A' ? test : test.skip;
export const testIfB = process.env.MY_VAR === 'B' ? test : test.skip;
// others...

// myCode.test.js
import { testIfA, testIfB } from './test-utils.js';

describe('My tests', () => {
  testIfA('Only when A', () => {
    // test A behavior
  });

  testIfB('Only when B', () => {
    // test B behavior
  });
}); 

And no-standalone-expect will error out for any expect usage in both the testIfA and the testIfB block since it cannot recognize that it is a test block. Hence it will be really helpful if we could whitelist our helper functions to be considered as test blocks.

@github-actions
Copy link

🎉 This issue has been resolved in version 23.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

4 participants