You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@
14
14
### Chore & Maintenance
15
15
16
16
-`[*]` Replace internal usage of `pretty-format/ConvertAnsi` with `jest-serializer-ansi-escapes` ([#12935](https://github.com/facebook/jest/pull/12935), [#13004](https://github.com/facebook/jest/pull/13004))
Copy file name to clipboardexpand all lines: docs/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -481,7 +481,17 @@ Determines if the given function is a mocked function.
481
481
482
482
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
483
483
484
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
484
+
:::note
485
+
486
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
487
+
488
+
:::
489
+
490
+
:::tip
491
+
492
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
493
+
494
+
:::
485
495
486
496
Example:
487
497
@@ -500,14 +510,17 @@ Example test:
500
510
```js
501
511
constvideo=require('./video');
502
512
513
+
afterEach(() => {
514
+
// restore the spy created with spyOn
515
+
jest.restoreAllMocks();
516
+
});
517
+
503
518
test('plays video', () => {
504
519
constspy=jest.spyOn(video, 'play');
505
520
constisPlaying=video.play();
506
521
507
522
expect(spy).toHaveBeenCalled();
508
523
expect(isPlaying).toBe(true);
509
-
510
-
spy.mockRestore();
511
524
});
512
525
```
513
526
@@ -547,14 +560,17 @@ Example test:
547
560
constaudio=require('./audio');
548
561
constvideo=require('./video');
549
562
563
+
afterEach(() => {
564
+
// restore the spy created with spyOn
565
+
jest.restoreAllMocks();
566
+
});
567
+
550
568
test('plays video', () => {
551
569
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
Copy file name to clipboardexpand all lines: website/versioned_docs/version-25.x/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -471,7 +471,17 @@ Determines if the given function is a mocked function.
471
471
472
472
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
473
473
474
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
474
+
:::note
475
+
476
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
477
+
478
+
:::
479
+
480
+
:::tip
481
+
482
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
483
+
484
+
:::
475
485
476
486
Example:
477
487
@@ -490,14 +500,17 @@ Example test:
490
500
```js
491
501
constvideo=require('./video');
492
502
503
+
afterEach(() => {
504
+
// restore the spy created with spyOn
505
+
jest.restoreAllMocks();
506
+
});
507
+
493
508
test('plays video', () => {
494
509
constspy=jest.spyOn(video, 'play');
495
510
constisPlaying=video.play();
496
511
497
512
expect(spy).toHaveBeenCalled();
498
513
expect(isPlaying).toBe(true);
499
-
500
-
spy.mockRestore();
501
514
});
502
515
```
503
516
@@ -537,14 +550,17 @@ Example test:
537
550
constaudio=require('./audio');
538
551
constvideo=require('./video');
539
552
553
+
afterEach(() => {
554
+
// restore the spy created with spyOn
555
+
jest.restoreAllMocks();
556
+
});
557
+
540
558
test('plays video', () => {
541
559
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
Copy file name to clipboardexpand all lines: website/versioned_docs/version-26.x/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -475,7 +475,17 @@ Determines if the given function is a mocked function.
475
475
476
476
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
477
477
478
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
478
+
:::note
479
+
480
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
481
+
482
+
:::
483
+
484
+
:::tip
485
+
486
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
487
+
488
+
:::
479
489
480
490
Example:
481
491
@@ -494,14 +504,17 @@ Example test:
494
504
```js
495
505
constvideo=require('./video');
496
506
507
+
afterEach(() => {
508
+
// restore the spy created with spyOn
509
+
jest.restoreAllMocks();
510
+
});
511
+
497
512
test('plays video', () => {
498
513
constspy=jest.spyOn(video, 'play');
499
514
constisPlaying=video.play();
500
515
501
516
expect(spy).toHaveBeenCalled();
502
517
expect(isPlaying).toBe(true);
503
-
504
-
spy.mockRestore();
505
518
});
506
519
```
507
520
@@ -541,14 +554,17 @@ Example test:
541
554
constaudio=require('./audio');
542
555
constvideo=require('./video');
543
556
557
+
afterEach(() => {
558
+
// restore the spy created with spyOn
559
+
jest.restoreAllMocks();
560
+
});
561
+
544
562
test('plays video', () => {
545
563
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
Copy file name to clipboardexpand all lines: website/versioned_docs/version-27.x/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -475,7 +475,17 @@ Determines if the given function is a mocked function.
475
475
476
476
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
477
477
478
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
478
+
:::note
479
+
480
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
481
+
482
+
:::
483
+
484
+
:::tip
485
+
486
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
487
+
488
+
:::
479
489
480
490
Example:
481
491
@@ -494,14 +504,17 @@ Example test:
494
504
```js
495
505
constvideo=require('./video');
496
506
507
+
afterEach(() => {
508
+
// restore the spy created with spyOn
509
+
jest.restoreAllMocks();
510
+
});
511
+
497
512
test('plays video', () => {
498
513
constspy=jest.spyOn(video, 'play');
499
514
constisPlaying=video.play();
500
515
501
516
expect(spy).toHaveBeenCalled();
502
517
expect(isPlaying).toBe(true);
503
-
504
-
spy.mockRestore();
505
518
});
506
519
```
507
520
@@ -541,14 +554,17 @@ Example test:
541
554
constaudio=require('./audio');
542
555
constvideo=require('./video');
543
556
557
+
afterEach(() => {
558
+
// restore the spy created with spyOn
559
+
jest.restoreAllMocks();
560
+
});
561
+
544
562
test('plays video', () => {
545
563
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
Copy file name to clipboardexpand all lines: website/versioned_docs/version-28.0/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -481,7 +481,17 @@ Determines if the given function is a mocked function.
481
481
482
482
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
483
483
484
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
484
+
:::note
485
+
486
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
487
+
488
+
:::
489
+
490
+
:::tip
491
+
492
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
493
+
494
+
:::
485
495
486
496
Example:
487
497
@@ -500,14 +510,17 @@ Example test:
500
510
```js
501
511
constvideo=require('./video');
502
512
513
+
afterEach(() => {
514
+
// restore the spy created with spyOn
515
+
jest.restoreAllMocks();
516
+
});
517
+
503
518
test('plays video', () => {
504
519
constspy=jest.spyOn(video, 'play');
505
520
constisPlaying=video.play();
506
521
507
522
expect(spy).toHaveBeenCalled();
508
523
expect(isPlaying).toBe(true);
509
-
510
-
spy.mockRestore();
511
524
});
512
525
```
513
526
@@ -547,14 +560,17 @@ Example test:
547
560
constaudio=require('./audio');
548
561
constvideo=require('./video');
549
562
563
+
afterEach(() => {
564
+
// restore the spy created with spyOn
565
+
jest.restoreAllMocks();
566
+
});
567
+
550
568
test('plays video', () => {
551
569
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
Copy file name to clipboardexpand all lines: website/versioned_docs/version-28.1/JestObjectAPI.md
+21-7
Original file line number
Diff line number
Diff line change
@@ -481,7 +481,17 @@ Determines if the given function is a mocked function.
481
481
482
482
Creates a mock function similar to `jest.fn` but also tracks calls to `object[methodName]`. Returns a Jest [mock function](MockFunctionAPI.md).
483
483
484
-
_Note: By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`_
484
+
:::note
485
+
486
+
By default, `jest.spyOn` also calls the **spied** method. This is different behavior from most other test libraries. If you want to overwrite the original function, you can use `jest.spyOn(object, methodName).mockImplementation(() => customImplementation)` or `object[methodName] = jest.fn(() => customImplementation);`
487
+
488
+
:::
489
+
490
+
:::tip
491
+
492
+
Since `jest.spyOn` is a mock. You could restore the initial state calling [jest.restoreAllMocks](#jestrestoreallmocks) on [afterEach](GlobalAPI.md#aftereachfn-timeout) method.
493
+
494
+
:::
485
495
486
496
Example:
487
497
@@ -500,14 +510,17 @@ Example test:
500
510
```js
501
511
constvideo=require('./video');
502
512
513
+
afterEach(() => {
514
+
// restore the spy created with spyOn
515
+
jest.restoreAllMocks();
516
+
});
517
+
503
518
test('plays video', () => {
504
519
constspy=jest.spyOn(video, 'play');
505
520
constisPlaying=video.play();
506
521
507
522
expect(spy).toHaveBeenCalled();
508
523
expect(isPlaying).toBe(true);
509
-
510
-
spy.mockRestore();
511
524
});
512
525
```
513
526
@@ -547,14 +560,17 @@ Example test:
547
560
constaudio=require('./audio');
548
561
constvideo=require('./video');
549
562
563
+
afterEach(() => {
564
+
// restore the spy created with spyOn
565
+
jest.restoreAllMocks();
566
+
});
567
+
550
568
test('plays video', () => {
551
569
constspy=jest.spyOn(video, 'play', 'get'); // we pass 'get'
0 commit comments