Repository: facebook/jest
File: packages/jest-types/__typetests__/jest.test.ts (TypeScript)

Code before:
    Promise.resolve(false),
  ),
).type.toRaiseError();

expect(jest.requireActual('./pathToModule')).type.toBeUnknown();
expect(jest.requireActual<{some: 'module'}>('./pathToModule')).type.toEqual<{
  some: 'module';
}>();
expect(jest.requireActual()).type.toRaiseError();

expect(jest.requireMock('./pathToModule')).type.toBeUnknown();
expect(jest.requireMock<{some: 'module'}>('./pathToModule')).type.toEqual<{
  some: 'module';
}>();
expect(jest.requireMock()).type.toRaiseError();

expect(jest.resetModules()).type.toEqual<typeof jest>();
expect(jest.resetModules('moduleName')).type.toRaiseError();

expect(jest.setMock('moduleName', {a: 'b'})).type.toEqual<typeof jest>();
expect(jest.setMock('moduleName')).type.toRaiseError();

expect(jest.unmock('moduleName')).type.toEqual<typeof jest>();
expect(jest.unmock()).type.toRaiseError();

expect(jest.unstable_unmockModule('moduleName')).type.toEqual<typeof jest>();
expect(jest.unstable_unmockModule()).type.toRaiseError();

// Mock Functions

expect(jest.clearAllMocks()).type.toEqual<typeof jest>();
expect(jest.clearAllMocks('moduleName')).type.toRaiseError();

expect(jest.resetAllMocks()).type.toEqual<typeof jest>();
expect(jest.resetAllMocks(true)).type.toRaiseError();

expect(jest.restoreAllMocks()).type.toEqual<typeof jest>();
expect(jest.restoreAllMocks(false)).type.toRaiseError();

expect(jest.isMockFunction(() => {})).type.toBeBoolean();
expect(jest.isMockFunction()).type.toRaiseError();

const maybeMock = (a: string, b: number) => true;

if (jest.isMockFunction(maybeMock)) {
  expect(maybeMock).type.toEqual<Mock<(a: string, b: number) => boolean>>();

  maybeMock.mockReturnValueOnce(false);
  expect(maybeMock.mockReturnValueOnce(123)).type.toRaiseError();
}


Review comment (suggestion):
Thanks. The type test looks good.

Some matchers got renamed in latest version of TSTyche (the type testing tool). Both `toEqual` and `toBe` do the same job, but would be better to use the new name here (I just opened an upgrade PR #15088):

```suggestion
expect(jest.unstable_unmockModule('moduleName')).type.toBe<typeof jest>();
```

Code after:
    Promise.resolve(false),
  ),
).type.toRaiseError();

expect(jest.requireActual('./pathToModule')).type.toBeUnknown();
expect(jest.requireActual<{some: 'module'}>('./pathToModule')).type.toBe<{
  some: 'module';
}>();
expect(jest.requireActual()).type.toRaiseError();

expect(jest.requireMock('./pathToModule')).type.toBeUnknown();
expect(jest.requireMock<{some: 'module'}>('./pathToModule')).type.toBe<{
  some: 'module';
}>();
expect(jest.requireMock()).type.toRaiseError();

expect(jest.resetModules()).type.toBe<typeof jest>();
expect(jest.resetModules('moduleName')).type.toRaiseError();

expect(jest.setMock('moduleName', {a: 'b'})).type.toBe<typeof jest>();
expect(jest.setMock('moduleName')).type.toRaiseError();

expect(jest.unmock('moduleName')).type.toBe<typeof jest>();
expect(jest.unmock()).type.toRaiseError();

expect(jest.unstable_unmockModule('moduleName')).type.toBe<typeof jest>();
expect(jest.unstable_unmockModule()).type.toRaiseError();

// Mock Functions

expect(jest.clearAllMocks()).type.toBe<typeof jest>();
expect(jest.clearAllMocks('moduleName')).type.toRaiseError();

expect(jest.resetAllMocks()).type.toBe<typeof jest>();
expect(jest.resetAllMocks(true)).type.toRaiseError();

expect(jest.restoreAllMocks()).type.toBe<typeof jest>();
expect(jest.restoreAllMocks(false)).type.toRaiseError();

expect(jest.isMockFunction(() => {})).type.toBeBoolean();
expect(jest.isMockFunction()).type.toRaiseError();

const maybeMock = (a: string, b: number) => true;

if (jest.isMockFunction(maybeMock)) {
  expect(maybeMock).type.toBe<Mock<(a: string, b: number) => boolean>>();

  maybeMock.mockReturnValueOnce(false);
  expect(maybeMock.mockReturnValueOnce(123)).type.toRaiseError();
}