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 }}
Repository navigation
Tests after upgrading [react-scripts] to version 4 fail #10571
After updating react-scripts to version 4+ more than half of the tests started to fail. But if I run any of the failing tests in VSCode or from jest they don't fail and work as before.
Looks like any of the mocks I use in my ./src/setupTests.ts file aren't picked up when I run react-scripts test.
Found an issue. From 4+ version of react-scripts--resetMocks is true by default. Fixed it by making react-scripts test --resetMocks=false.
Reacted by Joseph Thomaschaske, natashasheviakova, nhasrha1, Marcus, Nikhil Singh, Andreas Möller, Sandino, Chaitanya Sai Terli, MiroslavPetrik, Michael Waddell and 13 more
Reacted by Nikhil Singh
Reacted by Marcus, Nikhil Singh, Nathan Lyle Black, rhys-mondo, Alexander Gschwend, Maytee Sánchez and Carlton Van Putten
Reacted by MiroslavPetrik, rhys-mondo, Maytee Sánchez and Priscilla Romagnoli
Reacted by Marcus, Nikhil Singh, Jakub Abramowski, MiroslavPetrik, rhys-mondo, Maytee Sánchez, Matthew Israelson and Tristan Deane
The error I see it is `Error: Uncaught [TypeError: this.AppsSDK.getAppSettings is not a function]``
So it is like the mock is not working (this is related to the flag resetMocks=false but how??)
I can not see what the problem here is.
I see that SDK is jest.mockConstructor and it has nothing on it (as the methods I mocked were not mocked at all)
If someone can point out what was going on here I really appreciate any kind of advice.
Regards.
@wamujlb I tried as you suggested and without the --resetMocks flag it fails the same way, it says getAppSettings is not a function. Thank you anyway, I am still curious why the mock of the class constructor does not work without that flag, even in that simple case you provided.
On Thu, May 20, 2021, 19:43 Sandino ***@***.***> wrote:
@wamujlb <https://github.com/wamujlb> I tried as you suggested and
without the --resetMocks flag it fails the same way, it says getAppSettings
is not a function. Thank you anyway, I am still curious why the mock of the
class constructor does not work without that flag, even in that simple case
you provided.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10571 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADRW5VCVYTKX3DKPS7R4IWLTOVC4ZANCNFSM4XYUWRGQ>
.
It seems after using resetMocks: false the jest.spyOn is not working at all.
Code snippet that fails
// Spying and mockingjest.spyOn(viqMES,'getSuggestedPeopleService').mockImplementation(()=>Promise.resolve(// some response));// Assertionexpect(viqMES.getSuggestedPeopleService).toHaveBeenCalledTimes(1);
The assertion fails with
Expected number of calls: 1
Received number of calls: 0
Activity
wamujlb commentedon Feb 24, 2021
Found an issue. From 4+ version of
react-scripts--resetMocksistrueby default. Fixed it by makingreact-scripts test --resetMocks=false.sandinosaso commentedon May 20, 2021
I am not sure why, but this same makes my tests break passing --resetMocks=false solved it.
I am interested in knowing why this is happening.
What I do in some tests is mock a library (private) that export SDK class, in the code we use it like this:
Then we call methods on it (i.e lib.getAppSettings(), etc) ... I mock those methods for testing purposes the following way:
The error I see it is `Error: Uncaught [TypeError: this.AppsSDK.getAppSettings is not a function]``
So it is like the mock is not working (this is related to the flag resetMocks=false but how??)
I can not see what the problem here is.
I see that SDK is jest.mockConstructor and it has nothing on it (as the methods I mocked were not mocked at all)
If someone can point out what was going on here I really appreciate any kind of advice.
Regards.
wamujlb commentedon May 20, 2021
@sandinosaso Could you please try to remove this:
mockGetAppSettings(...args)use like:
getAppSettings: jest.fn((...args) => {}),
sandinosaso commentedon May 20, 2021
@wamujlb I tried as you suggested and without the --resetMocks flag it fails the same way, it says getAppSettings is not a function. Thank you anyway, I am still curious why the mock of the class constructor does not work without that flag, even in that simple case you provided.
wamujlb commentedon May 20, 2021
sandinosaso commentedon May 20, 2021
@wamujlb I did it, but seems that codesanbox does not support
jest.mock:( ...Do you know any other live coding tool that does?https://codesandbox.io/s/test-jestmock-j9xqt
Thank you in advance for your help
wamujlb commentedon May 20, 2021
papuruth commentedon Oct 4, 2021
It seems after using resetMocks: false the jest.spyOn is not working at all.
Code snippet that fails
The assertion fails with
Expected number of calls: 1
Received number of calls: 0
ozluy commentedon Oct 22, 2021
--resetMocks=falseflag and override withreact-app-rewiredworked for me