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

[new-rule] check that rejects & resolves are needed #804

Open
G-Rath opened this issue Mar 28, 2021 · 0 comments
Open

[new-rule] check that rejects & resolves are needed #804

G-Rath opened this issue Mar 28, 2021 · 0 comments

Comments

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 28, 2021

We should be able to use type-powered checking to determine if an expected value is PromiseLike with enough accurate to make a rule of it.

i.e

// fine
await expect(getEventOutcome(event)).resolves.toHaveProperty(
  'approves',
  2
);

// not fine: unneeded `resolves`
expect(await getEventOutcome(event)).resolves.toHaveProperty(
  'approves',
  2
);

likewise, we should be able to tell when a PromiseLike value is being interacted to make recommendations:

// not fine: this returns a Promise, so should be either awaited or have .resolves or .rejects
expect(fs.promises.readFile(...)).toStrictEqual(...);

However I think for now we should focus on the first case as the second has more valid edge cases that would make it much easier to get false positives, i.e

// this is valid
expect(fs.promises.readFile(...)).toBeInstanceOf(Promise);

This doesn't necessarily need to be a new rule - it could make sense to have it in valid-expect 🤔

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

No branches or pull requests

1 participant