Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rajat19 committed Nov 28, 2021
1 parent 0c8014f commit 93234bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@

- `[jest-core]` Add support for `testResultsProcessor` written in ESM ([#12006](https://github.com/facebook/jest/pull/12006))
- `[jest-diff, pretty-format]` Add `compareKeys` option for custom sorting of object keys ([#11992](https://github.com/facebook/jest/pull/11992))
- `[jest-mock]` Add `ts-jest` mock util functions ([#12089](https://github.com/facebook/jest/pull/12089))
- `[jest-mock]` Add `ts-jest` mock util functions ([#12089](https://github.com/facebook/jest/pull/12089))

### Fixes

Expand Down
21 changes: 10 additions & 11 deletions docs/JestObjectAPI.md
Expand Up @@ -597,32 +597,31 @@ export const foo = {
},
},
name: () => 'foo',
}
};
```

```ts
// foo.spec.ts
import { foo } from './foo'
jest.mock('./foo')
import {foo} from './foo';
jest.mock('./foo');

// here the whole foo var is mocked deeply
const mockedFoo = jest.mocked(foo, true)
const mockedFoo = jest.mocked(foo, true);

test('deep', () => {
// there will be no TS error here, and you'll have completion in modern IDEs
mockedFoo.a.b.c.hello('me')
mockedFoo.a.b.c.hello('me');
// same here
expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1)
})
expect(mockedFoo.a.b.c.hello.mock.calls).toHaveLength(1);
});

test('direct', () => {
foo.name()
foo.name();
// here only foo.name is mocked (or its methods if it's an object)
expect(mocked(foo.name).mock.calls).toHaveLength(1)
})
expect(mocked(foo.name).mock.calls).toHaveLength(1);
});
```


## Mock Timers

### `jest.useFakeTimers(implementation?: 'modern' | 'legacy')`
Expand Down

0 comments on commit 93234bd

Please sign in to comment.