-
Notifications
You must be signed in to change notification settings - Fork 0
/
argsTest.js
78 lines (64 loc) · 1.19 KB
/
argsTest.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-env jest */
var args = require("./"),
emit
beforeEach(function() {
emit = require("@emit-js/emit")()
args(emit)
emit.args("test", {
a: {
alias: "b",
},
})
emit.args("test", {
a: {
default: true,
},
})
emit.args("test2", {
c: { alias: ["d"] },
})
})
test("state", function() {
expect(emit.state.args).toEqual({
test: {
a: {
alias: ["b"],
default: true,
},
},
test2: {
c: {
alias: ["d"],
},
},
})
})
test("alias args", function() {
expect.assertions(2)
emit.any("test", function(arg) {
expect(arg.a).toBe(1)
})
emit.any("test2", function(arg) {
expect(arg.c).toBe(2)
})
emit.test({ a: 1 })
emit.test2({ c: 2 })
})
test("alias args (array concat)", function() {
expect.assertions(2)
emit.any("test", function(arg) {
expect(arg.a).toEqual([2, 1])
})
emit.any("test2", function(arg) {
expect(arg.c).toEqual([4, 3])
})
emit.test({ a: [1], b: [2] })
emit.test2({ c: [3], d: [4] })
})
test("alias args (default)", function() {
expect.assertions(1)
emit.any("test", function(arg) {
expect(arg.a).toBe(true)
})
emit.test()
})