/
Example2Test.js
60 lines (43 loc) · 1.62 KB
/
Example2Test.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
describe("Duplicator Example 2", function() {
var viewModel;
beforeEach(function() {
viewModel = DuplicatorExample2();
});
it("initializes", function() {
expect(viewModel.input()).toEqual("");
expect(viewModel.output()).toEqual("");
});
it("entering text doesn't trigger calculation", function(){
viewModel.input("10");
expect(viewModel.output()).toEqual("");
});
it("hitting the calc button triggeres the calculation", function(){
viewModel.input("10");
viewModel.calc();
expect(viewModel.inputValidation()).toEqual(true);
expect(viewModel.output()).toEqual("20");
});
it("should validate that input is numeric", function(){
viewModel.input("garbage");
viewModel.calc();
expect(viewModel.inputValidation()).toEqual(false);
})
it("should validate that input is not empty", function(){
viewModel.input("");
viewModel.calc();
expect(viewModel.inputValidation()).toEqual(false);
})
it("should not indicate validation error, after input is corrected", function(){
viewModel.input("garbage");
viewModel.calc();
expect(viewModel.inputValidation()).toEqual(false);
viewModel.input("101");
viewModel.calc();
expect(viewModel.inputValidation()).toEqual(true);
});
it("should show a validation message to the user when input is not numeric", function(){
viewModel.input("garbage");
viewModel.calc();
expect(viewModel.validationMessage()).toEqual("You must enter a number!");
});
});