Skip to content

Commit

Permalink
Add test cases for BusHelper.removeListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxedoxt committed Mar 13, 2023
1 parent 1cc34e9 commit 1855c3b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/BusHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,31 @@ test('propsEvents', async () => {
await helper.set('VirtualProperty', buildTypedValue('string', 'bar'))
await expect(res).resolves.toMatchObject({ VirtualProperty: { signature: 's', value: 'bar' } })
})

test('removeListeners', async () => {
const helper = new BusHelper(dbus, TEST_NAME, TEST_OBJECT, TEST_IFACE, { useProps: true, usePropsEvents: true })

const dummyCb = () => {}

// Init with listener on helper (directly attached dummyCb) and _propsProxy (through method call triggered _prepare)
helper.on('PropertiesChanged', dummyCb)
await helper.callMethod('Echo', 'ping')
expect(helper.listenerCount('PropertiesChanged')).toBeGreaterThan(0)
expect(helper._propsProxy.listenerCount('PropertiesChanged')).toBeGreaterThan(0)

// Test remove
helper.removeListeners()
expect(helper.listenerCount('PropertiesChanged')).toBe(0)
expect(helper._propsProxy.listenerCount('PropertiesChanged')).toBe(0)

// Test reuse after remove (same initialization as before)
helper.on('PropertiesChanged', dummyCb)
await helper.callMethod('Echo', 'ping')
expect(helper.listenerCount('PropertiesChanged')).toBeGreaterThan(0)
expect(helper._propsProxy.listenerCount('PropertiesChanged')).toBeGreaterThan(0)

// Remove second time
helper.removeListeners()
expect(helper.listenerCount('PropertiesChanged')).toBe(0)
expect(helper._propsProxy.listenerCount('PropertiesChanged')).toBe(0)
})

0 comments on commit 1855c3b

Please sign in to comment.