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

feat(expect-expect): support using wildcards in additionalTestBlockFunctions #994

Closed
wants to merge 4 commits into from

Conversation

NickBolles
Copy link

@NickBolles NickBolles commented Dec 2, 2021

TODO

  • - update no-standalone-expect
  • - update tests
  • - update docs
  • - fix tests 😦

Fixes #993

@SimenB SimenB requested a review from G-Rath December 15, 2021 09:39
@G-Rath G-Rath changed the title Allow regexp for additionalTestBlockFunctions feat(expect-expect): support using wildcards in additionalTestBlockFunctions Dec 19, 2021
Copy link
Collaborator

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good (minus the failing tests), but I think it would be good to have a changelog entry for each rule which means either doing a PR for each rule or having one PR with only two commits (that follow the conventional commit format), one for expect-expect & another for no-standalone-expect.

Let me know if you'd like me to help, or if you'd prefer I take care of that side of things.

(I'd say it's probably best to do two different PRs, as it looks like the change for no-standalone-expect has broken other tests, which could be because the regex is not suitable).

@@ -141,5 +146,38 @@ describe('NumberToLongString', () => {
expect(output).toBe(theory.expected);
},
);

it('should be correctly translated to string', () =>
expectToBeCorrectString(NumberToLongString(100), 'One hundred'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would prefer to have a body on this function, to make it simpler

@@ -125,6 +126,10 @@ The following is _correct_ when using the above configuration:
```js
import theoretically from 'jest-theories';

function expectToBeCorrectString(result, expectedString) {
return expect(result).toBe(expectedString);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's remove the return, since vanilla expect throws instead of returning and so it should be less chance of confusing developers

Suggested change
return expect(result).toBe(expectedString);
expect(result).toBe(expectedString);

`,
options: [
{
assertFunctionNames: ['assert*'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to have a test case without this option being provided, to keep things simple (having both test cases is good too).

e.g. like this https://github.com/jest-community/eslint-plugin-jest/pull/994/files#diff-be15fe30b6db731ff0d3ddcc2746228fd05cad63180b95c497b00869c2e7e601R144-R153

`,
options: [
{
assertFunctionNames: ['assert*'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to have a test case without this option being provided, to keep things simple (having both test cases is good too).

e.g. like this https://github.com/jest-community/eslint-plugin-jest/pull/994/files#diff-be15fe30b6db731ff0d3ddcc2746228fd05cad63180b95c497b00869c2e7e601R144-R153

Additionally, this test is currently failing because assertFunctionNames is meant to be all of the assertion functions to allow - i.e. it's default is ['expect'], meaning if you pass a custom value you need to explicitly include 'expect'.

@G-Rath
Copy link
Collaborator

G-Rath commented Feb 6, 2022

@NickBolles are you still working on this?

@NickBolles
Copy link
Author

@G-Rath totally forgot about it. I'll come back to it sometime in the next week

@G-Rath
Copy link
Collaborator

G-Rath commented May 28, 2022

@NickBolles are you willing to work on this, or are you happy if I pick it up?

@NickBolles
Copy link
Author

NickBolles commented May 30, 2022

@NickBolles are you willing to work on this, or are you happy if I pick it up?

@G-Rath You're welcome to pick it up, otherwise I'd still like to get to it.sorry for the delay.

@SimenB
Copy link
Member

SimenB commented Sep 9, 2022

is this one still alive? 🙂

@G-Rath
Copy link
Collaborator

G-Rath commented Sep 9, 2022

I don't think this PR is, but I started to implement myself and after looking at the rules source code for like half an hour I'm pretty sure its super broken and needs re-implementing (i.e. its not checking for expects using parseJestFnCall).

Based on the tests I also think that this change is actually not quite what the OP wanted, but its hard to know for sure because they didn't give a code example in the issue 🤔

@G-Rath G-Rath closed this Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[expect-expect] allow additionalTestBlockFunctions to take a regex
4 participants