assert.js
1.77 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var testResults = {
passed: 0,
failed: 0
};
phantom.Casper.extend({
assert: function(condition, message) {
var status = '[PASS]';
if (condition === true) {
testResults.passed++;
} else {
status = '[FAIL]';
testResults.failed++;
}
this.echo([status, message].join(' '));
},
assertEquals: function(testValue, expected, message) {
if (expected === testValue) {
this.echo('[PASS] ' + message);
testResults.passed++;
} else {
this.echo('[FAIL] ' + message);
this.echo(' got: ' + testValue);
this.echo(' expected: ' + expected);
testResults.failed++;
}
},
assertEval: function(fn, message) {
return this.assert(this.evaluate(fn), message);
},
assertEvalEquals: function(fn, expected, message) {
return this.assertEquals(this.evaluate(fn), expected, message);
},
assertMatch: function(subject, pattern, message) {
return this.assert(pattern.test(subject), message);
},
assertTitle: function(expected, message) {
return this.assertEvalEquals(function() {
return document.title;
}, expected, message);
},
assertUrlMatch: function(pattern, message) {
return this.assertMatch(this.getCurrentUrl(), pattern, message);
},
renderResults: function() {
this.echo("==========================================");
var total = testResults.passed + testResults.failed,
status = testResults.failed > 0 ? 'FAIL' : 'OK';
this.echo(status + ': ' + total + ' tests executed, ' + testResults.passed + ' passed, ' + testResults.failed + ' failed.');
this.exit();
}
});