fix: Ensure Response#mode is 'cors' when Request#type is 'cors' #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request ensures that the
Response#mode
property is properly set to"cors"
when thetype
property of theRequest
is set to"cors"
. This also ensures that the defaultResponse#mode
is"cors"
per the Fetch API specification (Bun sets it to"default"
.The most important changes include setting the
mode
property correctly in thecreateCustomRequest
function, updating theFetchMocker
class to set response properties, and modifying theMockServer
tests to validate response status and type.Replaces and closes #57.
Improvements to
fetch
API handling:src/custom-request.js
: Added logic to set themode
property to "cors" by default if not specified, ensuring consistency across different runtimes.src/fetch-mocker.js
: Updated theFetchMocker
class to set theurl
andtype
properties of the response based on the request'smode
.Updates to test cases:
tests/custom-request.test.js
: Added a test case to verify that the defaultmode
of aCustomRequest
is "cors".tests/fetch-mocker.test.js
: Added test cases to ensure that the response type is set correctly based on the request'smode
.tests/mock-server.test.js
: Modified existing tests to validate response status and type instead of the URL, ensuring comprehensive coverage of the new behavior. [1] [2] [3] [4] [5]