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

Request for new rule to prefer toBeFunction/toBeArray #219

Open
geoffswift opened this issue Oct 20, 2024 · 2 comments
Open

Request for new rule to prefer toBeFunction/toBeArray #219

geoffswift opened this issue Oct 20, 2024 · 2 comments

Comments

@geoffswift
Copy link

geoffswift commented Oct 20, 2024

I would expect something like this to be flagged in error, and ideally auto-fixable

// bad
expect(example).toStrictEqual(expect.any(Function));
expect(typeof example).toBe('function');
expect(typeof example == 'function').toBeTrue();
expect(typeof example == 'function').toBeTruthy();
expect(typeof example === 'function').toBeTrue();
expect(typeof example === 'function').toBeTruthy();

expect(example).toStrictEqual(expect.any(String));
expect(typeof example).toBe('string');
expect(typeof example == 'string').toBeTrue();
expect(typeof example == 'string').toBeTruthy();
expect(typeof example === 'string').toBeTrue();
expect(typeof example === 'string').toBeTruthy();

expect(example).toStrictEqual(expect.any(Number));
expect(typeof example).toBe('number');
expect(typeof example == 'number').toBeTrue();
expect(typeof example == 'number').toBeTruthy();
expect(typeof example === 'number').toBeTrue();
expect(typeof example === 'number').toBeTruthy();
// good
expect(example).toBeFunction();

expect(example).toBeString();

expect(example).toBeNumber();

Arrays are a bit different

// bad
expect(Array.isArray(example)).toBeTrue();
expect(Array.isArray(example)).toBeTruthy();
// good
expect(example).toBeArray();
@G-Rath G-Rath transferred this issue from jest-community/eslint-plugin-jest Oct 20, 2024
@G-Rath
Copy link
Collaborator

G-Rath commented Oct 20, 2024

I've transferred this to eslint-plugin-jest-extended as that's where rules for jest-extended matchers belong - note we've already got some rules for toBe including toBeArray and toBeObject

@geoffswift
Copy link
Author

I noticed the same idea suggested in #95. I think my report is more specific though, but I guess we should close one or the other.

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

2 participants