/
tests.js
200 lines (170 loc) · 4.48 KB
/
tests.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
if (typeof module !== 'undefined') {
var Testing = require('./testing');
} else {
var Testing = {};
this['git://github.com/oatkiller/testingjs.git'](Testing);
}
var Runner = Testing.Runner;
var Test = Testing.Test;
var Assert = Testing.Assert;
var Equals = Testing.Equals;
var Suite = Testing.Suite;
var Resume = Testing.Resume;
var Wait = Testing.Wait;
var basicTest = function () {
var runner = new Runner();
var suite = new Suite({
runner : runner,
'1+1 should not equal 3' : function () {
Assert(1+1!==3,'they did equal 3');
},
// this should fail
'1+1 should equal 3' : function () {
Assert(1+1===3,'they didnt equal 3');
}
});
suite.run();
};
//basicTest();
if (typeof module === 'undefined') {
var testExport = function () {
var testing = {};
this['git://github.com/oatkiller/testingjs.git'](testing);
var runner = new testing.Runner();
var suite = new testing.Suite({
runner : runner,
'1+1 should not equal 3' : function () {
testing.Assert(1+1!==3,'they did equal 3');
},
// this should fail
'1+1 should equal 3' : function () {
testing.Assert(1+1===3,'they didnt equal 3');
}
});
suite.run();
};
//testExport();
}
var testSetupAndTearDown = function () {
// In this example, I'll test the methods of a class
// A Widget class that has children
var Widget = function () {
this.children = [];
};
// a hasChildren method that will return true if the widget has children
Widget.prototype.hasChildren = function () {
return this.children.length > 0;
};
var runner = new Runner();
var suite = new Suite({
runner : runner,
// define the optional setUp method
// this will be run before each test
setUp : function () {
// we will use a new widget for each test
this.widget = new Widget();
},
// define the optional tearDown method
// this will be run after each test
tearDown : function () {
// destroy the widget that we just used
delete this.widget;
},
'hasChildren should return true if a widget has 1 child' : function () {
// add a child
this.widget.children.push({});
// test the method
Assert(this.widget.hasChildren() === true,'hasChildren did not return true when widget had 1 child');
},
'hasChildren should return false if a widget has 0 children' : function () {
// test the method
Assert(this.widget.hasChildren() === false,'hasChildren returned true when widget had 0 children');
}
});
suite.run();
};
//testSetupAndTearDown();
var testWait = function () {
var runner = new Runner();
var suite = new Suite({
runner : runner,
'wait should not fail if resume is called' : function () {
Wait(setTimeout(function () {
Resume();
},100),110);
},
'wait should assert false after default time if nothing happens' : function () {
Wait(setTimeout(function () {
Resume();
},100),90);
},
'wait should not fail if resume is called try again' : function () {
Wait(setTimeout(function () {
Resume();
},100),110);
},
'asserting false works too' : function () {
Wait(setTimeout(function () {
Assert(false,'asserted false');
},100),110);
},
'wait should not fail if resume is called try again again' : function () {
Wait(setTimeout(function () {
Resume();
},100),110);
},
'wait should fail if resume is not called in time try again' : function () {
Wait(setTimeout(function () {
Resume();
},100),90);
},
'wait will cancel if resume is called' : function () {
Wait(setTimeout(function () {
Resume();
},10),10000000);
},
'timeouts throw a timeout error' : function () {
Wait(setTimeout(function () {
// never gets called
Resume();
},10000000),1);
}
});
suite.run();
};
//testWait();
var testHelpers = function () {
var runner = new Runner();
var suite = new Suite({
runner : runner,
thisTotesDidnt : function () {
Assert(false,'it ran, bro');
},
'this ran' : function () {
Assert(1 === 1,'yeaaa!');
}
});
suite.run();
};
//testHelpers();
var testEquals = function () {
var runner = new Runner();
var suite = new Suite({
runner : runner,
'test that equals lets tests pass' : function () {
Equals(1,1,'damn test failed');
Equals('a','a','damn test failed');
var myObj = {};
Equals(myObj,myObj,'damn test failed');
},
'test that equals fails tests' : function () {
Equals(1,2,'damn test failed');
Equals('1',1,'damn test failed');
},
'test that equals works without a message' : function () {
Equals(1,2);
}
});
suite.run();
};
testEquals();