Skip to content

Commit

Permalink
feat: add 'hasContentFor()' method (#195)
Browse files Browse the repository at this point in the history
back to wormhole

close #194
  • Loading branch information
LinusBorg authored Apr 14, 2019
1 parent 4f22b57 commit 25aa31c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/components/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
19 changes: 17 additions & 2 deletions tests/unit/specs/wormhole.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
})
})

0 comments on commit 25aa31c

Please sign in to comment.