removed obsolete isolation tricks from test suite
Showing
28 changed files
with
397 additions
and
441 deletions
1 | (function(t) { | 1 | var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png'; |
2 | var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png'; | ||
3 | 2 | ||
4 | if (fs.exists(testFile) && fs.isFile(testFile)) { | 3 | if (fs.exists(testFile) && fs.isFile(testFile)) { |
5 | fs.remove(testFile); | 4 | fs.remove(testFile); |
6 | } | 5 | } |
7 | 6 | ||
8 | casper.start('tests/site/index.html', function(self) { | 7 | casper.start('tests/site/index.html', function(self) { |
9 | self.viewport(300, 200); | 8 | self.viewport(300, 200); |
10 | t.comment('Casper.capture()'); | 9 | this.test.comment('Casper.capture()'); |
11 | self.capture(testFile); | 10 | self.capture(testFile); |
12 | t.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); | 11 | this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); |
13 | }); | 12 | }); |
14 | 13 | ||
15 | try { | 14 | try { |
16 | fs.remove(testFile); | 15 | fs.remove(testFile); |
17 | } catch(e) {} | 16 | } catch(e) {} |
18 | 17 | ||
19 | casper.run(function(self) { | 18 | casper.run(function(self) { |
20 | t.done(); | 19 | this.test.done(); |
21 | }); | 20 | }); |
22 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/index.html', function() { |
2 | casper.start('tests/site/index.html', function() { | ||
3 | this.click('a[href="test.html"]'); | 2 | this.click('a[href="test.html"]'); |
4 | }); | 3 | }); |
5 | 4 | ||
6 | casper.then(function() { | 5 | casper.then(function() { |
7 | t.comment('Casper.click()'); | 6 | this.test.comment('Casper.click()'); |
8 | t.assertTitle('CasperJS test target', 'Casper.click() can click on a link'); | 7 | this.test.assertTitle('CasperJS test target', 'Casper.click() can click on a link'); |
9 | }).thenClick('a', function() { | 8 | }).thenClick('a', function() { |
10 | t.comment('Casper.thenClick()'); | 9 | this.test.comment('Casper.thenClick()'); |
11 | t.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link'); | 10 | this.test.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link'); |
12 | }); | 11 | }); |
13 | 12 | ||
14 | // onclick variants tests | 13 | // onclick variants tests |
15 | casper.thenOpen('tests/site/click.html', function() { | 14 | casper.thenOpen('tests/site/click.html', function() { |
16 | t.comment('CasperUtils.click()'); | 15 | this.test.comment('CasperUtils.click()'); |
17 | this.test.assert(this.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link'); | 16 | this.test.assert(this.click('#test1'), 'CasperUtils.click() can click an `href="javascript:` link'); |
18 | this.test.assert(this.click('#test2'), 'CasperUtils.click() can click an `href="#"` link'); | 17 | this.test.assert(this.click('#test2'), 'CasperUtils.click() can click an `href="#"` link'); |
19 | this.test.assert(this.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link'); | 18 | this.test.assert(this.click('#test3'), 'CasperUtils.click() can click an `onclick=".*; return false"` link'); |
... | @@ -23,27 +22,26 @@ | ... | @@ -23,27 +22,26 @@ |
23 | this.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link'); | 22 | this.test.assert(results.test2, 'CasperUtils.click() has clicked an `href="#"` link'); |
24 | this.test.assert(results.test3, 'CasperUtils.click() has clicked an `onclick=".*; return false"` link'); | 23 | this.test.assert(results.test3, 'CasperUtils.click() has clicked an `onclick=".*; return false"` link'); |
25 | this.test.assert(results.test4, 'CasperUtils.click() has clicked an unobstrusive js handled link'); | 24 | this.test.assert(results.test4, 'CasperUtils.click() has clicked an unobstrusive js handled link'); |
26 | }); | 25 | }); |
27 | 26 | ||
28 | // casper.mouse | 27 | // casper.mouse |
29 | casper.then(function() { | 28 | casper.then(function() { |
30 | t.comment('Mouse.down()'); | 29 | this.test.comment('Mouse.down()'); |
31 | this.mouse.down(200, 100); | 30 | this.mouse.down(200, 100); |
32 | var results = this.getGlobal('results'); | 31 | var results = this.getGlobal('results'); |
33 | this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position'); | 32 | this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position'); |
34 | 33 | ||
35 | t.comment('Mouse.up()'); | 34 | this.test.comment('Mouse.up()'); |
36 | this.mouse.up(200, 100); | 35 | this.mouse.up(200, 100); |
37 | results = this.getGlobal('results'); | 36 | results = this.getGlobal('results'); |
38 | this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position'); | 37 | this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position'); |
39 | 38 | ||
40 | t.comment('Mouse.move()'); | 39 | this.test.comment('Mouse.move()'); |
41 | this.mouse.move(200, 100); | 40 | this.mouse.move(200, 100); |
42 | results = this.getGlobal('results'); | 41 | results = this.getGlobal('results'); |
43 | this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position'); | 42 | this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position'); |
44 | }); | 43 | }); |
45 | 44 | ||
46 | casper.run(function() { | ||
47 | t.done(); | ||
48 | }); | ||
49 | })(casper.test); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
45 | casper.run(function() { | ||
46 | this.test.done(); | ||
47 | }); | ... | ... |
1 | (function(t) { | 1 | var fs = require('fs'); |
2 | t.comment('ClientUtils.encode()'); | 2 | var clientutils = require('clientutils').create(); |
3 | 3 | var testCases = { | |
4 | var fs = require('fs'); | ||
5 | var clientutils = require('clientutils').create(); | ||
6 | var testCases = { | ||
7 | 'an empty string': '', | 4 | 'an empty string': '', |
8 | 'a word': 'plop', | 5 | 'a word': 'plop', |
9 | 'a null char': 'a\u0000', | 6 | 'a null char': 'a\u0000', |
... | @@ -13,13 +10,14 @@ | ... | @@ -13,13 +10,14 @@ |
13 | "Et dans ma tête qui bourdonnent?\n" + | 10 | "Et dans ma tête qui bourdonnent?\n" + |
14 | "Les abeilles!"), | 11 | "Les abeilles!"), |
15 | 'a file contents': fs.read(phantom.casperPath + '/tests/site/alert.html') | 12 | 'a file contents': fs.read(phantom.casperPath + '/tests/site/alert.html') |
16 | }; | 13 | }; |
14 | |||
15 | casper.test.comment('ClientUtils.encode()'); | ||
17 | 16 | ||
18 | for (var what in testCases) { | 17 | for (var what in testCases) { |
19 | var source = testCases[what]; | 18 | var source = testCases[what]; |
20 | var encoded = clientutils.encode(source); | 19 | var encoded = clientutils.encode(source); |
21 | t.assertEquals(clientutils.decode(encoded), source, 'ClientUtils can encode and decode ' + what); | 20 | casper.test.assertEquals(clientutils.decode(encoded), source, 'ClientUtils can encode and decode ' + what); |
22 | } | 21 | } |
23 | 22 | ||
24 | t.done(); | 23 | casper.test.done(); |
25 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | var fs = require('fs'); |
2 | casper.start('tests/site/index.html', function(self) { | 2 | |
3 | casper.start('tests/site/index.html', function() { | ||
3 | var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png'; | 4 | var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png'; |
4 | var image = self.base64encode(imageUrl); | 5 | var image = this.base64encode(imageUrl); |
5 | var fs = require('fs'); | ||
6 | 6 | ||
7 | t.comment('Casper.base64encode()'); | 7 | this.test.comment('Casper.base64encode()'); |
8 | t.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents'); | 8 | this.test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents'); |
9 | 9 | ||
10 | t.comment('Casper.download()'); | 10 | this.test.comment('Casper.download()'); |
11 | self.download(imageUrl, 'logo.png'); | 11 | this.download(imageUrl, 'logo.png'); |
12 | t.assert(fs.exists('logo.png'), 'Casper.download() downloads a file'); | 12 | this.test.assert(fs.exists('logo.png'), 'Casper.download() downloads a file'); |
13 | if (fs.exists('logo.png')) { | 13 | if (fs.exists('logo.png')) { |
14 | fs.remove('logo.png'); | 14 | fs.remove('logo.png'); |
15 | } | 15 | } |
16 | }); | 16 | }); |
17 | 17 | ||
18 | casper.run(function(self) { | 18 | casper.run(function() { |
19 | t.done(); | 19 | this.test.done(); |
20 | }); | 20 | }); |
21 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.evaluate()'); |
2 | t.comment('Casper.evaluate()'); | ||
3 | 2 | ||
4 | casper.start(); | 3 | casper.start(); |
5 | 4 | ||
6 | var params = { | 5 | var params = { |
7 | "boolean true": true, | 6 | "boolean true": true, |
8 | "boolean false": false, | 7 | "boolean false": false, |
9 | "int number": 42, | 8 | "int number": 42, |
... | @@ -11,19 +10,18 @@ | ... | @@ -11,19 +10,18 @@ |
11 | "string": "plop! \"Ÿ£$\" 'no'", | 10 | "string": "plop! \"Ÿ£$\" 'no'", |
12 | "array": [1, 2, 3], | 11 | "array": [1, 2, 3], |
13 | "object": {a: 1, b: 2} | 12 | "object": {a: 1, b: 2} |
14 | }; | 13 | }; |
15 | 14 | ||
16 | var casperParams = casper.evaluate(function() { | 15 | var casperParams = casper.evaluate(function() { |
17 | return __casper_params__; | 16 | return __casper_params__; |
18 | }, params); | 17 | }, params); |
19 | 18 | ||
20 | casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object'); | 19 | casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object'); |
21 | casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length'); | 20 | casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length'); |
22 | 21 | ||
23 | for (var param in casperParams) { | 22 | for (var param in casperParams) { |
24 | casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param); | 23 | casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param); |
25 | casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type'); | 24 | casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type'); |
26 | } | 25 | } |
27 | 26 | ||
28 | t.done(); | 27 | casper.test.done(); |
29 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.exists()'); |
2 | t.comment('Casper.exists()'); | ||
3 | 2 | ||
4 | casper.start('tests/site/index.html', function(self) { | 3 | casper.start('tests/site/index.html', function() { |
5 | t.assert(self.exists('a') && !self.exists('chucknorriz'), 'Casper.exists() can check if an element exists'); | 4 | this.test.assert(this.exists('a') && !this.exists('chucknorriz'), 'Casper.exists() can check if an element exists'); |
6 | }); | 5 | }); |
7 | 6 | ||
8 | casper.run(function(step) { | 7 | casper.run(function() { |
9 | t.done(); | 8 | this.test.done(); |
10 | }); | 9 | }); |
11 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.fetchText()'); |
2 | t.comment('Casper.fetchText()'); | ||
3 | 2 | ||
4 | casper.start('tests/site/index.html', function(self) { | 3 | casper.start('tests/site/index.html', function() { |
5 | t.assertEquals(self.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents'); | 4 | this.test.assertEquals(this.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents'); |
6 | }); | 5 | }); |
7 | 6 | ||
8 | casper.run(function() { | 7 | casper.run(function() { |
9 | t.done(); | 8 | this.test.done(); |
10 | }); | 9 | }); |
11 | })(casper.test); | ... | ... |
1 | do(casper) -> | 1 | step = 0 |
2 | step = 0 | ||
3 | 2 | ||
4 | # testing resources | 3 | # testing resources |
5 | casper.start "tests/site/resources.html", -> | 4 | casper.start "tests/site/resources.html", -> |
6 | @test.assertEquals ++step, 1, "step 1" | 5 | @test.assertEquals ++step, 1, "step 1" |
7 | @wait 400, -> | 6 | @wait 400, -> |
8 | @test.assertEquals ++step, 2, "step 1.1" | 7 | @test.assertEquals ++step, 2, "step 1.1" |
... | @@ -15,16 +14,16 @@ do(casper) -> | ... | @@ -15,16 +14,16 @@ do(casper) -> |
15 | @wait 400, -> | 14 | @wait 400, -> |
16 | @test.assertEquals ++step, 6, "step 1.2" | 15 | @test.assertEquals ++step, 6, "step 1.2" |
17 | 16 | ||
18 | casper.wait 200, -> | 17 | casper.wait 200, -> |
19 | @test.assertEquals ++step, 7, "step 2" | 18 | @test.assertEquals ++step, 7, "step 2" |
20 | 19 | ||
21 | casper.waitForSelector( | 20 | casper.waitForSelector( |
22 | '#noneExistingSelector' | 21 | '#noneExistingSelector' |
23 | -> @test.fail "should run into timeout" | 22 | -> @test.fail "should run into timeout" |
24 | -> @test.assertEquals ++step, 8, "step 3 sucessfully timed out" | 23 | -> @test.assertEquals ++step, 8, "step 3 sucessfully timed out" |
25 | 1000 | 24 | 1000 |
26 | ) | 25 | ) |
27 | casper.then -> | 26 | casper.then -> |
28 | @test.assertEquals ++step, 9, "step 4" | 27 | @test.assertEquals ++step, 9, "step 4" |
29 | @wait 300, -> | 28 | @wait 300, -> |
30 | @test.assertEquals ++step, 10, "step 4.1" | 29 | @test.assertEquals ++step, 10, "step 4.1" |
... | @@ -33,7 +32,7 @@ do(casper) -> | ... | @@ -33,7 +32,7 @@ do(casper) -> |
33 | @wait 100, -> | 32 | @wait 100, -> |
34 | @test.assertEquals ++step, 12, "step 5.2" | 33 | @test.assertEquals ++step, 12, "step 5.2" |
35 | 34 | ||
36 | casper.then -> | 35 | casper.then -> |
37 | @test.assertEquals ++step, 13, "last step" | 36 | @test.assertEquals ++step, 13, "last step" |
38 | 37 | ||
39 | casper.run(-> @test.done()) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
38 | casper.run(-> @test.done()) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/form.html', function() { |
2 | casper.start('tests/site/form.html', function(self) { | 2 | this.test.comment('Casper.fill()'); |
3 | t.comment('Casper.fill()'); | 3 | this.fill('form[action="result.html"]', { |
4 | self.fill('form[action="result.html"]', { | ||
5 | email: 'chuck@norris.com', | 4 | email: 'chuck@norris.com', |
6 | content: 'Am watching thou', | 5 | content: 'Am watching thou', |
7 | check: true, | 6 | check: true, |
... | @@ -10,45 +9,44 @@ | ... | @@ -10,45 +9,44 @@ |
10 | file: phantom.libraryPath + '/README.md', | 9 | file: phantom.libraryPath + '/README.md', |
11 | 'checklist[]': ['1', '3'] | 10 | 'checklist[]': ['1', '3'] |
12 | }); | 11 | }); |
13 | t.assertEvalEquals(function() { | 12 | this.test.assertEvalEquals(function() { |
14 | return document.querySelector('input[name="email"]').value; | 13 | return document.querySelector('input[name="email"]').value; |
15 | }, 'chuck@norris.com', 'Casper.fill() can fill an input[type=text] form field'); | 14 | }, 'chuck@norris.com', 'Casper.fill() can fill an input[type=text] form field'); |
16 | t.assertEvalEquals(function() { | 15 | this.test.assertEvalEquals(function() { |
17 | return document.querySelector('textarea[name="content"]').value; | 16 | return document.querySelector('textarea[name="content"]').value; |
18 | }, 'Am watching thou', 'Casper.fill() can fill a textarea form field'); | 17 | }, 'Am watching thou', 'Casper.fill() can fill a textarea form field'); |
19 | t.assertEvalEquals(function() { | 18 | this.test.assertEvalEquals(function() { |
20 | return document.querySelector('select[name="topic"]').value; | 19 | return document.querySelector('select[name="topic"]').value; |
21 | }, 'bar', 'Casper.fill() can pick a value from a select form field'); | 20 | }, 'bar', 'Casper.fill() can pick a value from a select form field'); |
22 | t.assertEvalEquals(function() { | 21 | this.test.assertEvalEquals(function() { |
23 | return document.querySelector('input[name="check"]').checked; | 22 | return document.querySelector('input[name="check"]').checked; |
24 | }, true, 'Casper.fill() can check a form checkbox'); | 23 | }, true, 'Casper.fill() can check a form checkbox'); |
25 | t.assertEvalEquals(function() { | 24 | this.test.assertEvalEquals(function() { |
26 | return document.querySelector('input[name="choice"][value="no"]').checked; | 25 | return document.querySelector('input[name="choice"][value="no"]').checked; |
27 | }, true, 'Casper.fill() can check a form radio button 1/2'); | 26 | }, true, 'Casper.fill() can check a form radio button 1/2'); |
28 | t.assertEvalEquals(function() { | 27 | this.test.assertEvalEquals(function() { |
29 | return document.querySelector('input[name="choice"][value="yes"]').checked; | 28 | return document.querySelector('input[name="choice"][value="yes"]').checked; |
30 | }, false, 'Casper.fill() can check a form radio button 2/2'); | 29 | }, false, 'Casper.fill() can check a form radio button 2/2'); |
31 | t.assertEvalEquals(function() { | 30 | this.test.assertEvalEquals(function() { |
32 | return document.querySelector('input[name="file"]').files.length === 1; | 31 | return document.querySelector('input[name="file"]').files.length === 1; |
33 | }, true, 'Casper.fill() can select a file to upload'); | 32 | }, true, 'Casper.fill() can select a file to upload'); |
34 | t.assertEvalEquals(function() { | 33 | this.test.assertEvalEquals(function() { |
35 | return (document.querySelector('input[name="checklist[]"][value="1"]').checked && | 34 | return (document.querySelector('input[name="checklist[]"][value="1"]').checked && |
36 | !document.querySelector('input[name="checklist[]"][value="2"]').checked && | 35 | !document.querySelector('input[name="checklist[]"][value="2"]').checked && |
37 | document.querySelector('input[name="checklist[]"][value="3"]').checked); | 36 | document.querySelector('input[name="checklist[]"][value="3"]').checked); |
38 | }, true, 'Casper.fill() can fill a list of checkboxes'); | 37 | }, true, 'Casper.fill() can fill a list of checkboxes'); |
39 | self.click('input[type="submit"]'); | 38 | this.click('input[type="submit"]'); |
40 | }); | 39 | }); |
41 | 40 | ||
42 | casper.then(function(self) { | 41 | casper.then(function() { |
43 | t.comment('Form submitted'); | 42 | this.test.comment('Form submitted'); |
44 | t.assertUrlMatch(/email=chuck@norris.com/, 'Casper.fill() input[type=email] field was submitted'); | 43 | this.test.assertUrlMatch(/email=chuck@norris.com/, 'Casper.fill() input[type=email] field was submitted'); |
45 | t.assertUrlMatch(/content=Am\+watching\+thou/, 'Casper.fill() textarea field was submitted'); | 44 | this.test.assertUrlMatch(/content=Am\+watching\+thou/, 'Casper.fill() textarea field was submitted'); |
46 | t.assertUrlMatch(/check=on/, 'Casper.fill() input[type=checkbox] field was submitted'); | 45 | this.test.assertUrlMatch(/check=on/, 'Casper.fill() input[type=checkbox] field was submitted'); |
47 | t.assertUrlMatch(/choice=no/, 'Casper.fill() input[type=radio] field was submitted'); | 46 | this.test.assertUrlMatch(/choice=no/, 'Casper.fill() input[type=radio] field was submitted'); |
48 | t.assertUrlMatch(/topic=bar/, 'Casper.fill() select field was submitted'); | 47 | this.test.assertUrlMatch(/topic=bar/, 'Casper.fill() select field was submitted'); |
49 | }); | 48 | }); |
50 | 49 | ||
51 | casper.run(function(self) { | 50 | casper.run(function() { |
52 | t.done(); | 51 | this.test.done(); |
53 | }); | 52 | }); |
54 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/global.html', function() { |
2 | casper.start('tests/site/global.html', function(self) { | 2 | this.test.comment('Casper.getGlobal()'); |
3 | t.comment('Casper.getGlobal()'); | 3 | this.test.assertEquals(this.getGlobal('myGlobal'), 'awesome string', 'Casper.getGlobal() can retrieve a remote global variable'); |
4 | t.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'Casper.getGlobal() can retrieve a remote global variable'); | 4 | this.test.assertRaises(this.getGlobal, ['myUnencodableGlobal'], 'Casper.getGlobal() does not fail trying to encode an unencodable global'); |
5 | t.assertRaises(self.getGlobal, ['myUnencodableGlobal'], 'Casper.getGlobal() does not fail trying to encode an unencodable global'); | 5 | }); |
6 | }); | ||
7 | 6 | ||
8 | casper.run(function(self) { | 7 | casper.run(function() { |
9 | t.done(); | 8 | this.test.done(); |
10 | }); | 9 | }); |
11 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/page1.html'); |
2 | casper.start('tests/site/page1.html'); | 2 | casper.thenOpen('tests/site/page2.html'); |
3 | casper.thenOpen('tests/site/page2.html'); | 3 | casper.thenOpen('tests/site/page3.html'); |
4 | casper.thenOpen('tests/site/page3.html'); | ||
5 | 4 | ||
6 | casper.back(); | 5 | casper.back(); |
7 | casper.then(function(self) { | 6 | casper.then(function() { |
8 | t.comment('navigating history backward'); | 7 | this.test.comment('navigating history backward'); |
9 | t.assertMatch(self.getCurrentUrl(), /tests\/site\/page2\.html$/, 'Casper.back() can go back an history step'); | 8 | this.test.assertMatch(this.getCurrentUrl(), /tests\/site\/page2\.html$/, 'Casper.back() can go back an history step'); |
10 | }); | 9 | }); |
11 | 10 | ||
12 | casper.forward(); | 11 | casper.forward(); |
13 | casper.then(function(self) { | 12 | casper.then(function() { |
14 | t.comment('navigating history forward'); | 13 | this.test.comment('navigating history forward'); |
15 | t.assertMatch(self.getCurrentUrl(), /tests\/site\/page3\.html$/, 'Casper.forward() can go forward an history step'); | 14 | this.test.assertMatch(this.getCurrentUrl(), /tests\/site\/page3\.html$/, 'Casper.forward() can go forward an history step'); |
16 | }); | 15 | }); |
17 | 16 | ||
18 | casper.run(function(self) { | 17 | casper.run(function() { |
19 | t.assert(self.history.length > 0, 'Casper.history contains urls'); | 18 | this.test.assert(this.history.length > 0, 'Casper.history contains urls'); |
20 | t.assertMatch(self.history[0], /tests\/site\/page1\.html$/, 'Casper.history has the correct first url'); | 19 | this.test.assertMatch(this.history[0], /tests\/site\/page1\.html$/, 'Casper.history has the correct first url'); |
21 | t.done(); | 20 | this.test.done(); |
22 | }); | 21 | }); |
23 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | // Dear curious test reader, |
2 | // Casper.options.onStepComplete | 2 | // The on* family of methods is considered deprecated since 0.6.0; please use events instead |
3 | casper.start('tests/site/index.html', function(self) { | 3 | |
4 | self.options.onStepComplete = function(self, stepResult) { | 4 | // Casper.options.onStepComplete |
5 | t.comment('Casper.options.onStepComplete()'); | 5 | casper.start('tests/site/index.html', function() { |
6 | t.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); | 6 | this.options.onStepComplete = function(self, stepResult) { |
7 | this.test.comment('Casper.options.onStepComplete()'); | ||
8 | this.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); | ||
7 | self.options.onStepComplete = null; | 9 | self.options.onStepComplete = null; |
8 | }; | 10 | }; |
9 | return 'ok'; | 11 | return 'ok'; |
10 | }); | 12 | }); |
11 | 13 | ||
12 | // Casper.options.onResourceRequested & Casper.options.onResourceReceived | 14 | // Casper.options.onResourceRequested & Casper.options.onResourceReceived |
13 | casper.then(function(self) { | 15 | casper.then(function() { |
14 | self.options.onResourceReceived = function(self, resource) { | 16 | this.options.onResourceReceived = function(self, resource) { |
15 | t.comment('Casper.options.onResourceReceived()'); | 17 | this.test.comment('Casper.options.onResourceReceived()'); |
16 | t.assertType(resource, 'object', 'Casper.options.onResourceReceived() retrieve a resource object'); | 18 | this.test.assertType(resource, 'object', 'Casper.options.onResourceReceived() retrieve a resource object'); |
17 | t.assert('status' in resource, 'Casper.options.onResourceReceived() retrieve a valid resource object'); | 19 | this.test.assert('status' in resource, 'Casper.options.onResourceReceived() retrieve a valid resource object'); |
18 | self.options.onResourceReceived = null; | 20 | self.options.onResourceReceived = null; |
19 | }; | 21 | }; |
20 | self.options.onResourceRequested = function(self, request) { | 22 | this.options.onResourceRequested = function(self, request) { |
21 | t.comment('Casper.options.onResourceRequested()'); | 23 | this.test.comment('Casper.options.onResourceRequested()'); |
22 | t.assertType(request, 'object', 'Casper.options.onResourceRequested() retrieve a request object'); | 24 | this.test.assertType(request, 'object', 'Casper.options.onResourceRequested() retrieve a request object'); |
23 | t.assert('method' in request, 'Casper.options.onResourceRequested() retrieve a valid request object'); | 25 | this.test.assert('method' in request, 'Casper.options.onResourceRequested() retrieve a valid request object'); |
24 | self.options.onResourceRequested = null; | 26 | self.options.onResourceRequested = null; |
25 | }; | 27 | }; |
26 | self.thenOpen('tests/site/page1.html'); | 28 | this.thenOpen('tests/site/page1.html'); |
27 | }); | 29 | }); |
28 | 30 | ||
29 | // Casper.options.onAlert() | 31 | // Casper.options.onAlert() |
30 | casper.then(function(self) { | 32 | casper.then(function() { |
31 | self.options.onAlert = function(self, message) { | 33 | this.options.onAlert = function(self, message) { |
32 | t.assertEquals(message, 'plop', 'Casper.options.onAlert() can intercept an alert message'); | 34 | self.test.assertEquals(message, 'plop', 'Casper.options.onAlert() can intercept an alert message'); |
33 | }; | 35 | }; |
34 | }).thenOpen('tests/site/alert.html').thenClick('button', function(self) { | 36 | }).thenOpen('tests/site/alert.html').thenClick('button', function() { |
35 | self.options.onAlert = null; | 37 | this.options.onAlert = null; |
36 | }); | 38 | }); |
37 | 39 | ||
38 | casper.run(function(self) { | 40 | casper.run(function() { |
39 | t.done(); | 41 | this.test.done(); |
40 | }); | 42 | }); |
41 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/index.html'); |
2 | casper.start('tests/site/index.html'); | ||
3 | 2 | ||
4 | var oldLevel = casper.options.logLevel; | 3 | var oldLevel = casper.options.logLevel; |
5 | 4 | ||
6 | casper.options.logLevel = 'info'; | 5 | casper.options.logLevel = 'info'; |
7 | casper.options.verbose = false; | 6 | casper.options.verbose = false; |
8 | 7 | ||
9 | t.comment('Casper.log()'); | 8 | casper.test.comment('Casper.log()'); |
10 | casper.log('foo', 'info'); | 9 | casper.log('foo', 'info'); |
11 | t.assert(casper.result.log.some(function(e) { | 10 | casper.test.assert(casper.result.log.some(function(e) { |
12 | return e.message === 'foo' && e.level === 'info'; | 11 | return e.message === 'foo' && e.level === 'info'; |
13 | }), 'Casper.log() adds a log entry'); | 12 | }), 'Casper.log() adds a log entry'); |
14 | 13 | ||
15 | casper.options.logLevel = oldLevel; | 14 | casper.options.logLevel = oldLevel; |
16 | casper.options.verbose = true; | 15 | casper.options.verbose = true; |
17 | 16 | ||
18 | casper.then(function(self) { | 17 | casper.then(function() { |
19 | var oldLevel = casper.options.logLevel; | 18 | var oldLevel = casper.options.logLevel; |
20 | casper.options.logLevel = 'debug'; | 19 | casper.options.logLevel = 'debug'; |
21 | casper.options.verbose = false; | 20 | casper.options.verbose = false; |
... | @@ -23,18 +22,17 @@ | ... | @@ -23,18 +22,17 @@ |
23 | __utils__.log('debug message'); | 22 | __utils__.log('debug message'); |
24 | __utils__.log('info message', 'info'); | 23 | __utils__.log('info message', 'info'); |
25 | }); | 24 | }); |
26 | t.assert(casper.result.log.some(function(e) { | 25 | this.test.assert(casper.result.log.some(function(e) { |
27 | return e.message === 'debug message' && e.level === 'debug' && e.space === 'remote'; | 26 | return e.message === 'debug message' && e.level === 'debug' && e.space === 'remote'; |
28 | }), 'ClientUtils.log() adds a log entry'); | 27 | }), 'ClientUtils.log() adds a log entry'); |
29 | t.assert(casper.result.log.some(function(e) { | 28 | this.test.assert(casper.result.log.some(function(e) { |
30 | return e.message === 'info message' && e.level === 'info' && e.space === 'remote'; | 29 | return e.message === 'info message' && e.level === 'info' && e.space === 'remote'; |
31 | }), 'ClientUtils.log() adds a log entry at a given level'); | 30 | }), 'ClientUtils.log() adds a log entry at a given level'); |
32 | casper.options.logLevel = oldLevel; | 31 | casper.options.logLevel = oldLevel; |
33 | casper.options.verbose = true; | 32 | casper.options.verbose = true; |
34 | }); | 33 | }); |
35 | 34 | ||
36 | casper.run(function(self) { | 35 | casper.run(function() { |
37 | t.assertEquals(self.result.log.length, 3, 'Casper.log() logged messages'); | 36 | this.test.assertEquals(this.result.log.length, 3, 'Casper.log() logged messages'); |
38 | t.done(); | 37 | this.test.done(); |
39 | }); | 38 | }); |
40 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | var t = casper.test, current = 0, tests = [ |
2 | var current = 0, tests = [ | ||
3 | function(settings) { | 2 | function(settings) { |
4 | t.assertEquals(settings, { | 3 | t.assertEquals(settings, { |
5 | method: "get" | 4 | method: "get" |
... | @@ -24,52 +23,51 @@ | ... | @@ -24,52 +23,51 @@ |
24 | password: 'sinclar' | 23 | password: 'sinclar' |
25 | }, "Casper.open() used the expected HTTP auth settings"); | 24 | }, "Casper.open() used the expected HTTP auth settings"); |
26 | } | 25 | } |
27 | ]; | 26 | ]; |
28 | 27 | ||
29 | casper.start(); | 28 | casper.start(); |
30 | 29 | ||
31 | casper.on('open', function(url, settings) { | 30 | casper.on('open', function(url, settings) { |
32 | tests[current++](settings); | 31 | tests[current++](settings); |
33 | }); | 32 | }); |
34 | 33 | ||
35 | // GET | 34 | // GET |
36 | casper.open('tests/site/index.html').then(function() { | 35 | casper.open('tests/site/index.html').then(function() { |
37 | t.pass("Casper.open() can open and load a location using GET"); | 36 | t.pass("Casper.open() can open and load a location using GET"); |
38 | }); | 37 | }); |
39 | 38 | ||
40 | // POST | 39 | // POST |
41 | casper.open('tests/site/index.html', { | 40 | casper.open('tests/site/index.html', { |
42 | method: 'post', | 41 | method: 'post', |
43 | data: { | 42 | data: { |
44 | plop: 42, | 43 | plop: 42, |
45 | chuck: 'norris' | 44 | chuck: 'norris' |
46 | } | 45 | } |
47 | }).then(function() { | 46 | }).then(function() { |
48 | t.pass("Casper.open() can open and load a location using POST"); | 47 | t.pass("Casper.open() can open and load a location using POST"); |
49 | }); | 48 | }); |
50 | 49 | ||
51 | // PUT | 50 | // PUT |
52 | casper.open('tests/site/index.html', { | 51 | casper.open('tests/site/index.html', { |
53 | method: 'put', | 52 | method: 'put', |
54 | data: { | 53 | data: { |
55 | plop: 42, | 54 | plop: 42, |
56 | chuck: 'norris' | 55 | chuck: 'norris' |
57 | } | 56 | } |
58 | }).then(function() { | 57 | }).then(function() { |
59 | t.pass("Casper.open() can open and load a location using PUT"); | 58 | t.pass("Casper.open() can open and load a location using PUT"); |
60 | }); | 59 | }); |
61 | 60 | ||
62 | // HTTP Auth | 61 | // HTTP Auth |
63 | casper.open('tests/site/index.html', { | 62 | casper.open('tests/site/index.html', { |
64 | method: 'get', | 63 | method: 'get', |
65 | username: 'bob', | 64 | username: 'bob', |
66 | password: 'sinclar' | 65 | password: 'sinclar' |
67 | }).then(function() { | 66 | }).then(function() { |
68 | t.pass("Casper.open() can open and load a location using HTTP auth"); | 67 | t.pass("Casper.open() can open and load a location using HTTP auth"); |
69 | }); | 68 | }); |
70 | 69 | ||
71 | casper.run(function() { | 70 | casper.run(function() { |
72 | this.removeAllListeners('open'); | 71 | this.removeAllListeners('open'); |
73 | t.done(); | 72 | t.done(); |
74 | }); | 73 | }); |
75 | })(casper.test); | ... | ... |
1 | do(casper) -> | 1 | casper.start "tests/site/resources.html", -> |
2 | casper.start "tests/site/resources.html", -> | ||
3 | @test.assertEquals @resources.length, 1, "only one resource found" | 2 | @test.assertEquals @resources.length, 1, "only one resource found" |
4 | onTime = -> | 3 | onTime = -> |
5 | @test.assertEquals( | 4 | @test.assertEquals( |
... | @@ -22,4 +21,4 @@ do(casper) -> | ... | @@ -22,4 +21,4 @@ do(casper) -> |
22 | onTimeout = -> @test.fail "waitForResource timeout occured" | 21 | onTimeout = -> @test.fail "waitForResource timeout occured" |
23 | @waitForResource "phantom.png", onTime, onTimeout | 22 | @waitForResource "phantom.png", onTime, onTimeout |
24 | 23 | ||
25 | casper.run(-> @test.done()) | 24 | casper.run(-> @test.done()) | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.start()'); |
2 | t.comment('Casper.start()'); | ||
3 | 2 | ||
4 | casper.start('tests/site/index.html', function(self) { | 3 | casper.start('tests/site/index.html', function() { |
5 | t.pass('Casper.start() can chain a next step'); | 4 | this.test.pass('Casper.start() can chain a next step'); |
6 | t.assertTitle('CasperJS test index', 'Casper.start() opened the passed url'); | 5 | this.test.assertTitle('CasperJS test index', 'Casper.start() opened the passed url'); |
7 | t.assertEval(function() { | 6 | this.test.assertEval(function() { |
8 | return typeof(__utils__) === "object"; | 7 | return typeof(__utils__) === "object"; |
9 | }, 'Casper.start() injects ClientUtils instance within remote DOM'); | 8 | }, 'Casper.start() injects ClientUtils instance within remote DOM'); |
10 | }); | 9 | }); |
11 | 10 | ||
12 | t.assert(casper.started, 'Casper.start() started'); | 11 | casper.test.assert(casper.started, 'Casper.start() started'); |
13 | 12 | ||
14 | casper.run(function(self) { | 13 | casper.run(function() { |
15 | t.done(); | 14 | this.test.done(); |
16 | }); | 15 | }); |
17 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.then()'); |
2 | t.comment('Casper.then()'); | ||
3 | 2 | ||
4 | casper.start('tests/site/index.html'); | 3 | casper.start('tests/site/index.html'); |
5 | 4 | ||
6 | var nsteps = casper.steps.length; | 5 | var nsteps = casper.steps.length; |
7 | 6 | ||
8 | casper.then(function(self) { | 7 | casper.then(function(self) { |
9 | t.assertTitle('CasperJS test index', 'Casper.then() added a new step'); | 8 | this.test.assertTitle('CasperJS test index', 'Casper.then() added a new step'); |
10 | }); | 9 | }); |
11 | 10 | ||
12 | t.assertEquals(casper.steps.length, nsteps + 1, 'Casper.then() can add a new step'); | 11 | casper.test.assertEquals(casper.steps.length, nsteps + 1, 'Casper.then() can add a new step'); |
13 | 12 | ||
14 | t.comment('Casper.thenOpen()'); | 13 | casper.test.comment('Casper.thenOpen()'); |
15 | 14 | ||
16 | casper.thenOpen('tests/site/test.html'); | 15 | casper.thenOpen('tests/site/test.html'); |
17 | 16 | ||
18 | t.assertEquals(casper.steps.length, nsteps + 2, 'Casper.thenOpen() can add a new step'); | 17 | casper.test.assertEquals(casper.steps.length, nsteps + 2, 'Casper.thenOpen() can add a new step'); |
19 | 18 | ||
20 | casper.thenOpen('tests/site/test.html', function(self) { | 19 | casper.thenOpen('tests/site/test.html', function() { |
21 | t.assertTitle('CasperJS test target', 'Casper.thenOpen() opened a location and executed a step'); | 20 | this.test.assertTitle('CasperJS test target', 'Casper.thenOpen() opened a location and executed a step'); |
22 | }); | 21 | }); |
23 | 22 | ||
24 | t.assertEquals(casper.steps.length, nsteps + 4, 'Casper.thenOpen() can add a new step for opening, plus another step'); | 23 | casper.test.assertEquals(casper.steps.length, nsteps + 4, 'Casper.thenOpen() can add a new step for opening, plus another step'); |
25 | 24 | ||
26 | t.comment('Casper.each()'); | 25 | casper.test.comment('Casper.each()'); |
27 | casper.each([1, 2, 3], function(self, item, i) { | 26 | casper.each([1, 2, 3], function(self, item, i) { |
28 | self.test.assertEquals(i, item - 1, 'Casper.each() passes a contextualized index'); | 27 | self.test.assertEquals(i, item - 1, 'Casper.each() passes a contextualized index'); |
29 | }); | 28 | }); |
30 | 29 | ||
31 | casper.run(function() { | 30 | casper.run(function() { |
32 | t.done(); | 31 | this.test.done(); |
33 | }); | 32 | }); |
34 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('Casper.viewport()'); |
2 | t.comment('Casper.viewport()'); | ||
3 | 2 | ||
4 | casper.start(); | 3 | casper.start(); |
5 | 4 | ||
6 | casper.viewport(1337, 999); | 5 | casper.viewport(1337, 999); |
7 | 6 | ||
8 | t.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport() can change the width of page viewport'); | 7 | casper.test.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport() can change the width of page viewport'); |
9 | t.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of page viewport'); | 8 | casper.test.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of page viewport'); |
10 | t.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validates viewport size data'); | 9 | casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validates viewport size data'); |
11 | 10 | ||
12 | t.done(); | 11 | casper.test.done(); |
13 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.start('tests/site/visible.html', function() { |
2 | casper.start('tests/site/visible.html', function(self) { | 2 | this.test.comment('Casper.visible()'); |
3 | self.test.comment('Casper.visible()'); | 3 | this.test.assert(this.visible('#img1'), 'Casper.visible() can detect if an element is visible'); |
4 | self.test.assert(self.visible('#img1'), 'Casper.visible() can detect if an element is visible'); | 4 | this.test.assert(!this.visible('#img2'), 'Casper.visible() can detect if an element is invisible'); |
5 | self.test.assert(!self.visible('#img2'), 'Casper.visible() can detect if an element is invisible'); | 5 | this.test.assert(!this.visible('#img3'), 'Casper.visible() can detect if an element is invisible'); |
6 | self.test.assert(!self.visible('#img3'), 'Casper.visible() can detect if an element is invisible'); | 6 | this.waitWhileVisible('#img1', function() { |
7 | self.waitWhileVisible('#img1', function(self) { | 7 | this.test.comment('Casper.waitWhileVisible()'); |
8 | self.test.comment('Casper.waitWhileVisible()'); | 8 | this.test.pass('Casper.waitWhileVisible() can wait while an element is visible'); |
9 | self.test.pass('Casper.waitWhileVisible() can wait while an element is visible'); | 9 | }, function() { |
10 | }, function(self) { | 10 | this.test.comment('Casper.waitWhileVisible()'); |
11 | self.test.comment('Casper.waitWhileVisible()'); | 11 | this.test.fail('Casper.waitWhileVisible() can wait while an element is visible'); |
12 | self.test.fail('Casper.waitWhileVisible() can wait while an element is visible'); | ||
13 | }, 2000); | 12 | }, 2000); |
14 | }); | 13 | }); |
15 | 14 | ||
16 | casper.run(function(self) { | 15 | casper.run(function() { |
17 | t.done(); | 16 | this.test.done(); |
18 | }); | 17 | }); |
19 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | var waitStart; |
2 | var waitStart; | ||
3 | 2 | ||
4 | casper.start('tests/site/index.html', function(self) { | 3 | casper.start('tests/site/index.html', function() { |
5 | waitStart = new Date().getTime(); | 4 | waitStart = new Date().getTime(); |
6 | }); | 5 | }); |
7 | 6 | ||
8 | casper.wait(1000, function(self) { | 7 | casper.wait(1000, function() { |
9 | self.test.comment('Casper.wait()'); | 8 | this.test.comment('Casper.wait()'); |
10 | self.test.assert(new Date().getTime() - waitStart > 1000, 'Casper.wait() can wait for a given amount of time'); | 9 | this.test.assert(new Date().getTime() - waitStart > 1000, 'Casper.wait() can wait for a given amount of time'); |
11 | // Casper.waitFor() | 10 | // Casper.waitFor() |
12 | casper.thenOpen('tests/site/waitFor.html', function(self) { | 11 | casper.thenOpen('tests/site/waitFor.html', function() { |
13 | casper.test.comment('Casper.waitFor()'); | 12 | this.test.comment('Casper.waitFor()'); |
14 | self.waitFor(function(self) { | 13 | this.waitFor(function() { |
15 | return self.evaluate(function() { | 14 | return this.evaluate(function() { |
16 | return document.querySelectorAll('li').length === 4; | 15 | return document.querySelectorAll('li').length === 4; |
17 | }); | 16 | }); |
18 | }, function(self) { | 17 | }, function() { |
19 | self.test.pass('Casper.waitFor() can wait for something to happen'); | 18 | this.test.pass('Casper.waitFor() can wait for something to happen'); |
20 | }, function(self) { | 19 | }, function() { |
21 | self.test.fail('Casper.waitFor() can wait for something to happen'); | 20 | this.test.fail('Casper.waitFor() can wait for something to happen'); |
22 | }); | ||
23 | }); | 21 | }); |
24 | }); | 22 | }); |
23 | }); | ||
25 | 24 | ||
26 | casper.run(function(self) { | 25 | casper.run(function() { |
27 | t.done(); | 26 | this.test.done(); |
28 | }); | 27 | }); |
29 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | var cli = require('cli'), t = casper.test; |
2 | var cli = require('cli'); | ||
3 | 2 | ||
4 | t.comment('parse(), get(), has()'); | 3 | t.comment('parse(), get(), has()'); |
5 | 4 | ||
6 | (function(parsed) { | 5 | (function(parsed) { |
7 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); | 6 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); |
8 | t.assertEquals(parsed.options, {}, 'parse() returns expected options object'); | 7 | t.assertEquals(parsed.options, {}, 'parse() returns expected options object'); |
9 | t.assertEquals(parsed.get(0), undefined, 'parse() does not return inexistant positional arg'); | 8 | t.assertEquals(parsed.get(0), undefined, 'parse() does not return inexistant positional arg'); |
10 | t.assertEquals(parsed.get('blah'), undefined, 'parse() does not return inexistant option'); | 9 | t.assertEquals(parsed.get('blah'), undefined, 'parse() does not return inexistant option'); |
11 | t.assert(!parsed.has(0), 'has() checks if an arg is set'); | 10 | t.assert(!parsed.has(0), 'has() checks if an arg is set'); |
12 | t.assert(!parsed.has('blah'), 'has() checks if an option is set'); | 11 | t.assert(!parsed.has('blah'), 'has() checks if an option is set'); |
13 | })(cli.parse([])); | 12 | })(cli.parse([])); |
14 | 13 | ||
15 | (function(parsed) { | 14 | (function(parsed) { |
16 | t.assertEquals(parsed.args, ['foo', 'bar'], 'parse() returns expected positional args array'); | 15 | t.assertEquals(parsed.args, ['foo', 'bar'], 'parse() returns expected positional args array'); |
17 | t.assertEquals(parsed.options, {}, 'parse() returns expected options object'); | 16 | t.assertEquals(parsed.options, {}, 'parse() returns expected options object'); |
18 | t.assertEquals(parsed.get(0), 'foo', 'parse() retrieve first positional arg'); | 17 | t.assertEquals(parsed.get(0), 'foo', 'parse() retrieve first positional arg'); |
... | @@ -20,25 +19,25 @@ | ... | @@ -20,25 +19,25 @@ |
20 | t.assert(parsed.has(0), 'has() checks if an arg is set'); | 19 | t.assert(parsed.has(0), 'has() checks if an arg is set'); |
21 | t.assert(parsed.has(1), 'has() checks if an arg is set'); | 20 | t.assert(parsed.has(1), 'has() checks if an arg is set'); |
22 | t.assert(!parsed.has(2), 'has() checks if an arg is not set'); | 21 | t.assert(!parsed.has(2), 'has() checks if an arg is not set'); |
23 | })(cli.parse(['foo', 'bar'])); | 22 | })(cli.parse(['foo', 'bar'])); |
24 | 23 | ||
25 | (function(parsed) { | 24 | (function(parsed) { |
26 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); | 25 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); |
27 | t.assertEquals(parsed.options, {foo: 'bar', baz: true}, 'parse() returns expected options object'); | 26 | t.assertEquals(parsed.options, {foo: 'bar', baz: true}, 'parse() returns expected options object'); |
28 | t.assertEquals(parsed.get('foo'), 'bar', 'parse() retrieve an option value'); | 27 | t.assertEquals(parsed.get('foo'), 'bar', 'parse() retrieve an option value'); |
29 | t.assert(parsed.get('baz'), 'parse() retrieve boolean option flag'); | 28 | t.assert(parsed.get('baz'), 'parse() retrieve boolean option flag'); |
30 | t.assert(parsed.has("foo"), 'has() checks if an option is set'); | 29 | t.assert(parsed.has("foo"), 'has() checks if an option is set'); |
31 | t.assert(parsed.has("baz"), 'has() checks if an option is set'); | 30 | t.assert(parsed.has("baz"), 'has() checks if an option is set'); |
32 | })(cli.parse(['--foo=bar', '--baz'])); | 31 | })(cli.parse(['--foo=bar', '--baz'])); |
33 | 32 | ||
34 | (function(parsed) { | 33 | (function(parsed) { |
35 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); | 34 | t.assertEquals(parsed.args, [], 'parse() returns expected positional args array'); |
36 | t.assertEquals(parsed.options, { '&é"à': 42 }, 'parse() returns expected options object'); | 35 | t.assertEquals(parsed.options, { '&é"à': 42 }, 'parse() returns expected options object'); |
37 | t.assertEquals(parsed.get('&é"à'), 42, 'parse() handles options with exotic names'); | 36 | t.assertEquals(parsed.get('&é"à'), 42, 'parse() handles options with exotic names'); |
38 | t.assert(parsed.has('&é"à'), 'has() checks if an option is set'); | 37 | t.assert(parsed.has('&é"à'), 'has() checks if an option is set'); |
39 | })(cli.parse(['--&é"à=42'])); | 38 | })(cli.parse(['--&é"à=42'])); |
40 | 39 | ||
41 | (function(parsed) { | 40 | (function(parsed) { |
42 | t.assertEquals(parsed.args, ['foo & bar', 'baz & boz'], 'parse() returns expected positional args array'); | 41 | t.assertEquals(parsed.args, ['foo & bar', 'baz & boz'], 'parse() returns expected positional args array'); |
43 | t.assertEquals(parsed.options, { universe: 42, lap: 13.37, chucknorris: true, oops: false }, 'parse() returns expected options object'); | 42 | t.assertEquals(parsed.options, { universe: 42, lap: 13.37, chucknorris: true, oops: false }, 'parse() returns expected options object'); |
44 | t.assertEquals(parsed.get('universe'), 42, 'parse() can cast a numeric option value'); | 43 | t.assertEquals(parsed.get('universe'), 42, 'parse() can cast a numeric option value'); |
... | @@ -66,7 +65,6 @@ | ... | @@ -66,7 +65,6 @@ |
66 | chucknorris: true, | 65 | chucknorris: true, |
67 | oops: false | 66 | oops: false |
68 | }, 'drop() did not affect other options'); | 67 | }, 'drop() did not affect other options'); |
69 | })(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false'])); | 68 | })(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false'])); |
70 | 69 | ||
71 | t.done(); | 70 | t.done(); |
72 | })(casper.test); | ... | ... |
1 | "A small subset of the run.js written in coffeescript" | 1 | "A small subset of the run.js written in coffeescript" |
2 | 2 | ||
3 | do (casper) -> | 3 | steps = 0 |
4 | steps = 0 | ||
5 | 4 | ||
6 | casper.options.onStepComplete = -> steps++ | 5 | casper.options.onStepComplete = -> steps++ |
7 | 6 | ||
8 | casper.start "tests/site/index.html", -> | 7 | casper.start "tests/site/index.html", -> |
9 | @test.assertTitle "CasperJS test index", "Casper.start() casper can start itself an open an url" | 8 | @test.assertTitle "CasperJS test index", "Casper.start() casper can start itself an open an url" |
10 | @test.assertEquals @fetchText("ul li"), "onetwothree", "Casper.fetchText() can retrieves text contents" | 9 | @test.assertEquals @fetchText("ul li"), "onetwothree", "Casper.fetchText() can retrieves text contents" |
11 | @click "a[href=\"test.html\"]" | 10 | @click "a[href=\"test.html\"]" |
12 | 11 | ||
13 | casper.then -> | 12 | casper.then -> |
14 | @test.assertTitle "CasperJS test target", "Casper.click() casper can click on a text link" | 13 | @test.assertTitle "CasperJS test target", "Casper.click() casper can click on a text link" |
15 | @click "a[href=\"form.html\"]" | 14 | @click "a[href=\"form.html\"]" |
16 | 15 | ||
17 | casper.run -> | 16 | casper.run -> |
18 | @test.assertEquals steps, 3, "Casper.options.onStepComplete() is called on step complete" | 17 | @test.assertEquals steps, 3, "Casper.options.onStepComplete() is called on step complete" |
19 | @options.onStepComplete = null | 18 | @options.onStepComplete = null |
20 | @test.done() | 19 | @test.done() | ... | ... |
1 | (function(t) { | 1 | var error; |
2 | var error; | ||
3 | 2 | ||
4 | function foo() { | 3 | function foo() { |
5 | bar(); | 4 | bar(); |
6 | } | 5 | } |
7 | 6 | ||
8 | function bar() { | 7 | function bar() { |
9 | throw new CasperError('bar'); | 8 | throw new CasperError('bar'); |
10 | } | 9 | } |
11 | 10 | ||
12 | try { | 11 | try { |
13 | foo(); | 12 | foo(); |
14 | } catch (e) { | 13 | } catch (e) { |
15 | error = e; | 14 | error = e; |
16 | } | 15 | } |
17 | 16 | ||
18 | t.assertType(error.stack, "string", "CasperError() has a stack string property set"); | 17 | casper.test.assertType(error.stack, "string", "CasperError() has a stack string property set"); |
19 | t.assertMatch(error.stack, /^CasperError: bar\s/, "CasperError() has the expected stack value"); | 18 | casper.test.assertMatch(error.stack, /^CasperError: bar\s/, "CasperError() has the expected stack value"); |
20 | 19 | ||
21 | t.done(); | ||
22 | })(casper.test); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
20 | casper.test.done(); | ... | ... |
1 | (function(t) { | 1 | var t = casper.test; |
2 | function createInjector(fn, values) { | 2 | var createInjector = function(fn, values) { |
3 | return require('injector').create(fn, values); | 3 | return require('injector').create(fn, values); |
4 | } | 4 | }; |
5 | var testFn = function(a, b) { return a + b; }; | ||
6 | var injector = createInjector(testFn); | ||
7 | var extract = injector.extract(testFn); | ||
5 | 8 | ||
6 | var testFn = function(a, b) { return a + b; }; | 9 | t.comment('FunctionArgsInjector.extract()'); |
7 | var injector = createInjector(testFn); | 10 | t.assertType(extract, "object", 'FunctionArgsInjector.extract() returns an object'); |
8 | var extract = injector.extract(testFn); | 11 | t.assertEquals(extract.name, null, 'FunctionArgsInjector.extract() process function name as expected'); |
12 | t.assertEquals(extract.body, 'return a + b;', 'FunctionArgsInjector.extract() process function body as expected'); | ||
13 | t.assertEquals(extract.args, ['a', 'b'], 'FunctionArgsInjector.extract() process function args as expected'); | ||
9 | 14 | ||
10 | t.comment('FunctionArgsInjector.extract()'); | 15 | function Plop(foo, bar) { |
11 | t.assertType(extract, "object", 'FunctionArgsInjector.extract() returns an object'); | ||
12 | t.assertEquals(extract.name, null, 'FunctionArgsInjector.extract() process function name as expected'); | ||
13 | t.assertEquals(extract.body, 'return a + b;', 'FunctionArgsInjector.extract() process function body as expected'); | ||
14 | t.assertEquals(extract.args, ['a', 'b'], 'FunctionArgsInjector.extract() process function args as expected'); | ||
15 | |||
16 | function Plop(foo, bar) { | ||
17 | return 'foo: ' + foo +', bar: ' + bar; | 16 | return 'foo: ' + foo +', bar: ' + bar; |
18 | } | 17 | } |
19 | function Plip() { return 'plop'; } | 18 | function Plip() { return 'plop'; } |
20 | function foo_bar(boz) {} | 19 | function foo_bar(boz) {} |
21 | var gni = function ($bubu_bibi, __popo__) {}; | 20 | var gni = function ($bubu_bibi, __popo__) {}; |
22 | var gno = function ( arg1, /*plop*/ arg2 ) { }; | 21 | var gno = function ( arg1, /*plop*/ arg2 ) { }; |
23 | t.assertEquals(injector.extract(Plop), { | 22 | t.assertEquals(injector.extract(Plop), { |
24 | name: 'Plop', | 23 | name: 'Plop', |
25 | args: ['foo', 'bar'], | 24 | args: ['foo', 'bar'], |
26 | body: "return 'foo: ' + foo +', bar: ' + bar;" | 25 | body: "return 'foo: ' + foo +', bar: ' + bar;" |
27 | }, 'FunctionArgsInjector.extract() handles named functions with arguments and body'); | 26 | }, 'FunctionArgsInjector.extract() handles named functions with arguments and body'); |
28 | t.assertEquals(injector.extract(Plip), { | 27 | t.assertEquals(injector.extract(Plip), { |
29 | name: 'Plip', | 28 | name: 'Plip', |
30 | args: [], | 29 | args: [], |
31 | body: "return 'plop';" | 30 | body: "return 'plop';" |
32 | }, 'FunctionArgsInjector.extract() handles functions with no arguments'); | 31 | }, 'FunctionArgsInjector.extract() handles functions with no arguments'); |
33 | t.assertEquals(injector.extract(foo_bar), { | 32 | t.assertEquals(injector.extract(foo_bar), { |
34 | name: 'foo_bar', | 33 | name: 'foo_bar', |
35 | args: ['boz'], | 34 | args: ['boz'], |
36 | body: "" | 35 | body: "" |
37 | }, 'FunctionArgsInjector.extract() handles functions with no body'); | 36 | }, 'FunctionArgsInjector.extract() handles functions with no body'); |
38 | t.assertEquals(injector.extract(gni), { | 37 | t.assertEquals(injector.extract(gni), { |
39 | name: null, | 38 | name: null, |
40 | args: ['$bubu_bibi', '__popo__'], | 39 | args: ['$bubu_bibi', '__popo__'], |
41 | body: "" | 40 | body: "" |
42 | }, 'FunctionArgsInjector.extract() handles anonymous functions with complex args passed'); | 41 | }, 'FunctionArgsInjector.extract() handles anonymous functions with complex args passed'); |
43 | t.assertEquals(injector.extract(gno), { | 42 | t.assertEquals(injector.extract(gno), { |
44 | name: null, | 43 | name: null, |
45 | args: ['arg1', 'arg2'], | 44 | args: ['arg1', 'arg2'], |
46 | body: "" | 45 | body: "" |
47 | }, 'FunctionArgsInjector.extract() handles can filter comments in function args'); | 46 | }, 'FunctionArgsInjector.extract() handles can filter comments in function args'); |
48 | 47 | ||
49 | t.comment('FunctionArgsInjector.process()'); | 48 | t.comment('FunctionArgsInjector.process()'); |
50 | var processed; | 49 | var processed; |
51 | eval('processed = ' + injector.process({ a: 1, b: 2 })); | 50 | eval('processed = ' + injector.process({ a: 1, b: 2 })); |
52 | 51 | ||
53 | t.assertType(processed, "function", 'FunctionArgsInjector.process() processed a function'); | 52 | t.assertType(processed, "function", 'FunctionArgsInjector.process() processed a function'); |
54 | t.assertEquals(processed(), 3, 'FunctionArgsInjector.process() processed the function correctly'); | 53 | t.assertEquals(processed(), 3, 'FunctionArgsInjector.process() processed the function correctly'); |
55 | 54 | ||
56 | t.done(); | 55 | t.done(); |
57 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | var t = casper.test; |
2 | t.comment('Tester.testEquals()'); | ||
3 | t.assert(casper.test.testEquals(null, null), 'Tester.testEquals() null equality'); | ||
4 | t.assertNot(casper.test.testEquals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); | ||
5 | t.assert(casper.test.testEquals("hi", "hi"), 'Tester.testEquals() string equality'); | ||
6 | t.assertNot(casper.test.testEquals("hi", "ih"), 'Tester.testEquals() string inequality'); | ||
7 | t.assert(casper.test.testEquals(5, 5), 'Tester.testEquals() number equality'); | ||
8 | t.assertNot(casper.test.testEquals("5", 5), 'Tester.testEquals() number equality without implicit cast'); | ||
9 | t.assert(casper.test.testEquals(5, 5.0), 'Tester.testEquals() number equality with cast'); | ||
10 | t.assertNot(casper.test.testEquals(5, 10), 'Tester.testEquals() number inequality'); | ||
11 | t.assert(casper.test.testEquals([], []), 'Tester.testEquals() empty array equality'); | ||
12 | t.assert(casper.test.testEquals([1,2], [1,2]), 'Tester.testEquals() array equality'); | ||
13 | t.assert(casper.test.testEquals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'Tester.testEquals() complex array equality'); | ||
14 | t.assertNot(casper.test.testEquals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'Tester.testEquals() complex array inequality'); | ||
15 | t.assertNot(casper.test.testEquals([1,2], [2,1]), 'Tester.testEquals() shuffled array inequality'); | ||
16 | t.assertNot(casper.test.testEquals([1,2], [1,2,3]), 'Tester.testEquals() array length inequality'); | ||
17 | t.assert(casper.test.testEquals({}, {}), 'Tester.testEquals() empty object equality'); | ||
18 | t.assert(casper.test.testEquals({a:1,b:2}, {a:1,b:2}), 'Tester.testEquals() object length equality'); | ||
19 | t.assert(casper.test.testEquals({a:1,b:2}, {b:2,a:1}), 'Tester.testEquals() shuffled object keys equality'); | ||
20 | t.assertNot(casper.test.testEquals({a:1,b:2}, {a:1,b:3}), 'Tester.testEquals() object inequality'); | ||
21 | t.assert(casper.test.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'Tester.testEquals() complex object equality'); | ||
22 | t.assertNot(casper.test.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'Tester.testEquals() complex object inequality'); | ||
23 | t.assert(casper.test.testEquals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality'); | ||
24 | t.assertNot(casper.test.testEquals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality'); | ||
25 | 2 | ||
26 | t.done(); | 3 | t.comment('Tester.testEquals()'); |
27 | })(casper.test); | 4 | t.assert(casper.test.testEquals(null, null), 'Tester.testEquals() null equality'); |
5 | t.assertNot(casper.test.testEquals(null, undefined), 'Tester.testEquals() null vs. undefined inequality'); | ||
6 | t.assert(casper.test.testEquals("hi", "hi"), 'Tester.testEquals() string equality'); | ||
7 | t.assertNot(casper.test.testEquals("hi", "ih"), 'Tester.testEquals() string inequality'); | ||
8 | t.assert(casper.test.testEquals(5, 5), 'Tester.testEquals() number equality'); | ||
9 | t.assertNot(casper.test.testEquals("5", 5), 'Tester.testEquals() number equality without implicit cast'); | ||
10 | t.assert(casper.test.testEquals(5, 5.0), 'Tester.testEquals() number equality with cast'); | ||
11 | t.assertNot(casper.test.testEquals(5, 10), 'Tester.testEquals() number inequality'); | ||
12 | t.assert(casper.test.testEquals([], []), 'Tester.testEquals() empty array equality'); | ||
13 | t.assert(casper.test.testEquals([1,2], [1,2]), 'Tester.testEquals() array equality'); | ||
14 | t.assert(casper.test.testEquals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'Tester.testEquals() complex array equality'); | ||
15 | t.assertNot(casper.test.testEquals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'Tester.testEquals() complex array inequality'); | ||
16 | t.assertNot(casper.test.testEquals([1,2], [2,1]), 'Tester.testEquals() shuffled array inequality'); | ||
17 | t.assertNot(casper.test.testEquals([1,2], [1,2,3]), 'Tester.testEquals() array length inequality'); | ||
18 | t.assert(casper.test.testEquals({}, {}), 'Tester.testEquals() empty object equality'); | ||
19 | t.assert(casper.test.testEquals({a:1,b:2}, {a:1,b:2}), 'Tester.testEquals() object length equality'); | ||
20 | t.assert(casper.test.testEquals({a:1,b:2}, {b:2,a:1}), 'Tester.testEquals() shuffled object keys equality'); | ||
21 | t.assertNot(casper.test.testEquals({a:1,b:2}, {a:1,b:3}), 'Tester.testEquals() object inequality'); | ||
22 | t.assert(casper.test.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'Tester.testEquals() complex object equality'); | ||
23 | t.assertNot(casper.test.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'Tester.testEquals() complex object inequality'); | ||
24 | t.assert(casper.test.testEquals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality'); | ||
25 | t.assertNot(casper.test.testEquals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality'); | ||
26 | |||
27 | t.done(); | ... | ... |
1 | (function(t) { | 1 | var utils = require('utils'), t = casper.test; |
2 | var utils = require('utils'); | ||
3 | 2 | ||
4 | t.comment('fileExt()'); | 3 | t.comment('fileExt()'); |
5 | (function() { | 4 | (function() { |
6 | var testCases = { | 5 | var testCases = { |
7 | 'foo.ext': 'ext', | 6 | 'foo.ext': 'ext', |
8 | 'FOO.EXT': 'ext', | 7 | 'FOO.EXT': 'ext', |
... | @@ -15,10 +14,10 @@ | ... | @@ -15,10 +14,10 @@ |
15 | for (var testCase in testCases) { | 14 | for (var testCase in testCases) { |
16 | t.assertEquals(utils.fileExt(testCase), testCases[testCase], 'fileExt() extract file extension'); | 15 | t.assertEquals(utils.fileExt(testCase), testCases[testCase], 'fileExt() extract file extension'); |
17 | } | 16 | } |
18 | })(); | 17 | })(); |
19 | 18 | ||
20 | t.comment('fillBlanks()'); | 19 | t.comment('fillBlanks()'); |
21 | (function() { | 20 | (function() { |
22 | testCases = { | 21 | testCases = { |
23 | 'foo': 'foo ', | 22 | 'foo': 'foo ', |
24 | ' foo bar ': ' foo bar ', | 23 | ' foo bar ': ' foo bar ', |
... | @@ -28,10 +27,10 @@ | ... | @@ -28,10 +27,10 @@ |
28 | for (var testCase in testCases) { | 27 | for (var testCase in testCases) { |
29 | t.assertEquals(utils.fillBlanks(testCase, 10), testCases[testCase], 'fillBlanks() fills blanks'); | 28 | t.assertEquals(utils.fillBlanks(testCase, 10), testCases[testCase], 'fillBlanks() fills blanks'); |
30 | } | 29 | } |
31 | })(); | 30 | })(); |
32 | 31 | ||
33 | t.comment('isClipRect()'); | 32 | t.comment('isClipRect()'); |
34 | (function() { | 33 | (function() { |
35 | testCases = [ | 34 | testCases = [ |
36 | [{}, false], | 35 | [{}, false], |
37 | [{top: 2}, false], | 36 | [{top: 2}, false], |
... | @@ -43,10 +42,10 @@ | ... | @@ -43,10 +42,10 @@ |
43 | testCases.forEach(function(testCase) { | 42 | testCases.forEach(function(testCase) { |
44 | t.assertEquals(utils.isClipRect(testCase[0]), testCase[1], 'isClipRect() checks for a ClipRect'); | 43 | t.assertEquals(utils.isClipRect(testCase[0]), testCase[1], 'isClipRect() checks for a ClipRect'); |
45 | }); | 44 | }); |
46 | })(); | 45 | })(); |
47 | 46 | ||
48 | t.comment('isJsFile()'); | 47 | t.comment('isJsFile()'); |
49 | (function() { | 48 | (function() { |
50 | testCases = { | 49 | testCases = { |
51 | '': false, | 50 | '': false, |
52 | 'toto.png': false, | 51 | 'toto.png': false, |
... | @@ -58,10 +57,10 @@ | ... | @@ -58,10 +57,10 @@ |
58 | for (var testCase in testCases) { | 57 | for (var testCase in testCases) { |
59 | t.assertEquals(utils.isJsFile(testCase), testCases[testCase], 'isJsFile() checks for js file'); | 58 | t.assertEquals(utils.isJsFile(testCase), testCases[testCase], 'isJsFile() checks for js file'); |
60 | } | 59 | } |
61 | })(); | 60 | })(); |
62 | 61 | ||
63 | t.comment('mergeObjects()'); | 62 | t.comment('mergeObjects()'); |
64 | (function() { | 63 | (function() { |
65 | testCases = [ | 64 | testCases = [ |
66 | { | 65 | { |
67 | obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2} | 66 | obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2} |
... | @@ -89,7 +88,6 @@ | ... | @@ -89,7 +88,6 @@ |
89 | testCases.forEach(function(testCase) { | 88 | testCases.forEach(function(testCase) { |
90 | t.assertEquals(utils.mergeObjects(testCase.obj1, testCase.obj2), testCase.merged, 'mergeObjects() can merge objects'); | 89 | t.assertEquals(utils.mergeObjects(testCase.obj1, testCase.obj2), testCase.merged, 'mergeObjects() can merge objects'); |
91 | }); | 90 | }); |
92 | })(); | 91 | })(); |
93 | 92 | ||
94 | t.done(); | 93 | t.done(); |
95 | })(casper.test); | ... | ... |
1 | (function(t) { | 1 | casper.test.comment('phantom.Casper.XUnitExporter'); |
2 | t.comment('phantom.Casper.XUnitExporter'); | ||
3 | 2 | ||
4 | xunit = require('xunit').create(); | 3 | xunit = require('xunit').create(); |
5 | xunit.addSuccess('foo', 'bar'); | 4 | xunit.addSuccess('foo', 'bar'); |
6 | t.assertMatch(xunit.getXML(), /<testcase classname="foo" name="bar"/, 'XUnitExporter.addSuccess() adds a successful testcase'); | 5 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="foo" name="bar"/, 'XUnitExporter.addSuccess() adds a successful testcase'); |
7 | xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz'); | 6 | xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz'); |
8 | t.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase'); | 7 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase'); |
9 | 8 | ||
10 | t.done(); | 9 | casper.test.done(); |
11 | })(casper.test); | ... | ... |
-
Please register or sign in to post a comment