Skip to content

Commit

Permalink
chore(typetests): replace expectError<T> with `expectNotAssignable<…
Browse files Browse the repository at this point in the history
…T>` (#14204)
  • Loading branch information
mrazauskas committed Jun 21, 2023
1 parent 45daa05 commit 96a9702
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
10 changes: 5 additions & 5 deletions packages/jest-resolve/__typetests__/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectAssignable, expectError, expectType} from 'tsd-lite';
import {expectAssignable, expectNotAssignable, expectType} from 'tsd-lite';
import type {
AsyncResolver,
JestResolver,
Expand All @@ -26,7 +26,7 @@ expectAssignable<PackageJSON>({
values: [0, 10, 20, {x: 1, y: 2}, true, 'test', ['a', 'b']],
});

expectError<PackageJSON>({
expectNotAssignable<PackageJSON>({
filter: () => {},
});

Expand Down Expand Up @@ -77,7 +77,7 @@ const asyncResolver: AsyncResolver = async (path, options) => {
};

const notReturningAsyncResolver = async () => {};
expectError<AsyncResolver>(notReturningAsyncResolver());
expectNotAssignable<AsyncResolver>(notReturningAsyncResolver());

// SyncResolver

Expand All @@ -98,11 +98,11 @@ const syncResolver: SyncResolver = (path, options) => {
};

const notReturningSyncResolver = () => {};
expectError<SyncResolver>(notReturningSyncResolver());
expectNotAssignable<SyncResolver>(notReturningSyncResolver());

// JestResolver

expectAssignable<JestResolver>({async: asyncResolver});
expectAssignable<JestResolver>({sync: syncResolver});
expectAssignable<JestResolver>({async: asyncResolver, sync: syncResolver});
expectError<JestResolver>({});
expectNotAssignable<JestResolver>({});
22 changes: 11 additions & 11 deletions packages/jest-snapshot/__typetests__/SnapshotResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectError, expectType} from 'tsd-lite';
import {expectNotAssignable, expectType} from 'tsd-lite';
import type {SnapshotResolver} from 'jest-snapshot';

// SnapshotResolver
Expand All @@ -28,65 +28,65 @@ const snapshotResolver: SnapshotResolver = {

// resolveSnapshotPath

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: (testPath: string, snapshotExtension: boolean) =>
'snapshot/path',
resolveTestPath: () => 'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: (testPath: boolean) => 'snapshot/path',
resolveTestPath: () => 'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => true,
resolveTestPath: () => 'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveTestPath: () => 'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

// resolveTestPath

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
resolveTestPath: (snapshotPath: string, snapshotExtension: boolean) =>
'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
resolveTestPath: (snapshotPath: boolean) => 'test/path',
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
resolveTestPath: () => true,
testPathForConsistencyCheck: 'test/path/example',
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
testPathForConsistencyCheck: 'test/path/example',
});

// testPathForConsistencyCheck

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
resolveTestPath: () => 'test/path',
testPathForConsistencyCheck: true,
});

expectError<SnapshotResolver>({
expectNotAssignable<SnapshotResolver>({
resolveSnapshotPath: () => 'snapshot/path',
resolveTestPath: () => 'test/path',
});
22 changes: 11 additions & 11 deletions packages/jest-types/__typetests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectAssignable, expectError} from 'tsd-lite';
import {expectAssignable, expectNotAssignable} from 'tsd-lite';
import type {Config} from '@jest/types';

expectAssignable<Config.InitialOptions>({});
Expand Down Expand Up @@ -77,7 +77,7 @@ expectAssignable<Config.InitialOptions>({
},
});

expectError<Config.InitialOptions>({
expectNotAssignable<Config.InitialOptions>({
fakeTimers: {
now: new Date(),
},
Expand All @@ -86,34 +86,34 @@ expectError<Config.InitialOptions>({
expectAssignable<Config.InitialOptions>({
fakeTimers: {
enableGlobally: true,
legacyFakeTimers: true,
legacyFakeTimers: true as const,
},
});

expectError<Config.InitialOptions>({
expectNotAssignable<Config.InitialOptions>({
fakeTimers: {
advanceTimers: true,
legacyFakeTimers: true,
legacyFakeTimers: true as const,
},
});

expectError<Config.InitialOptions>({
expectNotAssignable<Config.InitialOptions>({
fakeTimers: {
doNotFake,
legacyFakeTimers: true,
legacyFakeTimers: true as const,
},
});

expectError<Config.InitialOptions>({
expectNotAssignable<Config.InitialOptions>({
fakeTimers: {
legacyFakeTimers: true,
legacyFakeTimers: true as const,
now: 1483228800000,
},
});

expectError<Config.InitialOptions>({
expectNotAssignable<Config.InitialOptions>({
fakeTimers: {
legacyFakeTimers: true,
legacyFakeTimers: true as const,
timerLimit: 1000,
},
});
8 changes: 3 additions & 5 deletions packages/jest-types/__typetests__/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,16 @@ expectType<[]>(mockObjectB.methodA.mock.calls[0]);
expectType<[b: string]>(mockObjectB.methodB.mock.calls[0]);
expectType<[c: number]>(mockObjectB.methodC.mock.calls[0]);

expectError<[t: number]>(mockObjectB.one.more.time.mock.calls[0]);
expectError(mockObjectB.one.more.time.mock.calls[0]);

expectType<[one: string, two?: boolean]>(mockObjectB.SomeClass.mock.calls[0]);
expectType<[]>(mockObjectB.SomeClass.prototype.methodA.mock.calls[0]);
expectType<[a: string, b?: number]>(
mockObjectB.SomeClass.prototype.methodB.mock.calls[0],
);

expectError<[]>(mockObjectB.someClassInstance.methodA.mock.calls[0]);
expectError<[a: string, b?: number]>(
mockObjectB.someClassInstance.methodB.mock.calls[0],
);
expectError(mockObjectB.someClassInstance.methodA.mock.calls[0]);
expectError(mockObjectB.someClassInstance.methodB.mock.calls[0]);

expectError(mockObjectB.methodA.mockReturnValue(123));
expectError(mockObjectB.methodA.mockImplementation((a: number) => 123));
Expand Down
14 changes: 7 additions & 7 deletions packages/jest-worker/__typetests__/jest-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectError, expectType} from 'tsd-lite';
import {expectError, expectNotAssignable, expectType} from 'tsd-lite';
import type {JestWorkerFarm} from 'jest-worker';
import type * as testWorker from './testWorker';

Expand Down Expand Up @@ -62,13 +62,13 @@ expectError(detectedWorkerFarm.isResult);
expectError(detectedWorkerFarm.setup());
expectError(detectedWorkerFarm.teardown());

expectError<Promise<void>>(detectedWorkerFarm.end());
expectNotAssignable<Promise<void>>(detectedWorkerFarm.end());
expectType<Promise<{forceExited: boolean}>>(detectedWorkerFarm.end());

expectError<Promise<string>>(detectedWorkerFarm.getStderr());
expectNotAssignable<Promise<string>>(detectedWorkerFarm.getStderr());
expectType<NodeJS.ReadableStream>(detectedWorkerFarm.getStderr());

expectError<Promise<string>>(detectedWorkerFarm.getStdout());
expectNotAssignable<Promise<string>>(detectedWorkerFarm.getStdout());
expectType<NodeJS.ReadableStream>(detectedWorkerFarm.getStdout());

// typed JestWorkerFarm
Expand All @@ -90,11 +90,11 @@ expectError(typedWorkerFarm.teardown());

expectType<Promise<void>>(typedWorkerFarm.start());

expectError<Promise<void>>(typedWorkerFarm.end());
expectNotAssignable<Promise<void>>(typedWorkerFarm.end());
expectType<Promise<{forceExited: boolean}>>(typedWorkerFarm.end());

expectError<Promise<string>>(typedWorkerFarm.getStderr());
expectNotAssignable<Promise<string>>(typedWorkerFarm.getStderr());
expectType<NodeJS.ReadableStream>(typedWorkerFarm.getStderr());

expectError<Promise<string>>(typedWorkerFarm.getStdout());
expectNotAssignable<Promise<string>>(typedWorkerFarm.getStdout());
expectType<NodeJS.ReadableStream>(typedWorkerFarm.getStdout());

0 comments on commit 96a9702

Please sign in to comment.