diff --git a/package.json b/package.json index 404a8d6..17ffde5 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@types/chrome": "^0.0.155", "@types/jest": "^26.0.20", "@types/ws": "^3.2.1", + "expect-type": "^0.13.0", "husky": "^4.3.8", "jest": "^28.1.3", "npm-run-all": "^4.1.5", diff --git a/test/Types.spec.ts b/test/Types.spec.ts new file mode 100644 index 0000000..e54d0a8 --- /dev/null +++ b/test/Types.spec.ts @@ -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 + eventToIgnore: Slot + } + + type FilteredEvents = { + numberToString: Slot + } + + const events: Events = { + numberToString: slot(), + eventToIgnore: slot(), + } + + 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() + expectTypeOf(eventBus).not.toEqualTypeOf() + expectTypeOf(eventBusWithIgnored).not.toEqualTypeOf() + expectTypeOf(eventBusWithIgnored).toEqualTypeOf() + }) +}) diff --git a/yarn.lock b/yarn.lock index a0bda9a..9e699fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2091,6 +2091,11 @@ exit@^0.1.2: resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" integrity sha1-BjJjj42HfMghB9MKD/8aF8uhzQw= +expect-type@^0.13.0: + version "0.13.0" + resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.13.0.tgz#916646a7a73f3ee77039a634ee9035efe1876eb2" + integrity sha512-CclevazQfrqo8EvbLPmP7osnb1SZXkw47XPPvUUpeMz4HuGzDltE7CaIt3RLyT9UQrwVK/LDn+KVcC0hcgjgDg== + expect@^28.1.3: version "28.1.3" resolved "https://registry.yarnpkg.com/expect/-/expect-28.1.3.tgz#90a7c1a124f1824133dd4533cce2d2bdcb6603ec"