Skip to content

Commit 8219820

Browse files
authored
chore(lint): use jest/prefer-to-be rule (#13369)
1 parent 04dae6c commit 8219820

File tree

178 files changed

+760
-759
lines changed

Some content is hidden

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

178 files changed

+760
-759
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ module.exports = {
166166
rules: {
167167
'jest/no-focused-tests': 'error',
168168
'jest/no-identical-title': 'error',
169+
'jest/prefer-to-be': 'error',
169170
'jest/valid-expect': 'error',
170171
},
171172
},
@@ -191,6 +192,12 @@ module.exports = {
191192
'sort-keys': 'off',
192193
},
193194
},
195+
{
196+
files: ['**/UsingMatchers.md/**'],
197+
rules: {
198+
'jest/prefer-to-be': 'off',
199+
},
200+
},
194201

195202
// snapshots in examples plus inline snapshots need to keep backtick
196203
{

docs/Es6ClassMocks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ it('We can check if the consumer called a method on the class instance', () => {
8181
// mock.instances is available with automatic mocks:
8282
const mockSoundPlayerInstance = SoundPlayer.mock.instances[0];
8383
const mockPlaySoundFile = mockSoundPlayerInstance.playSoundFile;
84-
expect(mockPlaySoundFile.mock.calls[0][0]).toEqual(coolSoundFileName);
84+
expect(mockPlaySoundFile.mock.calls[0][0]).toBe(coolSoundFileName);
8585
// Equivalent to above check:
8686
expect(mockPlaySoundFile).toHaveBeenCalledWith(coolSoundFileName);
8787
expect(mockPlaySoundFile).toHaveBeenCalledTimes(1);
@@ -349,7 +349,7 @@ jest.mock('./sound-player', () => {
349349
});
350350
```
351351

352-
This will let us inspect usage of our mocked class, using `SoundPlayer.mock.calls`: `expect(SoundPlayer).toHaveBeenCalled();` or near-equivalent: `expect(SoundPlayer.mock.calls.length).toEqual(1);`
352+
This will let us inspect usage of our mocked class, using `SoundPlayer.mock.calls`: `expect(SoundPlayer).toHaveBeenCalled();` or near-equivalent: `expect(SoundPlayer.mock.calls.length).toBe(1);`
353353

354354
### Mocking non-default class exports
355355

@@ -444,6 +444,6 @@ it('We can check if the consumer called a method on the class instance', () => {
444444
const soundPlayerConsumer = new SoundPlayerConsumer();
445445
const coolSoundFileName = 'song.mp3';
446446
soundPlayerConsumer.playSomethingCool();
447-
expect(mockPlaySoundFile.mock.calls[0][0]).toEqual(coolSoundFileName);
447+
expect(mockPlaySoundFile.mock.calls[0][0]).toBe(coolSoundFileName);
448448
});
449449
```

docs/JestObjectAPI.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,17 @@ const example = jest.createMockFromModule('../example');
229229

230230
test('should run example code', () => {
231231
// creates a new mocked function with no formal arguments.
232-
expect(example.function.name).toEqual('square');
233-
expect(example.function.length).toEqual(0);
232+
expect(example.function.name).toBe('square');
233+
expect(example.function.length).toBe(0);
234234

235235
// async functions get the same treatment as standard synchronous functions.
236-
expect(example.asyncFunction.name).toEqual('asyncSquare');
237-
expect(example.asyncFunction.length).toEqual(0);
236+
expect(example.asyncFunction.name).toBe('asyncSquare');
237+
expect(example.asyncFunction.length).toBe(0);
238238

239239
// creates a new class with the same interface, member functions and properties are mocked.
240-
expect(example.class.constructor.name).toEqual('Bar');
241-
expect(example.class.foo.name).toEqual('foo');
242-
expect(example.class.array.length).toEqual(0);
240+
expect(example.class.constructor.name).toBe('Bar');
241+
expect(example.class.foo.name).toBe('foo');
242+
expect(example.class.array.length).toBe(0);
243243

244244
// creates a deeply cloned version of the original object.
245245
expect(example.object).toEqual({
@@ -251,12 +251,12 @@ test('should run example code', () => {
251251
});
252252

253253
// creates a new empty array, ignoring the original array.
254-
expect(example.array.length).toEqual(0);
254+
expect(example.array.length).toBe(0);
255255

256256
// creates a new property with the same primitive value as the original property.
257-
expect(example.number).toEqual(123);
258-
expect(example.string).toEqual('baz');
259-
expect(example.boolean).toEqual(true);
257+
expect(example.number).toBe(123);
258+
expect(example.string).toBe('baz');
259+
expect(example.boolean).toBe(true);
260260
expect(example.symbol).toEqual(Symbol.for('a.b.c'));
261261
});
262262
```
@@ -380,15 +380,15 @@ test('moduleName 1', () => {
380380
return jest.fn(() => 1);
381381
});
382382
const moduleName = require('../moduleName');
383-
expect(moduleName()).toEqual(1);
383+
expect(moduleName()).toBe(1);
384384
});
385385

386386
test('moduleName 2', () => {
387387
jest.doMock('../moduleName', () => {
388388
return jest.fn(() => 2);
389389
});
390390
const moduleName = require('../moduleName');
391-
expect(moduleName()).toEqual(2);
391+
expect(moduleName()).toBe(2);
392392
});
393393
```
394394

@@ -403,15 +403,15 @@ test('moduleName 1', () => {
403403
return jest.fn(() => 1);
404404
});
405405
const moduleName = require('../moduleName');
406-
expect(moduleName()).toEqual(1);
406+
expect(moduleName()).toBe(1);
407407
});
408408

409409
test('moduleName 2', () => {
410410
jest.doMock<typeof import('../moduleName')>('../moduleName', () => {
411411
return jest.fn(() => 2);
412412
});
413413
const moduleName = require('../moduleName');
414-
expect(moduleName()).toEqual(2);
414+
expect(moduleName()).toBe(2);
415415
});
416416
```
417417

@@ -435,8 +435,8 @@ test('moduleName 1', () => {
435435
};
436436
});
437437
return import('../moduleName').then(moduleName => {
438-
expect(moduleName.default).toEqual('default1');
439-
expect(moduleName.foo).toEqual('foo1');
438+
expect(moduleName.default).toBe('default1');
439+
expect(moduleName.foo).toBe('foo1');
440440
});
441441
});
442442

@@ -449,8 +449,8 @@ test('moduleName 2', () => {
449449
};
450450
});
451451
return import('../moduleName').then(moduleName => {
452-
expect(moduleName.default).toEqual('default2');
453-
expect(moduleName.foo).toEqual('foo2');
452+
expect(moduleName.default).toBe('default2');
453+
expect(moduleName.foo).toBe('foo2');
454454
});
455455
});
456456
```

docs/MockFunctions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ expect(someMockFunction.mock.instances.length).toBe(2);
7979

8080
// The object returned by the first instantiation of this function
8181
// had a `name` property whose value was set to 'test'
82-
expect(someMockFunction.mock.instances[0].name).toEqual('test');
82+
expect(someMockFunction.mock.instances[0].name).toBe('test');
8383

8484
// The first argument of the last call to the function was 'test'
8585
expect(someMockFunction.mock.lastCall[0]).toBe('test');

docs/TutorialAsync.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import * as user from '../user';
6868
// The assertion for a promise must be returned.
6969
it('works with promises', () => {
7070
expect.assertions(1);
71-
return user.getUserName(4).then(data => expect(data).toEqual('Mark'));
71+
return user.getUserName(4).then(data => expect(data).toBe('Mark'));
7272
});
7373
```
7474

@@ -81,7 +81,7 @@ There is a less verbose way using `resolves` to unwrap the value of a fulfilled
8181
```js
8282
it('works with resolves', () => {
8383
expect.assertions(1);
84-
return expect(user.getUserName(5)).resolves.toEqual('Paul');
84+
return expect(user.getUserName(5)).resolves.toBe('Paul');
8585
});
8686
```
8787

@@ -94,13 +94,13 @@ Writing tests using the `async`/`await` syntax is also possible. Here is how you
9494
it('works with async/await', async () => {
9595
expect.assertions(1);
9696
const data = await user.getUserName(4);
97-
expect(data).toEqual('Mark');
97+
expect(data).toBe('Mark');
9898
});
9999

100100
// async/await can also be used with `.resolves`.
101101
it('works with async/await and resolves', async () => {
102102
expect.assertions(1);
103-
await expect(user.getUserName(5)).resolves.toEqual('Paul');
103+
await expect(user.getUserName(5)).resolves.toBe('Paul');
104104
});
105105
```
106106

docs/TutorialReact.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ it('CheckboxWithLabel changes the text after click', () => {
282282
// Render a checkbox with label in the document
283283
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);
284284
285-
expect(checkbox.text()).toEqual('Off');
285+
expect(checkbox.text()).toBe('Off');
286286
287287
checkbox.find('input').simulate('change');
288288
289-
expect(checkbox.text()).toEqual('On');
289+
expect(checkbox.text()).toBe('On');
290290
});
291291
```
292292

docs/TutorialjQuery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('displays a user after a click', () => {
5555
// Assert that the fetchCurrentUser function was called, and that the
5656
// #username span's inner text was updated as we'd expect it to.
5757
expect(fetchCurrentUser).toBeCalled();
58-
expect($('#username').text()).toEqual('Johnny Cash - Logged In');
58+
expect($('#username').text()).toBe('Johnny Cash - Logged In');
5959
});
6060
```
6161

e2e/__tests__/__snapshots__/nestedTestDefinitions.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports[`print correct error message with nested test definitions outside descri
3232
14 |
3333
> 15 | test('inner test', () => {
3434
| ^
35-
16 | expect(getTruthy()).toEqual('This test should not have run');
35+
16 | expect(getTruthy()).toBe('This test should not have run');
3636
17 | });
3737
18 | });
3838

e2e/__tests__/cliHandlesExactFilenames.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ test('CLI skips exact file names if no matchers matched', () => {
4747

4848
expect(result.exitCode).toBe(1);
4949
expect(result.stdout).toMatch(/No tests found([\S\s]*)2 files checked./);
50-
expect(result.stderr).toEqual('');
50+
expect(result.stderr).toBe('');
5151
});

e2e/__tests__/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ test('negated flags override previous flags', () => {
7373
'--silent',
7474
]);
7575

76-
expect(globalConfig.silent).toEqual(true);
76+
expect(globalConfig.silent).toBe(true);
7777
});

e2e/__tests__/crawlSymlinks.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ test('Node crawler picks up symlinked files when option is set as flag', () => {
4848
'--no-watchman',
4949
]);
5050

51-
expect(stdout).toEqual('');
51+
expect(stdout).toBe('');
5252
expect(stderr).toContain('Test Suites: 1 passed, 1 total');
53-
expect(exitCode).toEqual(0);
53+
expect(exitCode).toBe(0);
5454
});
5555

5656
test('Node crawler does not pick up symlinked files by default', () => {
5757
const {stdout, stderr, exitCode} = runJest(DIR, ['--no-watchman']);
5858
expect(stdout).toContain('No tests found, exiting with code 1');
59-
expect(stderr).toEqual('');
60-
expect(exitCode).toEqual(1);
59+
expect(stderr).toBe('');
60+
expect(exitCode).toBe(1);
6161
});
6262

6363
test('Should throw if watchman used with haste.enableSymlinks', () => {
@@ -71,13 +71,13 @@ test('Should throw if watchman used with haste.enableSymlinks', () => {
7171

7272
const {exitCode, stderr, stdout} = run1;
7373

74-
expect(stdout).toEqual('');
74+
expect(stdout).toBe('');
7575
expect(stderr).toMatchInlineSnapshot(`
7676
"Validation Error:
7777
7878
haste.enableSymlinks is incompatible with watchman
7979
8080
Either set haste.enableSymlinks to false or do not use watchman"
8181
`);
82-
expect(exitCode).toEqual(1);
82+
expect(exitCode).toBe(1);
8383
});

e2e/__tests__/doneInHooks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ import runJest from '../runJest';
1111
skipSuiteOnJasmine();
1212
test('`done()` works properly in hooks', () => {
1313
const {exitCode} = runJest('done-in-hooks');
14-
expect(exitCode).toEqual(0);
14+
expect(exitCode).toBe(0);
1515
});

e2e/__tests__/failureDetailsProperty.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('that the failureDetails property is set', () => {
2020
]);
2121

2222
// safety check: if the reporter errors it'll show up here
23-
expect(stderr).toStrictEqual('');
23+
expect(stderr).toBe('');
2424

2525
const output = JSON.parse(removeStackTraces(stdout));
2626

e2e/__tests__/hasteMapSha1.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ test('exits the process after test are done but before timers complete', async (
6666

6767
// Ignored files do not get the SHA-1 computed.
6868

69-
expect(hasteFS.getSha1(path.join(DIR, 'fileWithExtension.ignored'))).toBe(
70-
null,
71-
);
69+
expect(
70+
hasteFS.getSha1(path.join(DIR, 'fileWithExtension.ignored')),
71+
).toBeNull();
7272

7373
expect(
7474
hasteFS.getSha1(
7575
path.join(DIR, 'node_modules/bar/fileWithExtension.ignored'),
7676
),
77-
).toBe(null);
77+
).toBeNull();
7878
});

e2e/__tests__/multiProjectRunner.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ test.each([{projectPath: 'packages/somepackage'}, {projectPath: 'packages/*'}])(
200200
const {stdout, stderr, exitCode} = runJest(DIR, ['--no-watchman']);
201201
expect(stderr).toContain('PASS somepackage packages/somepackage/test.js');
202202
expect(stderr).toContain('Test Suites: 1 passed, 1 total');
203-
expect(stdout).toEqual('');
204-
expect(exitCode).toEqual(0);
203+
expect(stdout).toBe('');
204+
expect(exitCode).toBe(0);
205205
},
206206
);
207207

@@ -250,8 +250,8 @@ test.each([
250250
const {stdout, stderr, exitCode} = runJest(DIR, ['--no-watchman']);
251251
expect(stderr).toContain(`PASS ${displayName} ${projectPath}/test.js`);
252252
expect(stderr).toContain('Test Suites: 1 passed, 1 total');
253-
expect(stdout).toEqual('');
254-
expect(exitCode).toEqual(0);
253+
expect(stdout).toBe('');
254+
expect(exitCode).toBe(0);
255255
},
256256
);
257257

@@ -284,8 +284,8 @@ test('projects can be workspaces with non-JS/JSON files', () => {
284284
expect(stderr).toContain('PASS packages/project1/__tests__/file1.test.js');
285285
expect(stderr).toContain('PASS packages/project2/__tests__/file2.test.js');
286286
expect(stderr).toContain('Ran all test suites in 2 projects.');
287-
expect(stdout).toEqual('');
288-
expect(exitCode).toEqual(0);
287+
expect(stdout).toBe('');
288+
expect(exitCode).toBe(0);
289289
});
290290

291291
test('objects in project configuration', () => {
@@ -310,8 +310,8 @@ test('objects in project configuration', () => {
310310
expect(stderr).toContain('PASS __tests__/file1.test.js');
311311
expect(stderr).toContain('PASS __tests__/file2.test.js');
312312
expect(stderr).toContain('Ran all test suites in 2 projects.');
313-
expect(stdout).toEqual('');
314-
expect(exitCode).toEqual(0);
313+
expect(stdout).toBe('');
314+
expect(exitCode).toBe(0);
315315
});
316316

317317
test('allows a single project', () => {
@@ -330,8 +330,8 @@ test('allows a single project', () => {
330330
const {stdout, stderr, exitCode} = runJest(DIR, ['--no-watchman']);
331331
expect(stderr).toContain('PASS __tests__/file1.test.js');
332332
expect(stderr).toContain('Test Suites: 1 passed, 1 total');
333-
expect(stdout).toEqual('');
334-
expect(exitCode).toEqual(0);
333+
expect(stdout).toBe('');
334+
expect(exitCode).toBe(0);
335335
});
336336

337337
test('resolves projects and their <rootDir> properly', () => {

e2e/__tests__/runProgrammaticallyMultipleProjects.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ const dir = resolve(__dirname, '../run-programmatically-multiple-projects');
1414
test('run programmatically with multiple projects', () => {
1515
const {stderr, exitCode} = run('node run-jest.js', dir);
1616
const {summary} = extractSummary(stripAnsi(stderr));
17-
expect(exitCode).toEqual(0);
17+
expect(exitCode).toBe(0);
1818
expect(summary).toMatchSnapshot('summary');
1919
});

0 commit comments

Comments
 (0)