How to define a type for mocked function in node test? #51176
-
Let’s say I have a class called abstract class Base {
public async call() {
// some logic
}
} In unit test I have to mock mock.method(Base.prototype, “call”).mock.mockImplementation(async() => {
// something here
});
assert.equal(Base.prototype.call.mock.callCount(), 1); Typescript shows error in VS code where Node version: 20 LTS |
Beta Was this translation helpful? Give feedback.
Answered by
varunkamra
Dec 17, 2023
Replies: 1 comment
-
Found a solution on stackoverflow. I had to define a custom type like this: type GenericFunction {
(): any,
mock: any
} then use the type to typecast like following:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
varunkamra
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a solution on stackoverflow. I had to define a custom type like this:
then use the type to typecast like following:
assert.equal((<GenericFunction>Base.prototype.call).mock.callCount(), 1);