Last active
November 27, 2018 16:07
-
-
Save itsMapleLeaf/1d5f862e96e105cfdc28cd0381d50346 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| test('Emitter', () => { | |
| const emitter = new Emitter() | |
| let counter = 0 | |
| const increment = () => counter += 1 | |
| // test the handler being fired | |
| emitter.on('increment', increment) | |
| emitter.emit('increment') | |
| expect(counter).toBe(1) | |
| // test that the handler isn't fired after being unassigned | |
| emitter.off('increment', increment) | |
| emitter.emit('increment') | |
| expect(counter).toBe(1) | |
| // test that once unbinds after being fired | |
| emitter.once('increment', increment) | |
| emitter.emit('increment') | |
| expect(counter).toBe(2) | |
| emitter.emit('increment') | |
| expect(counter).toBe(2) | |
| // test getListenerCount | |
| emitter.on('increment', increment) | |
| emitter.on('increment', increment) | |
| emitter.on('increment', increment) | |
| emitter.on('notincrement', increment) | |
| expect(emitter.getListenerCount('increment')).toBe(3) | |
| expect(emitter.getListenerCount('notincrement')).toBe(1) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment