Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-mock):
generateFromMetadata
return type
- Loading branch information
1 parent
2fa8763
commit 7f18c36
Showing
2 changed files
with
109 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {expectType} from 'tsd-lite'; | ||
import {MockMetadata, Mocked, ModuleMocker} from 'jest-mock'; | ||
|
||
class ExampleClass { | ||
memberA: Array<number>; | ||
|
||
constructor() { | ||
this.memberA = [1, 2, 3]; | ||
} | ||
memberB() {} | ||
} | ||
|
||
const exampleModule = { | ||
instance: new ExampleClass(), | ||
|
||
methodA: function square(a: number, b: number) { | ||
return a * b; | ||
}, | ||
methodB: async function asyncSquare(a: number, b: number) { | ||
const result = (await a) * b; | ||
return result; | ||
}, | ||
|
||
propertyA: { | ||
one: 'foo', | ||
three: { | ||
nine: 1, | ||
ten: [1, 2, 3], | ||
}, | ||
two() {}, | ||
}, | ||
propertyB: [1, 2, 3], | ||
propertyC: 123, | ||
propertyD: 'baz', | ||
propertyE: true, | ||
propertyF: Symbol.for('a.b.c'), | ||
}; | ||
|
||
const moduleMocker = new ModuleMocker(globalThis); | ||
|
||
// getMetadata | ||
|
||
const exampleMetadata = moduleMocker.getMetadata(exampleModule); | ||
|
||
expectType<MockMetadata<typeof exampleModule> | null>(exampleMetadata); | ||
|
||
// generateFromMetadata | ||
|
||
expectType<Mocked<typeof exampleModule>>( | ||
moduleMocker.generateFromMetadata(exampleMetadata!), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters