-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(types): add createEventBus compile time type checks test
added expect-type which is jest like compile time type checks test framework added coverage for createEventBus return type check to prevent type regression in the futur
- Loading branch information
1 parent
41ac9be
commit cc074b8
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { expectTypeOf } from 'expect-type' | ||
import { createEventBus } from '../src/Events' | ||
import { Slot, slot } from '../src/Slot' | ||
|
||
describe('createEventBus', () => { | ||
type Events = { | ||
numberToString: Slot<number, string> | ||
eventToIgnore: Slot<void, void> | ||
} | ||
|
||
type FilteredEvents = { | ||
numberToString: Slot<number, string> | ||
} | ||
|
||
const events: Events = { | ||
numberToString: slot<number, string>(), | ||
eventToIgnore: slot<void, void>(), | ||
} | ||
|
||
it('should return the right types regardless of an ingnoredEvents list being passed or not', () => { | ||
const eventBus = createEventBus({ events }) | ||
const eventBusWithIgnored = createEventBus({ | ||
events, | ||
ignoredEvents: ['eventToIgnore'], | ||
}) | ||
|
||
expectTypeOf(eventBus).toEqualTypeOf<Events>() | ||
expectTypeOf(eventBus).not.toEqualTypeOf<FilteredEvents>() | ||
expectTypeOf(eventBusWithIgnored).not.toEqualTypeOf<Events>() | ||
expectTypeOf(eventBusWithIgnored).toEqualTypeOf<FilteredEvents>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters