Permalink
Browse files

migrated remaining tests to the new format

  • Loading branch information...
1 parent 8e10762 commit c61f0f1839c4aa73800b50871f52d9e97159d7b1 @n1k0 n1k0 committed Dec 29, 2012
2 docs
Submodule docs updated from 058396 to 18b8cb
View
@@ -16,7 +16,7 @@
var li = document.createElement('li')
li.appendChild(document.createTextNode('four'));
document.querySelector('ul').appendChild(li);
- }, 2000);
+ }, 500);
</script>
</body>
-</html>
+</html>
@@ -1,10 +1,12 @@
/*global casper*/
/*jshint strict:false*/
-casper.start('tests/site/index.html', function() {
- this.test.assertEquals(this.getHTML('ul li'), 'one', 'Casper.getHTML() retrieves inner HTML by default');
- this.test.assertEquals(this.getHTML('ul li', true), '<li>one</li>', 'Casper.getHTML() can retrieve outer HTML');
-});
-
-casper.run(function() {
- casper.test.done(2);
+casper.test.begin('getHTML() tests', 2, function(test) {
+ casper.start('tests/site/index.html', function() {
+ test.assertEquals(this.getHTML('ul li'), 'one',
+ 'Casper.getHTML() retrieves inner HTML by default');
+ test.assertEquals(this.getHTML('ul li', true), '<li>one</li>',
+ 'Casper.getHTML() can retrieve outer HTML');
+ }).run(function() {
+ test.done();
+ });
});
@@ -1,10 +1,10 @@
/*global casper*/
/*jshint strict:false*/
-casper.start('tests/site/elementattribute.html', function() {
- this.test.comment('Casper.getElementAttribute()');
- this.test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string', 'Casper.getElementAttribute() works as intended');
-});
-
-casper.run(function() {
- this.test.done(1);
+casper.test.begin('getElementAttribute() tests', 1, function(test) {
+ casper.start('tests/site/elementattribute.html', function() {
+ test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string',
+ 'Casper.getElementAttribute() works as intended');
+ }).run(function() {
+ test.done();
+ });
});
@@ -2,23 +2,18 @@
/*jshint strict:false*/
var fs = require('fs');
-// FIXME: we're using local url scheme until https://github.com/ariya/phantomjs/pull/288 is
-// possibly merged
-casper.start('file://' + phantom.casperPath + '/tests/site/index.html', function() {
- var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png';
- var image = this.base64encode(imageUrl);
-
- this.test.comment('Casper.base64encode()');
- this.test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents');
-
- this.test.comment('Casper.download()');
- this.download(imageUrl, '__test_logo.png');
- this.test.assert(fs.exists('__test_logo.png'), 'Casper.download() downloads a file');
- if (fs.exists('__test_logo.png')) {
- fs.remove('__test_logo.png');
- }
-});
-
-casper.run(function() {
- this.test.done(2);
+casper.test.begin('base64encode() and download() tests', 2, function(test) {
+ // FIXME: https://github.com/ariya/phantomjs/pull/364 has been merged, update scheme
+ casper.start('file://' + phantom.casperPath + '/tests/site/index.html', function() {
+ var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png',
+ image = this.base64encode(imageUrl);
+ test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents');
+ this.download(imageUrl, '__test_logo.png');
+ test.assert(fs.exists('__test_logo.png'), 'Casper.download() downloads a file');
+ if (fs.exists('__test_logo.png')) {
+ fs.remove('__test_logo.png');
+ }
+ }).run(function() {
+ test.done();
+ });
});
@@ -1,87 +1,92 @@
/*global casper*/
/*jshint strict:false maxparams:99*/
-casper.test.comment('Casper.evaluate()');
-
-casper.start();
-
-var context = {
- "_boolean_true": true,
- "_boolean_false": false,
- "_int_number": 42,
- "_float_number": 1337.42,
- "_string": "plop! \"Ÿ£$\" 'no'",
- "_array": [1, 2, 3],
- "_object": {a: 1, b: 2},
- "_function": function(){console.log('ok');}
-};
-
-var result = casper.evaluate(function(_boolean_true,
- _boolean_false,
- _int_number,
- _float_number,
- _string,
- _array,
- _object,
- _function) {
- return [].map.call(arguments, function(arg) {
- return typeof(arg);
- });
-}, context);
-
-casper.test.assertEquals(result.toString(),
- ['boolean', 'boolean', 'number', 'number', 'string', 'object', 'object', 'function'].toString(),
- 'Casper.evaluate() handles passed argument context correcly');
-
-// no context
-casper.test.assertEquals(casper.evaluate(function() {
- return 42;
-}), 42, 'Casper.evaluate() handles evaluation with no context passed');
-
-// object context (previous casperjs versions compatibility mode)
-casper.test.assertEquals(casper.evaluate(function(a) {
- return [a];
-}, {a: "foo"}), ["foo"], 'Casper.evaluate() accepts an object as arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b) {
- return [a, b];
-}, {a: "foo", b: "bar"}), ["foo", "bar"], 'Casper.evaluate() accepts an object as arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b, c) {
- return [a, b, c];
-}, {a: "foo", b: "bar", c: "baz"}), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an object as arguments context');
+casper.test.begin('mapping argument context', 1, function(test) {
+ casper.start();
+ var context = {
+ "_boolean_true": true,
+ "_boolean_false": false,
+ "_int_number": 42,
+ "_float_number": 1337.42,
+ "_string": "plop! \"Ÿ£$\" 'no'",
+ "_array": [1, 2, 3],
+ "_object": {a: 1, b: 2},
+ "_function": function(){console.log('ok');}
+ };
+ var result = casper.evaluate(function(_boolean_true, _boolean_false, _int_number,
+ _float_number, _string, _array, _object, _function) {
+ return [].map.call(arguments, function(arg) {
+ return typeof(arg);
+ });
+ }, context);
+ test.assertEquals(
+ result.toString(),
+ ['boolean', 'boolean', 'number', 'number', 'string', 'object', 'object', 'function'].toString(),
+ 'Casper.evaluate() handles passed argument context correcly'
+ );
+ test.done();
+});
-// array context
-casper.test.assertEquals(casper.evaluate(function(a) {
- return [a];
-}, ["foo"]), ["foo"], 'Casper.evaluate() accepts an array as arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b) {
- return [a, b];
-}, ["foo", "bar"]), ["foo", "bar"], 'Casper.evaluate() accepts an array as arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b, c) {
- return [a, b, c];
-}, ["foo", "bar", "baz"]), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an array as arguments context');
+casper.test.begin('handling no argument context', 1, function(test) {
+ casper.start();
+ test.assertEquals(casper.evaluate(function() {
+ return 42;
+ }), 42, 'Casper.evaluate() handles evaluation with no context passed');
+ test.done();
+});
-// natural arguments context (phantomjs equivalent)
-casper.test.assertEquals(casper.evaluate(function(a) {
- return [a];
-}, "foo"), ["foo"], 'Casper.evaluate() accepts natural arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b) {
- return [a, b];
-}, "foo", "bar"), ["foo", "bar"], 'Casper.evaluate() accepts natural arguments context');
-casper.test.assertEquals(casper.evaluate(function(a, b, c) {
- return [a, b, c];
-}, "foo", "bar", "baz"), ["foo", "bar", "baz"], 'Casper.evaluate() accepts natural arguments context');
+casper.test.begin('handling of object context (BC mode)', 3, function(test) {
+ casper.start();
+ test.assertEquals(casper.evaluate(function(a) {
+ return [a];
+ }, {a: "foo"}), ["foo"], 'Casper.evaluate() accepts an object as arguments context');
+ test.assertEquals(casper.evaluate(function(a, b) {
+ return [a, b];
+ }, {a: "foo", b: "bar"}), ["foo", "bar"], 'Casper.evaluate() accepts an object as arguments context');
+ test.assertEquals(casper.evaluate(function(a, b, c) {
+ return [a, b, c];
+ }, {a: "foo", b: "bar", c: "baz"}), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an object as arguments context');
+ test.done();
+});
-casper.start().thenEvaluate(function(a, b) {
- window.a = a
- window.b = b;
-}, "foo", "bar");
+casper.test.begin('handling of array context', 3, function(test) {
+ casper.start();
+ test.assertEquals(casper.evaluate(function(a) {
+ return [a];
+ }, ["foo"]), ["foo"], 'Casper.evaluate() accepts an array as arguments context');
+ test.assertEquals(casper.evaluate(function(a, b) {
+ return [a, b];
+ }, ["foo", "bar"]), ["foo", "bar"], 'Casper.evaluate() accepts an array as arguments context');
+ test.assertEquals(casper.evaluate(function(a, b, c) {
+ return [a, b, c];
+ }, ["foo", "bar", "baz"]), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an array as arguments context');
+ test.done();
+});
-casper.then(function() {
- this.test.comment('Casper.thenEvaluate()');
- this.test.assertEquals(this.getGlobal('a'), "foo", "Casper.thenEvaluate() sets args");
- this.test.assertEquals(this.getGlobal('b'), "bar",
- "Casper.thenEvaluate() sets args the same way evaluate() does");
+casper.test.begin('natural arguments context (phantomjs equivalent)', 3, function(test) {
+ casper.start();
+ test.assertEquals(casper.evaluate(function(a) {
+ return [a];
+ }, "foo"), ["foo"], 'Casper.evaluate() accepts natural arguments context');
+ test.assertEquals(casper.evaluate(function(a, b) {
+ return [a, b];
+ }, "foo", "bar"), ["foo", "bar"], 'Casper.evaluate() accepts natural arguments context');
+ test.assertEquals(casper.evaluate(function(a, b, c) {
+ return [a, b, c];
+ }, "foo", "bar", "baz"), ["foo", "bar", "baz"], 'Casper.evaluate() accepts natural arguments context');
+ test.done();
});
-casper.run(function() {
- this.test.done(13);
+casper.test.begin('thenEvaluate() tests', 2, function(test) {
+ casper.start().thenEvaluate(function(a, b) {
+ window.a = a
+ window.b = b;
+ }, "foo", "bar");
+ casper.then(function() {
+ test.assertEquals(this.getGlobal('a'), "foo", "Casper.thenEvaluate() sets args");
+ test.assertEquals(this.getGlobal('b'), "bar",
+ "Casper.thenEvaluate() sets args the same way evaluate() does");
+ });
+ casper.run(function() {
+ test.done();
+ });
});
@@ -1,40 +1,29 @@
/*global casper*/
/*jshint strict:false*/
-// events
-
-casper.test.comment("events");
-
-casper.plopped = false;
-
-casper.on("plop", function() {
- this.plopped = true;
+casper.test.begin('events', 2, function(test) {
+ casper.plopped = false;
+ casper.on("plop", function() {
+ this.plopped = true;
+ });
+ test.assert(Object.keys(casper._events).some(function(i) {
+ return i === "plop";
+ }), "on() has set an event handler");
+ casper.emit("plop");
+ test.assert(casper.plopped, "emit() emits an event");
+ test.done();
});
-casper.test.assert(Object.keys(casper._events).some(function(i) {
- return i === "plop";
-}), "on() has set an event handler");
-
-casper.emit("plop");
-
-casper.test.assert(casper.plopped, "emit() emits an event");
-
-// filters
-
-casper.test.comment("filters");
-
-casper.foo = 0;
-casper.setFilter("test", function(a) {
- this.foo = 42;
- return a + 1;
+casper.test.begin('filters', 3, function(test) {
+ casper.foo = 0;
+ casper.setFilter("test", function(a) {
+ this.foo = 42;
+ return a + 1;
+ });
+ test.assert(Object.keys(casper._filters).some(function(i) {
+ return i === "test";
+ }), "setFilter() has set a filter");
+ test.assertEquals(casper.filter("test", 1), 2, "filter() filters a value");
+ test.assertEquals(casper.foo, 42, "filter() applies the correct context");
+ delete casper.foo;
+ test.done();
});
-
-casper.test.assert(Object.keys(casper._filters).some(function(i) {
- return i === "test";
-}), "setFilter() has set a filter");
-
-casper.test.assertEquals(casper.filter("test", 1), 2, "filter() filters a value");
-casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context");
-
-delete casper.foo;
-
-casper.test.done(5);
@@ -1,11 +1,10 @@
/*global casper*/
/*jshint strict:false*/
-casper.test.comment('Casper.exists()');
-
-casper.start('tests/site/index.html', function() {
- this.test.assert(this.exists('a') && !this.exists('chucknorriz'), 'Casper.exists() can check if an element exists');
-});
-
-casper.run(function() {
- this.test.done(1);
+casper.test.begin('exists() tests', 2, function(test) {
+ casper.start('tests/site/index.html', function() {
+ test.assert(this.exists('a'), 'Casper.exists() can check if an element exists');
+ test.assertNot(this.exists('chucknorriz'), 'Casper.exists() can check than an element does not exist')
+ }).run(function() {
+ test.done();
+ });
});
@@ -1,11 +1,10 @@
/*global casper*/
/*jshint strict:false*/
-casper.test.comment('Casper.fetchText()');
-
-casper.start('tests/site/index.html', function() {
- this.test.assertEquals(this.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents');
-});
-
-casper.run(function() {
- this.test.done(1);
+casper.test.begin('fetchText() tests', 1, function(test) {
+ casper.start('tests/site/index.html', function() {
+ test.assertEquals(this.fetchText('ul li'), 'onetwothree',
+ 'Casper.fetchText() can retrieve text contents');
+ }).run(function() {
+ test.done();
+ });
});
Oops, something went wrong.

0 comments on commit c61f0f1

Please sign in to comment.