mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
523 stars 118 forks source link

fix(CancelableMessageEvent): add setters for "cancelable" and "defaultPrevented" #546

Closed kettanaito closed 2 months ago

kettanaito commented 2 months ago

Without these setters, using CancelableMessageEvent in HappyDOM fails:

TypeError: Cannot set property defaultPrevented of #<CancelableMessageEvent> which has only a getter
 ❯ new Event node_modules/happy-dom/src/event/Event.ts:18:25
 ❯ new MessageEvent node_modules/happy-dom/src/event/events/MessageEvent.ts:25:3
 ❯ new CancelableMessageEvent node_modules/@mswjs/interceptors/src/interceptors/WebSocket/utils/events.ts:16:5
 ❯ WebSocketOverride.WebSocketClassTransport.socket.<computed> node_modules/@mswjs/interceptors/src/interceptors/WebSocket/WebSocketClassTransport.ts:40:13
 ❯ node_modules/@mswjs/interceptors/src/interceptors/WebSocket/WebSocketOverride.ts:140:3
 ❯ node:internal/process/task_queues:140:7
 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9
 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8

HappyDOM sets the cancelable and defaultPrevented properties directly although those properties have no setters per spec (I may be wrong).

HappyDOM sets those properties in the constructor so, technically, it's not forbidden since they use the setters to provide initial values for those properties. It's clashing syntax-wise since the Interceptor's implementation is more strict.

kettanaito commented 2 months ago

Released: v0.27.1 🎉

This has been released in v0.27.1!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.