-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
35 lines (31 loc) · 775 Bytes
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import test from 'ava'
import { Emitter } from './'
type Actions = {
SHOULD_OPEN_MODAL: boolean
SHOULD_CLOSE_MODAL: boolean
}
const store: { [id: number]: boolean } = {
123: false
}
class App extends Emitter<Actions, number> { }
const app = new App({
SHOULD_CLOSE_MODAL: ({ id, value }) => {
const previousValue = store[id]
store[id] = value
return previousValue
},
SHOULD_OPEN_MODAL: ({ id, value }) => {
const previousValue = store[id]
store[id] = value
return previousValue
}
})
test('it should trigger subscribers', t => {
t.plan(3)
app.on('SHOULD_OPEN_MODAL').subscribe(_ => {
t.is(_.id, 123)
t.is(_.previousValue, false)
t.is(_.value, true)
})
app.dispatch('SHOULD_OPEN_MODAL', { id: 123, value: true })
})