remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/libs/remix-lib/test/eventManager.ts

36 lines
1.1 KiB

'use strict'
import tape from 'tape'
import { EventManager } from '../src/eventManager'
tape('eventManager', function (t) {
t.test('eventManager', function (st) {
const events = new EventManager()
9 months ago
const listener = {}
let trace = ''
9 months ago
listener['listen'] = function (data1) {
trace += data1
}
const registeredFunction = function (data) {
trace += data
}
9 months ago
events.register('event1', listener, listener['listen'])
events.register('event2', registeredFunction, null)
events.trigger('event1', ['event1'])
events.trigger('event2', ['event2'])
st.equal(trace, 'event1event2')
9 months ago
events.unregister('event1', listener['listen'], null)
st.equal(events.registered['event1'].length, 1)
st.equal(events.registered['event2'].length, 1)
9 months ago
events.unregister('event1', listener, listener['listen'])
st.equal(events.registered['event1'].length, 0)
st.equal(events.registered['event2'].length, 1)
events.unregister('event2', registeredFunction, null)
st.equal(events.registered['event1'].length, 0)
st.equal(events.registered['event2'].length, 0)
st.end()
})
})