APITest.js
1.41 KB
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
function APITest(expected, actual, message){
it('should implement the API: ' + (message||''), function(){
APITest.testKind(expected, actual, message);
});
if (!(typeof expected == 'object' || typeof expected == 'function')) {
return;
}
for (var property in expected) {
APITest(
expected[property],
actual[property],
(message ? [message] : []).concat([property]).join('.')
);
}
if (typeof expected.prototype == 'object') for (var property in expected.prototype) {
APITest(
expected.prototype[property],
actual.prototype[property],
(message ? [message] : []).concat(['prototype',property]).join('.')
);
}
}
APITest.testKind = function(expected, actual, message){
expect(typeof actual).toBe(typeof expected);
if (typeof expected == 'boolean') expect(actual).toBe(expected);
if (expected instanceof Array) expect(actual instanceof Array).toBe(true);
if (expected instanceof String) expect(actual instanceof String).toBe(true);
if (expected instanceof Number) expect(actual instanceof Number).toBe(true);
if (expected instanceof Date) expect(actual instanceof Date).toBe(true);
if (expected instanceof RegExp) expect(actual instanceof RegExp).toBe(true);
if (expected instanceof Function) expect(actual instanceof Function).toBe(true);
};