Skip to content

Commit

Permalink
fix(tests): update tests for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwils committed May 29, 2024
1 parent c459f47 commit 0c29991
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions src/event-mixin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,36 @@ describe('a child class', () => {
});
});

// New test cases for the path functionality
describe('DeepNestedEvents with path', () => {
class DeepNestedEvents {
eventContainer = {
deeper: {
eventOne: new TypedEvent<(value: number) => void>(),
eventTwo: new TypedEvent<(value: boolean) => void>(),
},
};

fireEventOne() {
this.eventContainer.deeper.eventOne.emit(42);
}

fireEventTwo() {
this.eventContainer.deeper.eventTwo.emit(true);
}
interface NestedEvents {
eventOne: TypedEvent<(value: number) => void>;
eventTwo: TypedEvent<(value: boolean) => void>;
}

interface InvalidPathEvents {
eventOne: TypedEvent<(value: number) => void>;
}
class _Nested {
eventContainer = {
deeper: {
eventOne: new TypedEvent<(value: number) => void>(),
eventTwo: new TypedEvent<(value: boolean) => void>(),
},
};

fireEventOne() {
this.eventContainer.deeper.eventOne.emit(42);
}

fireEventTwo() {
this.eventContainer.deeper.eventTwo.emit(true);
}
}

const NestedEventsClass = AddEvents<
typeof DeepNestedEvents,
{
eventOne: TypedEvent<(value: number) => void>;
eventTwo: TypedEvent<(value: boolean) => void>;
}
>(DeepNestedEvents, 'eventContainer.deeper');
const Nested = AddEvents<typeof _Nested, NestedEvents>(_Nested, 'eventContainer.deeper');
const InvalidPath = AddEvents<typeof _Nested, InvalidPathEvents>(_Nested, 'eventContainer.unknown');

const myClass = new NestedEventsClass();
describe('a nested class with path', () => {
const myClass = new Nested();
it('should notify handlers when nested events are fired', () => {
expect.hasAssertions();
const handlerOneArgs: number[] = [];
Expand All @@ -124,14 +126,7 @@ describe('DeepNestedEvents with path', () => {
it('should throw an error when trying to subscribe to an event with an invalid path', () => {
expect.hasAssertions();

const InvalidPathClass = AddEvents<
typeof DeepNestedEvents,
{
eventOne: TypedEvent<(value: number) => void>;
}
>(DeepNestedEvents, 'eventContainer.unknown');

const instance = new InvalidPathClass();
const instance = new InvalidPath();

// Trying to bind an event handler to an invalid path
expect(() => {
Expand Down

0 comments on commit 0c29991

Please sign in to comment.