diff --git a/src/components/wormhole.ts b/src/components/wormhole.ts index 4d4ab50..cb94ada 100644 --- a/src/components/wormhole.ts +++ b/src/components/wormhole.ts @@ -89,12 +89,14 @@ export const Wormhole = Vue.extend({ this.$delete(this.sources, source) }, hasTarget(to: string) { - return !!this.targets[to] && this.targets[to][0] + return !!(this.targets[to] && this.targets[to][0]) }, hasSource(to: string) { - return !!this.sources[to] && this.sources[to][0] + return !!(this.sources[to] && this.sources[to][0]) + }, + hasContentFor(to: string) { + return !!this.transports[to] && !!this.transports[to].length }, - // Internal $_getTransportIndex({ to, from }: TransportVector): number { for (const i in this.transports[to]) { diff --git a/tests/unit/specs/wormhole.spec.js b/tests/unit/specs/wormhole.spec.js index e51eb16..ac18b34 100644 --- a/tests/unit/specs/wormhole.spec.js +++ b/tests/unit/specs/wormhole.spec.js @@ -106,7 +106,7 @@ describe('Wormhole', function() { wormhole.registerTarget('target', new Vue({})) const check2 = wormhole.hasTarget('target') - expect(check2).toEqual(expect.any(Object)) + expect(check2).toEqual(true) wormhole.unregisterTarget('target') const check3 = wormhole.hasTarget('target') @@ -119,10 +119,25 @@ describe('Wormhole', function() { wormhole.registerSource('source', new Vue({})) const check2 = wormhole.hasSource('source') - expect(check2).toEqual(expect.any(Object)) + expect(check2).toEqual(true) wormhole.unregisterSource('source') const check3 = wormhole.hasSource('source') expect(check3).toEqual(false) }) + + it('hasContentFor() returns boolean depending on content', () => { + expect(wormhole.hasContentFor('test')).toBe(false) + wormhole.open({ + to: 'test', + from: 'test-source', + passengers: ['fakeVNode'], + }) + expect(wormhole.hasContentFor('test')).toBe(true) + wormhole.close({ + to: 'test', + from: 'test-source', + }) + expect(wormhole.hasContentFor('test')).toBe(false) + }) })