-
Notifications
You must be signed in to change notification settings - Fork 3
/
mockExamples.test.brs
90 lines (72 loc) · 2.39 KB
/
mockExamples.test.brs
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
79
80
81
82
83
84
85
86
87
88
89
90
' @import /components/KopytkoTestSuite.brs from @dazn/kopytko-unit-testing-framework
' @mock /components/Math.brs
' @mock /components/sum.brs
function TestSuite__mockExamples() as Object
ts = KopytkoTestSuite()
ts.name = "Mock Examples"
beforeEach(sub ()
mockFunction("sum").returnValue(111)
end sub)
it("should return sum value passed in before each hook", function () as String
' Then
return expect(funcCallingSum()).toBe(111)
end function)
it("should be able to mock Math.multiply implementation", function () as String
' When
m.__expected = 222
mockFunction("Math.multiply").implementation(function (_params as Object, context as Object) as Integer
return context.__expected
end function)
' Then
return expect(funcCallingMultiply()).toBe(m.__expected)
end function)
it("should be able to mock Math.multiply return value", function () as String
' When
expected = 333
mockFunction("Math.multiply").returnValue(expected)
' Then
return expect(funcCallingMultiply()).toBe(expected)
end function)
it("should be able to mock Math.multiply error", function () as String
' When
expected = "Some mocked error"
mockFunction("Math.multiply").throw(expected)
' Then
return expect(funcCallingMultiply).toThrow(expected)
end function)
it("should be able to reset all previous mocks", function () as String
' Given
mockFunction("Math.multiply").returnValue(444)
' When
mockFunction("Math.multiply").clear()
' Then
return expect(funcCallingMultiply()).toBe(0)
end function)
it("should be able to mock property value", function () as String
' When
mockFunction("Math").setProperty("Pi", 4.123)
' Then
return expect(funcReturningPi()).toBe(4.123)
end function)
it("should be able to mock multiple property values", function () as Object
' When
mockFunction("Math").setProperties({
Pi: 10.1112,
Tau: 55555.1,
})
' Then
return [
expect(funcReturningPi()).toBe(10.1112),
expect(funcReturningTau()).toBe(55555.1),
]
end function)
' This test needs to be at the bottom
it("should clear all mock calls from previous tests", function () as Object
' Then
return [
expect("Math.multiply").toHaveBeenCalledTimes(0),
expect(mockFunction("Math.multiply").getCalls()).toEqual([]),
]
end function)
return ts
end function