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: docs/JestObjectAPI.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -699,6 +699,10 @@ test('plays audio', () => {
699
699
});
700
700
```
701
701
702
+
### `jest.Spied<Source>`
703
+
704
+
See [TypeScript Usage](MockFunctionAPI.md#jestspiedsource) chapter of Mock Functions page for documentation.
705
+
702
706
### `jest.clearAllMocks()`
703
707
704
708
Clears the `mock.calls`, `mock.instances`, `mock.contexts` and `mock.results` properties of all mocks. Equivalent to calling [`.mockClear()`](MockFunctionAPI.md#mockfnmockclear) on every mocked function.
import {afterEach, expect, jest, test} from'@jest/globals';
662
+
import {setDateNow} from'./__utils__/setDateNow';
663
+
664
+
let spiedDateNow:jest.Spied<typeofDate.now> |undefined=undefined;
665
+
666
+
afterEach(() => {
667
+
spiedDateNow?.mockReset();
668
+
});
669
+
670
+
test('renders correctly with a given date', () => {
671
+
spiedDateNow=setDateNow(1482363367071);
672
+
// ...
673
+
674
+
expect(spiedDateNow).toHaveBeenCalledTimes(1);
675
+
});
676
+
```
677
+
678
+
Types of a class or function can be passed as type argument to `jest.Spied<Source>`. If you prefer to constrain the input type, use: `jest.SpiedClass<Source>` or `jest.SpiedFunction<Source>`.
679
+
680
+
Use `jest.SpiedGetter<Source>` or `jest.SpiedSetter<Source>` to create the type of a spied getter or setter respectively.
0 commit comments