EventTarget.test.js 613 B

12345678910111213141516171819202122
  1. import EventTarget from '../src/EventTarget'
  2. describe('EventTarget', () => {
  3. it('addEventListener', () => {
  4. const target = new EventTarget()
  5. const listener = jest.fn()
  6. target.addEventListener('foo', listener)
  7. target.dispatchEvent({ type: 'foo' })
  8. expect(listener).toHaveBeenCalledTimes(1)
  9. })
  10. it('removeEventListener', () => {
  11. const target = new EventTarget()
  12. const listener = jest.fn()
  13. target.addEventListener('foo', listener)
  14. target.removeEventListener('foo', listener)
  15. target.dispatchEvent({ type: 'foo' })
  16. expect(listener).toHaveBeenCalledTimes(0)
  17. })
  18. })