fixed #821 - test.assertRaises always PASS
Showing
2 changed files
with
14 additions
and
11 deletions
... | @@ -688,20 +688,23 @@ Tester.prototype.assertRaises = | ... | @@ -688,20 +688,23 @@ Tester.prototype.assertRaises = |
688 | Tester.prototype.assertRaise = | 688 | Tester.prototype.assertRaise = |
689 | Tester.prototype.assertThrows = function assertRaises(fn, args, message) { | 689 | Tester.prototype.assertThrows = function assertRaises(fn, args, message) { |
690 | "use strict"; | 690 | "use strict"; |
691 | var context = { | 691 | var thrown = false, |
692 | error = undefined, | ||
693 | context = { | ||
692 | type: "assertRaises", | 694 | type: "assertRaises", |
693 | standard: "Function raises an error" | 695 | standard: "Function raises an error" |
694 | }; | 696 | }; |
695 | try { | 697 | try { |
696 | fn.apply(null, args); | 698 | fn.apply(null, args); |
697 | this.assert(false, message, context); | 699 | } catch (err) { |
698 | } catch (error) { | 700 | thrown = true; |
699 | this.assert(true, message, utils.mergeObjects(context, { | 701 | error = err; |
702 | } | ||
703 | this.assert(thrown, message, utils.mergeObjects(context, { | ||
700 | values: { | 704 | values: { |
701 | error: error | 705 | error: error |
702 | } | 706 | } |
703 | })); | 707 | })); |
704 | } | ||
705 | }; | 708 | }; |
706 | 709 | ||
707 | /** | 710 | /** | ... | ... |
... | @@ -48,12 +48,12 @@ casper.test.begin('Common assertions tests', 47, function(test) { | ... | @@ -48,12 +48,12 @@ casper.test.begin('Common assertions tests', 47, function(test) { |
48 | test.assertRaises(function() { | 48 | test.assertRaises(function() { |
49 | throw new Error('plop'); | 49 | throw new Error('plop'); |
50 | }, [], 'Tester.assertRaises() works as expected'); | 50 | }, [], 'Tester.assertRaises() works as expected'); |
51 | test.assertRaise(function() { | 51 | try { |
52 | throw new Error('plop'); | 52 | test.assertRaises(function() {}, []); |
53 | }, [], 'Tester.assertRaise() works as expected [alias]'); | 53 | test.fail("Tester.assertRaises() doesn't pass when no error is thrown"); |
54 | test.assertThrows(function() { | 54 | } catch (err) { |
55 | throw new Error('plop'); | 55 | test.pass("Tester.assertRaises() doesn't pass when no error is thrown"); |
56 | }, [], 'Tester.assertThrows() works as expected [alias]'); | 56 | } |
57 | test.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected'); | 57 | test.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected'); |
58 | test.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]'); | 58 | test.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]'); |
59 | test.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected'); | 59 | test.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected'); | ... | ... |
-
Please register or sign in to post a comment