Closed hpohlmeyer closed 9 months ago
This is a great find, @hpohlmeyer! Thank you for fixing this.
Yes, adding an integration test that does exactly what you do in that code snippet would be essential. Would you have a chance to add it, please? You can put it in test/modules/XMLHttpRequest/compliance/xhr-event-callback-null
. A better name for the test module is also welcome!
Let me know if you need any help writing that test.
@kettanaito sorry for not responding sooner. I am on vacation right now. I will be back next week.
I did write some tests already, but was not sure where to put it. Thanks for pointing me to the right file. I will probably be able to add the tests on Monday.
I am thinking of logging the actual value instead of making the property access optional. Do you think this would be helpful or make the logging output too verbose? If it is too verbose we could at least log the value type.
@hpohlmeyer, I think it's enough to put your usage scenario from the description and assert that the request doesn't error. We shouldn't assert the name
or anything since those are implementation details.
Okay, I have added some tests and I am just logging the event listener now.
This has been released in v0.25.8!
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.
When a XMLHttpRequest event handler is reset by setting it to
null
, an error will be thrown, that @mswjs/interceptors cannot access the propertyname
onnull
. Here is an example of that error:This PR prevents the error by not accessing the
name
property if the listener isundefined | null
;Do you think it needs tests, or is it fine as-is?