Commit c24f3e2e c24f3e2e0002c746b8b07b7f2029bc52222d2aa4 by Nicolas Perriault

fixed #821 - test.assertRaises always PASS

1 parent 69728f9b
......@@ -688,20 +688,23 @@ Tester.prototype.assertRaises =
Tester.prototype.assertRaise =
Tester.prototype.assertThrows = function assertRaises(fn, args, message) {
"use strict";
var context = {
type: "assertRaises",
standard: "Function raises an error"
};
var thrown = false,
error = undefined,
context = {
type: "assertRaises",
standard: "Function raises an error"
};
try {
fn.apply(null, args);
this.assert(false, message, context);
} catch (error) {
this.assert(true, message, utils.mergeObjects(context, {
values: {
error: error
}
}));
} catch (err) {
thrown = true;
error = err;
}
this.assert(thrown, message, utils.mergeObjects(context, {
values: {
error: error
}
}));
};
/**
......
......@@ -48,12 +48,12 @@ casper.test.begin('Common assertions tests', 47, function(test) {
test.assertRaises(function() {
throw new Error('plop');
}, [], 'Tester.assertRaises() works as expected');
test.assertRaise(function() {
throw new Error('plop');
}, [], 'Tester.assertRaise() works as expected [alias]');
test.assertThrows(function() {
throw new Error('plop');
}, [], 'Tester.assertThrows() works as expected [alias]');
try {
test.assertRaises(function() {}, []);
test.fail("Tester.assertRaises() doesn't pass when no error is thrown");
} catch (err) {
test.pass("Tester.assertRaises() doesn't pass when no error is thrown");
}
test.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected');
test.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]');
test.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected');
......