Refactored tester module
Now all `assert*` methods returns an object containing informations about the failure, if any.
Showing
2 changed files
with
58 additions
and
4 deletions
This diff is collapsed.
Click to expand it.
... | @@ -2,6 +2,8 @@ var fs = require('fs'); | ... | @@ -2,6 +2,8 @@ var fs = require('fs'); |
2 | 2 | ||
3 | var t = casper.test; | 3 | var t = casper.test; |
4 | 4 | ||
5 | casper.start(); | ||
6 | |||
5 | t.comment('Tester.testEquals()'); | 7 | t.comment('Tester.testEquals()'); |
6 | t.assert(t.testEquals(null, null), 'Tester.testEquals() null equality'); | 8 | t.assert(t.testEquals(null, null), 'Tester.testEquals() null equality'); |
7 | t.assertNot(t.testEquals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); | 9 | t.assertNot(t.testEquals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); |
... | @@ -26,8 +28,6 @@ t.assertNot(t.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{na | ... | @@ -26,8 +28,6 @@ t.assertNot(t.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{na |
26 | t.assert(t.testEquals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality'); | 28 | t.assert(t.testEquals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality'); |
27 | t.assertNot(t.testEquals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality'); | 29 | t.assertNot(t.testEquals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality'); |
28 | 30 | ||
29 | t.assertNotEquals(42, 43, 'Tester.assertNotEquals() works as expected'); | ||
30 | |||
31 | t.comment('Tester.sortFiles()'); | 31 | t.comment('Tester.sortFiles()'); |
32 | var testDirRoot = fs.pathJoin(phantom.casperPath, 'tests', 'testdir'); | 32 | var testDirRoot = fs.pathJoin(phantom.casperPath, 'tests', 'testdir'); |
33 | var files = t.findTestFiles(testDirRoot); | 33 | var files = t.findTestFiles(testDirRoot); |
... | @@ -44,11 +44,65 @@ var expected = [ | ... | @@ -44,11 +44,65 @@ var expected = [ |
44 | }); | 44 | }); |
45 | t.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); | 45 | t.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); |
46 | 46 | ||
47 | t.comment('Tester.assertTextExists()'); | 47 | casper.thenOpen('tests/site/index.html', function() { |
48 | casper.start('tests/site/index.html', function() { | 48 | t.comment('Tester.assertTextExists()'); |
49 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); | 49 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); |
50 | }); | 50 | }); |
51 | 51 | ||
52 | casper.then(function() { | ||
53 | t.comment('Tester.assert()'); | ||
54 | t.assert(true, 'Tester.assert() works as expected'); | ||
55 | |||
56 | t.comment('Tester.assertNot()'); | ||
57 | t.assertNot(false, 'Tester.assertNot() works as expected'); | ||
58 | |||
59 | t.comment('Tester.assertEquals()'); | ||
60 | t.assertEquals(true, true, 'Tester.assertEquals() works as expected'); | ||
61 | |||
62 | t.comment('Tester.assertNotEquals()'); | ||
63 | t.assertNotEquals(true, false, 'Tester.assertNotEquals() works as expected'); | ||
64 | |||
65 | t.comment('Tester.assertEval()'); | ||
66 | t.assertEval(function() { | ||
67 | return true; | ||
68 | }, 'Tester.assertEval() works as expected'); | ||
69 | |||
70 | t.comment('Tester.assertEvalEquals()'); | ||
71 | t.assertEvalEquals(function() { | ||
72 | return 42; | ||
73 | }, 42, 'Tester.assertEvalEquals() works as expected'); | ||
74 | |||
75 | t.comment('Tester.assertExists()'); | ||
76 | t.assertExists('body', 'Tester.assertExists() works as expected'); | ||
77 | |||
78 | t.comment('Tester.assertDoesntExist()'); | ||
79 | t.assertDoesntExist('foobar', 'Tester.assertDoesntExist() works as expected'); | ||
80 | |||
81 | t.comment('Tester.assertHttpStatus()'); | ||
82 | // using file:// protocol, HTTP status is always null | ||
83 | t.assertHttpStatus(null, 'Tester.assertHttpStatus() works as expected'); | ||
84 | |||
85 | t.comment('Tester.assertMatch()'); | ||
86 | t.assertMatch("the lazy dog", /lazy/, 'Tester.assertMatch() works as expected'); | ||
87 | |||
88 | t.comment('Tester.assertRaises()'); | ||
89 | t.assertRaises(function() { | ||
90 | throw new Error('plop'); | ||
91 | }, [], 'Tester.assertRaises() works as expected'); | ||
92 | |||
93 | t.comment('Tester.assertResourceExists()'); | ||
94 | t.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected'); | ||
95 | |||
96 | t.comment('Tester.assertTitle()'); | ||
97 | t.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected'); | ||
98 | |||
99 | t.comment('Tester.assertType()'); | ||
100 | t.assertType("plop", "string", "Tester.assertType() works as expected"); | ||
101 | |||
102 | t.comment('Tester.assertUrlMatch()'); | ||
103 | t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); | ||
104 | }); | ||
105 | |||
52 | casper.run(function() { | 106 | casper.run(function() { |
53 | t.done(); | 107 | t.done(); |
54 | }); | 108 | }); | ... | ... |
-
Please register or sign in to post a comment