Reputation: 4127
I've a simple code base, and I'm using Jest for unit tests, combined with MSW version 2. APIs are properly mocked. I'm checking a fetch call, and I've an issue when it's time to compare symbols instead of object.
This code passes the test
expect(global.fetch).toHaveBeenCalledWith(
expect.objectContaining({
method: "POST",
url: "http://localhost/v1/message",
}),
);
while this
expect(global.fetch).toHaveBeenCalledWith(
expect.objectContaining({
method: "POST",
state: {
body: {
source: {
origin: "http://localhost/",
origin_id: "SL",
message: "Hello, this is a test message!",
}
}
},
url: "http://localhost/v1/message",
}),
);
has the following error
Expected: ObjectContaining {"_bodyText": "{\"origin\":\"http://localhost/\",\"origin_id\":\"SL\",\"message\":\"Hello, this is a test message!\"}", "method": "POST", "url": "http://localhost/v1/message"}
Received: {Symbol(realm): {"settingsObject": {"baseUrl": "http://localhost/", "origin": "http://localhost", "policyContainer": {"referrerPolicy": "strict-origin-when-cross-origin"}}}, Symbol(state): {"body": {"length": 106, "source": "{\"origin\":\"http://localhost/\",\"origin_id\":\"SL\",\"message\":\"Hello, this is a test message!\"}", "stream": {"constructor": [Function ReadableStream], Symbol(kType): "ReadableStream", Symbol(kState): {"controller": {Symbol(kType): "ReadableStreamDefaultController", Symbol(kState): {"cancelAlgorithm": [Function cancel1Algorithm], "closeRequested": true, "highWaterMark": 1, "pullAgain": false, "pullAlgorithm": [Function pullAlgorithm], "pulling": false, "queue": [{"size": 1, "value": [123, 34, 111, 114, 105, 103, 105, 110, 34, 58, …]}], "queueTotalSize": 1, "sizeAlgorithm": [Function size], "started": true, "stream": {Symbol(kType): "ReadableStream", Symbol(kState): [Circular], Symbol(nodejs.webstream.isClosedPromise): {"promise": {}, "reject": [Function anonymous], "resolve": [Function anonymous]}, Symbol(nodejs.webstream.controllerErrorFunction): [Function bound error]}}}, "disturbed": false, "reader": undefined, "state": "readable", "storedError": undefined, "transfer": {"port1": undefined, "port2": undefined, "promise": undefined, "writable": undefined}}, Symbol(nodejs.webstream.isClosedPromise): {"promise": {}, "reject": [Function anonymous], "resolve": [Function anonymous]}, Symbol(nodejs.webstream.controllerErrorFunction): [Function bound error]}}, "cache": "default", "client": {"baseUrl": "http://localhost/", "origin": "http://localhost", "policyContainer": {"referrerPolicy": "strict-origin-when-cross-origin"}}, "credentials": "same-origin", "cryptoGraphicsNonceMetadata": "", "destination": "", "done": false, "headersList": {"cookies": null, Symbol(headers map): Map {"content-type" => {"name": "content-type", "value": "application/json"}}, Symbol(headers map sorted): null}, "historyNavigation": false, "initiator": "", "integrity": "", "keepalive": false, "localURLsOnly": false, "method": "POST", "mode": "cors", "origin": "client", "parserMetadata": "", "policyContainer": "client", "preventNoCacheCacheControlHeaderModification": false, "priority": null, "redirect": "follow", "redirectCount": 0, "referrer": "client", "referrerPolicy": "", "reloadNavigation": false, "replacesClientId": "", "reservedClient": null, "responseTainting": "basic", "serviceWorkers": "all", "taintedOrigin": false, "timingAllowFailed": false, "unsafeRequest": false, "url": "http://localhost/v1/message", "urlList": ["http://localhost/v1/message"], "useCORSPreflightFlag": false, "useCredentials": false, "userActivation": false, "window": "client"}, Symbol(signal): {Symbol(realm): {"settingsObject": {"baseUrl": "http://localhost/", "origin": "http://localhost", "policyContainer": {"referrerPolicy": "strict-origin-when-cross-origin"}}}}, Symbol(abortController): {Symbol(SameObject caches): {"signal": {Symbol(realm): {"settingsObject": {"baseUrl": "http://localhost/", "origin": "http://localhost", "policyContainer": {"referrerPolicy": "strict-origin-when-cross-origin"}}}}}}, Symbol(headers): {Symbol(headers list): {"cookies": null, Symbol(headers map): Map {"content-type" => {"name": "content-type", "value": "application/json"}}, Symbol(headers map sorted): null}, Symbol(guard): "request", Symbol(realm): {"settingsObject": {"baseUrl": "http://localhost/", "origin": "http://localhost", "policyContainer": {"referrerPolicy": "strict-origin-when-cross-origin"}}}}}
Symbol(state) can't be tested as an object.
Ideas on how to fix it?
Upvotes: 0
Views: 37