-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
55 lines (48 loc) · 1.15 KB
/
test.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const Broadcaster = require("./index")
const mockStore = {
actions: [],
dispatch: function(action){
this.actions.push(action)
}
}
let redispatchedActions = []
const mockReactor = (action)=>{
redispatchedActions.push(action)
store.dispatch(action)
}
const store = Broadcaster(mockStore, mockReactor)
store.dispatch({
type: "SAY",
payload: "HELLO"
})
store.dispatch({
type: "SAY",
payload: "GOODBYE"
})
let errors = []
test = "Broadcaster should send local actions to store"
if(mockStore.actions.length < 2){
errors.push(test)
console.log(`${test} - failed`)
}else{
console.log(`${test} - passed`)
}
test = "Broadcaster should properly filter actions that have previously dispatched on store"
if(mockStore.actions.length > 2){
errors.push(test)
console.log(`${test} - failed`)
}else{
console.log(`${test} - passed`)
}
test = "Broadcaster should redispatch actions to remote dispatcher (generally socket broadcast)"
if(redispatchedActions.length !== 2){
errors.push(test)
console.log(`${test} - failed`)
}else{
console.log(`${test} - passed`)
}
if(errors.length !== 0){
throw errors.join(". ")
}else{
console.log("ALL TESTS PASSED")
}