Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 338 forks source link

TypeError: Cannot use 'in' operator to search for 'withCredentials' in undefined #218

Open rahulkelaskar opened 1 year ago

rahulkelaskar commented 1 year ago

The library doesn't pass through Jest unit test. On debug it is observed that NativeEventSource is undefined. Since the Jest runs on terminal NativeEventSource is undefined. var R = NativeEventSource if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {

I've tried multiple ways, but couldn't find any solution.

I'm currently using angular: 12.2.0 "jest": "^27.0.3", "jest-junit": "^11.1.0", "jest-preset-angular": "9.0.0", "jest-zone-patch": "~0.0.10",

Yaffle commented 1 year ago

NativeEventSource is not undefined so, otherwise the "in" is not executed because of the short-circuit evaluation and "NativeEventSource == undefined" check. perhaps, you have NativeEventSource.prototype == undefined, which is weird. could you just do something to set it to non-undefined value? (or just do globalThis.EventSource = undefined)