TypeError: expected.toLowerCase() is not a function when using "rest.all()"
See original GitHub issueDescribe the bug
When using rest.all()
to mock all requests of a given path, it blocks HMR (and other requests).
That’s due to an issue with the usage of isStringEqual
in the file src/utils/request/onUnhandledRequest.ts
.
It assumes that method
is always a string and with the introduction of rest.all
it seems to be a RegExp
now.
Environment
msw: 0.36.0
nodejs: 14.17.6
npm: 6.14.15
yarn: 1.22.15
Chrome: Version 96.0.4664.55 (Official Build) (x86_64)
To Reproduce
Steps to reproduce the behavior:
- Scaffold a create-react-app
- Set up MSW with a
rest.all()
handler (mine was like this:rest.all('/todos', (req, res, ctx) => {...});
- Run
yarn start
- Make a change on one of the files
- See error in the console like the ones below:
Expected behavior
Requests not targeted by the rest.all()
should still be performed.
By temporarily patching the rest-deps changing the return to:
return actual.toString().toLowerCase() === expected.toString().toLowerCase();
solved the issue, but I know that’s not the right fix 😄
Screenshots
HMR broken:
(also messes requests for the chrome extension)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
javascript - .toLowerCase not working, replacement function?
The .toLowerCase() function only exists on strings. You can call .toString() on anything in JavaScript to get a string representation.
Read more >[Solved] TypeError: toLowerCase is not a function in JavaScript
TypeError : .toLowerCase is not a function occurs when we call toLowerCase() function on object which is not an string. toLowerCase() function can...
Read more >parseInt() - JavaScript - MDN Web Docs
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
Read more >Best Practices for Spies, Stubs and Mocks in Sinon.js
Thankfully, we can use Sinon.js to avoid all the hassles involved. ... the example function, we call two functions in it — toLowerCase...
Read more >Node.js v19.3.0 Documentation
Iterates through the list of functions passed to tracker.calls() and will throw an error for functions that have not been called the expected...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The fix has been released in 0.36.2.
Hi @kettanaito,
From what I can see, you’re creating
all
as RegExp handler: https://github.com/mswjs/msw/blob/master/src/rest.ts#L35I was checking on the integration tests and it hasn’t been caught on them because you always have a fallback -
rest.all('*', () => { ... });
- and you check against that generic response.The issue here is exactly the case where you set up something like:
And a request is done to say
/another/different/endpoint
… Not having any generic request should let it pass and request the actual resource… right?