Skip to content

Commit 5da3402

Browse files
authored
chore(lint): use jest/no-alias-methods rule (#13371)
1 parent 71044c0 commit 5da3402

File tree

78 files changed

+502
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+502
-496
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,12 @@ module.exports = {
162162
],
163163
env: {'jest/globals': true},
164164
excludedFiles: ['**/__typetests__/**'],
165+
extends: ['plugin:jest/style'],
165166
plugins: ['jest'],
166167
rules: {
168+
'jest/no-alias-methods': 'error',
167169
'jest/no-focused-tests': 'error',
168170
'jest/no-identical-title': 'error',
169-
'jest/prefer-to-be': 'error',
170-
'jest/prefer-to-contain': 'error',
171-
'jest/prefer-to-have-length': 'error',
172171
'jest/valid-expect': 'error',
173172
},
174173
},

docs/ExpectAPI.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ it('transitions as expected', () => {
503503
test('map calls its argument with a non-null argument', () => {
504504
const mock = jest.fn();
505505
[1].map(x => mock(x));
506-
expect(mock).toBeCalledWith(expect.anything());
506+
expect(mock).toHaveBeenCalledWith(expect.anything());
507507
});
508508
```
509509

@@ -520,7 +520,7 @@ function getCat(fn) {
520520
test('randocall calls its callback with a class instance', () => {
521521
const mock = jest.fn();
522522
getCat(mock);
523-
expect(mock).toBeCalledWith(expect.any(Cat));
523+
expect(mock).toHaveBeenCalledWith(expect.any(Cat));
524524
});
525525

526526
function randocall(fn) {
@@ -530,7 +530,7 @@ function randocall(fn) {
530530
test('randocall calls its callback with a number', () => {
531531
const mock = jest.fn();
532532
randocall(mock);
533-
expect(mock).toBeCalledWith(expect.any(Number));
533+
expect(mock).toHaveBeenCalledWith(expect.any(Number));
534534
});
535535
```
536536

@@ -709,7 +709,7 @@ For example, let's say that we expect an `onPress` function to be called with an
709709
test('onPress gets called with the right thing', () => {
710710
const onPress = jest.fn();
711711
simulatePresses(onPress);
712-
expect(onPress).toBeCalledWith(
712+
expect(onPress).toHaveBeenCalledWith(
713713
expect.objectContaining({
714714
x: expect.any(Number),
715715
y: expect.any(Number),
@@ -1548,15 +1548,15 @@ test('throws on octopus', () => {
15481548
}
15491549

15501550
// Test that the error message says "yuck" somewhere: these are equivalent
1551-
expect(drinkOctopus).toThrowError(/yuck/);
1552-
expect(drinkOctopus).toThrowError('yuck');
1551+
expect(drinkOctopus).toThrow(/yuck/);
1552+
expect(drinkOctopus).toThrow('yuck');
15531553

15541554
// Test the exact error message
1555-
expect(drinkOctopus).toThrowError(/^yuck, octopus flavor$/);
1556-
expect(drinkOctopus).toThrowError(new Error('yuck, octopus flavor'));
1555+
expect(drinkOctopus).toThrow(/^yuck, octopus flavor$/);
1556+
expect(drinkOctopus).toThrow(new Error('yuck, octopus flavor'));
15571557

15581558
// Test that we get a DisgustingFlavorError
1559-
expect(drinkOctopus).toThrowError(DisgustingFlavorError);
1559+
expect(drinkOctopus).toThrow(DisgustingFlavorError);
15601560
});
15611561
```
15621562

docs/GlobalAPI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ const binaryStringToNumber = binString => {
212212
describe('binaryStringToNumber', () => {
213213
describe('given an invalid binary string', () => {
214214
test('composed of non-numbers throws CustomError', () => {
215-
expect(() => binaryStringToNumber('abc')).toThrowError(CustomError);
215+
expect(() => binaryStringToNumber('abc')).toThrow(CustomError);
216216
});
217217

218218
test('with extra whitespace throws CustomError', () => {
219-
expect(() => binaryStringToNumber(' 100')).toThrowError(CustomError);
219+
expect(() => binaryStringToNumber(' 100')).toThrow(CustomError);
220220
});
221221
});
222222

docs/MockFunctionAPI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ test('calculate calls add', () => {
548548
// requiring `add`.
549549
calculate(mockAdd, 1, 2);
550550

551-
expect(mockAdd).toBeCalledTimes(1);
552-
expect(mockAdd).toBeCalledWith(1, 2);
551+
expect(mockAdd).toHaveBeenCalledTimes(1);
552+
expect(mockAdd).toHaveBeenCalledWith(1, 2);
553553
});
554554
```
555555

e2e/__tests__/failureDetailsProperty.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,19 @@ test('that the failureDetails property is set', () => {
160160
Object {
161161
"actual": "",
162162
"error": Object {
163-
"message": "expect(received).rejects.toThrowError()
163+
"message": "expect(received).rejects.toThrow()
164164
165165
Received promise resolved instead of rejected
166166
Resolved to value: 1",
167167
},
168168
"expected": "",
169169
"matcherName": "",
170-
"message": "Error: expect(received).rejects.toThrowError()
170+
"message": "Error: expect(received).rejects.toThrow()
171171
172172
Received promise resolved instead of rejected
173173
Resolved to value: 1",
174174
"passed": false,
175-
"stack": "Error: expect(received).rejects.toThrowError()
175+
"stack": "Error: expect(received).rejects.toThrow()
176176
177177
Received promise resolved instead of rejected
178178
Resolved to value: 1
@@ -245,7 +245,7 @@ test('that the failureDetails property is set', () => {
245245
],
246246
Array [
247247
Object {
248-
"message": "expect(received).rejects.toThrowError()
248+
"message": "expect(received).rejects.toThrow()
249249
250250
Received promise resolved instead of rejected
251251
Resolved to value: 1",

e2e/failureDetails-property/__tests__/tests.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ it('throws!', () => {
3333
});
3434

3535
test('promise rejection', async () => {
36-
await expect(Promise.resolve(1)).rejects.toThrowError();
36+
await expect(Promise.resolve(1)).rejects.toThrow();
3737
});

e2e/module-name-mapper-mock/__tests__/storage/track/Track.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jest.mock('@@storage/track/Track');
1010

1111
test('relative import', () => {
1212
const track = new Track();
13-
expect(track.someRandomFunction).not.toBeCalled();
13+
expect(track.someRandomFunction).not.toHaveBeenCalled();
1414
});

e2e/module-name-mapper-mock/__tests__/storage/track/TrackExpected.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jest.mock('@@storage/track/Track');
1010

1111
test('through moduleNameMapper', () => {
1212
const track = new Track();
13-
expect(track.someRandomFunction).not.toBeCalled();
13+
expect(track.someRandomFunction).not.toHaveBeenCalled();
1414
});

examples/jquery/__tests__/display_user.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ it('displays a user after a click', () => {
3434

3535
// Assert that the fetchCurrentUser function was called, and that the
3636
// #username span's inner text was updated as we'd expect it to.
37-
expect(fetchCurrentUser).toBeCalled();
37+
expect(fetchCurrentUser).toHaveBeenCalled();
3838
expect($('#username').text()).toBe('Johnny Cash - Logged In');
3939
});

examples/jquery/__tests__/fetch_current_user.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ it('calls into $.ajax with the correct params', () => {
1414

1515
// Now make sure that $.ajax was properly called during the previous
1616
// 2 lines
17-
expect($.ajax).toBeCalledWith({
17+
expect($.ajax).toHaveBeenCalledWith({
1818
success: expect.any(Function),
1919
type: 'GET',
2020
url: 'http://example.com/currentUser',

0 commit comments

Comments
 (0)