You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 22, 2024. It is now read-only.
Using stub to temporarily set an object property to a non-function value should be possible, such as in this TypeScript code:
fancy.stub(process.stdout,"isTTY",false).it("Sets isTTY to false",()=>{expect(process.stdout.isTTY).to.equal(false);});
Actual behavior
This causes a compile error:
Argument of type 'false' is not assignable to parameter of type '() => any'.
Additional info
While it might look tempting to use () => false as the final argument to stub, this does not create the desired behavior because it sets process.stdout.isTTY to be a function.
Note that this issue is similar to #40, but is intended to encompass any case where the value to be stubbed is not a function or a getter.
I'd be happy to submit a PR with a fix for this issue, if you'd like one. The implementation of stub is arguably correct, except for the types.
Workaround
Cast the 3rd parameter to any, like this and the code works correctly:
fancy.stub(process.stdout,"isTTY",falseasany).it("Sets isTTY to false",()=>{expect(process.stdout.isTTY).to.equal(false);});
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Expected behavior
Using stub to temporarily set an object property to a non-function value should be possible, such as in this TypeScript code:
Actual behavior
This causes a compile error:
Additional info
While it might look tempting to use
() => false
as the final argument to stub, this does not create the desired behavior because it setsprocess.stdout.isTTY
to be a function.Note that this issue is similar to #40, but is intended to encompass any case where the value to be stubbed is not a function or a getter.
I'd be happy to submit a PR with a fix for this issue, if you'd like one. The implementation of
stub
is arguably correct, except for the types.Workaround
Cast the 3rd parameter to
any
, like this and the code works correctly:The text was updated successfully, but these errors were encountered: