jest-test-custom-events
v0.1.0
Published
Jest test matchers for comparing custom events
Readme
Jest Test Custom Events
An NPM package which adds a custom matcher to Jest allowing for testing of CustomEvents.
Installation
npm install -D jest-test-custom-eventsExample Usage
// file: example.test.ts
import { test, expect } from "@jest/globals";
import "jest-test-custom-events";
test("example test", () => {
const customEvent = new CustomEvent("custom-event-name", {
bubbles: true,
composed: true,
detail: {
exampleProperty: true
}
});
expect(customEvent).toMatchCustomEvent({
type: "custom-event-name",
bubbles: true,
composed: true,
detail: {
exampleProperty: true
}
})
});Well you may think you're able to do this with the built-in isEqual matcher, CustomEvent is implemented in such a way as to make it's properties non-enumerable, and hence almost always pass on deep equality checks.
