-
Notifications
You must be signed in to change notification settings - Fork 2
test: unit test fails when using after msw 2.6.x #187
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
Changes from 2 commits
461ec57
2099af0
8b9bd9b
be3d641
55e737d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
22.7.0 | ||
22.11.0 |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import { | |
beforeAll, | ||
vi, | ||
} from 'vitest' | ||
import fetch from 'cross-fetch' | ||
// import fetch from 'cross-fetch' | ||
import { HttpResponse, http, delay, StrictRequest } from 'msw' | ||
import assert from 'assert' | ||
import { SetupServer } from 'msw/node' | ||
|
@@ -52,10 +52,7 @@ suite('internal/remote/ApiClient', () => { | |
|
||
suite('getEvaluations', () => { | ||
test('success', async () => { | ||
const requestInterceptor = vi.fn< | ||
[StrictRequest<GetEvaluationsRequest>], | ||
void | ||
>() | ||
const requestInterceptor = vi.fn((_request: StrictRequest<GetEvaluationsRequest>) => {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. requestInterceptor should look like this with new mswjs version |
||
|
||
server.use( | ||
http.post< | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ export function setupServerAndListen( | |||||||
...handlers: Array<RequestHandler> | ||||||||
): SetupServer { | ||||||||
const server = setupServer(...handlers) | ||||||||
server.listen({ onUnhandledRequest: 'error' }) | ||||||||
server.listen({ onUnhandledRequest: 'warn' }) | ||||||||
|
"warn" (Default) | Print a warning but perform the request as-is. |
---|---|
"error" | Print an error and halt request execution. |
"bypass" | Does not print anything and perform the request as-is. |
======================
If we want to keep using the error
option, We could update the flush
test case @cre8ivejp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I restored the code be3d641
The unhandled request was created because the cross-fetch
was not working as expected.
We don't need to change any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cross-fetch
is outdated and isn't getting any update more than a years.since Fetch is widely available (at least from Node.js 18 and higher).
so we could get rid of "cross-fetch" as a dependency.
I am testing more to make sure. So far all tests passed when run on both browser & node environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with node 18 and higher and it seems good.
mswjs example for
vitest
could run on both browser & node environment withoutcross-fetch
https://github.com/mswjs/examples/tree/main/examples/with-vitest