-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sinon stubbing failed after upgrade to 3.9.2 #38568
Comments
The same problem exists for jasmine's Should we tell those libraries to adapt their code or can we have a flag to keep those properties enumerable? |
I found this code to break when upgrading from 3.8.2 to 3.9.2. We use import * as foo from 'some/path'
jest.spyOn(foo, 'bar'); I would get an error like:
I resolved this by doing this workaround: jest.mock('some/path', () => ({
...jest.requireActual('some/path'),
}));
const foo = require('some/path'); It's not pretty, but it at least unblocked me from upgrading. |
ES module exports are specified to not be enumerable, so this is the expected behavior. Prior behavior was out of compliance with the spec. |
Does your comment still apply if we are using Before
After
Both modules work fine, but the latter (3.9) breaks our ability to mock the imported functions with |
If you're targeting This code is effectively not legal ES, since it's attempting to modify (indirectly via |
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
See jasmine/jasmine#1817 (comment) for a temporary workaround. |
@RyanCavanaugh Sorry, I didn't understand your answer when you said
I created a demo project here typescript-3.9-commonjs with a very simple node script. |
Just the workaround i was looking for! |
Yeah, having the same issue, very annoying 👍 |
…etCurrentUser due to version change It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
… we can stub them as part of the TypeScript 3.9.2+ update It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 Currently, my package-lock.json has 3.9.5, so that appears to be why I was having these problems in my test. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The solution is to make an object, FacultyAPI, that contains those functions and export the object instead of the functions themselves
…SchedulesForYear It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
The latest version of @atomist/skill is compiled with TypeScript 3.9, which introduces the change mentioned here microsoft/TypeScript#38568 , making it more difficult to mock wildcard imports. Worked around this for now by mocking the underlying console.info call. [changelog:changed]
Hi @SimenB not sure if you are aware of this ? I assume once jest supports fully esm this won’t be an issue ? |
Jest module mocks should work regardless, but you probably need to use That said, semantics in Jest are probably off for ESM behaviour up until ESM support stabilises |
…etCurrentUser due to version change It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
… we can stub them as part of the TypeScript 3.9.2+ update It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 Currently, my package-lock.json has 3.9.5, so that appears to be why I was having these problems in my test. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The solution is to make an object, FacultyAPI, that contains those functions and export the object instead of the functions themselves
…SchedulesForYear It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
…etCurrentUser due to version change It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
… we can stub them as part of the TypeScript 3.9.2+ update It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The test in App.test.tsx was failing when it tried to get the callCount for a stub for a free-standing function getCurrentUser, and currently, my package-lock.json has 3.9.5, so that appears to be why. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 Currently, my package-lock.json has 3.9.5, so that appears to be why I was having these problems in my test. My fix was to use an object where the functions become methods instead.
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 The solution is to make an object, FacultyAPI, that contains those functions and export the object instead of the functions themselves
…SchedulesForYear It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562 Export Multi Year Plan function from the API so that it is no longer a free-standing function and can be used appropriately in the test and in the multi year plan code.
getMetadata cannot be exported as a standalone function. It turns out that you can no longer stub free-standing functions in Typescript 3.9.2+ according to this issue: microsoft/TypeScript#38568 sinonjs/sinon#562
@RyanCavanaugh Though may I ask you to consider testability. |
@AndyOGo see jasmine/jasmine#1817 (comment) for an easy workaround monkey-patching |
Related: |
I did a similar thing with babel, https://github.com/snyk/babel-plugin-mutable-imports , but ended up just forking sinon to make it warn, and fixing all the code. sinonjs/sinon#2319 |
I noticed this only breaks if there is an
|
Hi @RyanCavanaugh so if we are targeting 'commonjs', how can be writing without ES module imports/exports in ts 3.9? I mean how can we make it mutable? Thanks. |
TypeScript Version: 3.9.2, 3.9.3
Search Terms: sinon, stub
Code
Run the start.ts script by compiling it with
tsc
or simply usets-node
.I'd expect it print fake stub but now it prints real stub. It's working as expected for typescript@3.8 or lower, start breaking from 3.9.2.
Expected behavior:
Print "fake stub"
Actual behavior:
Print "real stub"
Playground Link: Can't provide Playground link because it contains multiple files
Related Issues: Nope
The text was updated successfully, but these errors were encountered: