(fn, expected)
| 101 | |
| 102 | // Utility for testing whether a function throws an error |
| 103 | function functionThrows (fn, expected) { |
| 104 | |
| 105 | // Try/catch |
| 106 | var thrown = false; |
| 107 | var thrownError; |
| 108 | try { |
| 109 | fn(); |
| 110 | } catch (err) { |
| 111 | thrown = true; |
| 112 | thrownError = err; |
| 113 | } |
| 114 | |
| 115 | // Check error |
| 116 | if (thrown && expected) { |
| 117 | thrown = errorMatches(thrownError, expected); |
| 118 | } |
| 119 | |
| 120 | return thrown; |
| 121 | } |
| 122 | |
| 123 | // Utility for checking whether an error matches a given constructor, regexp or string |
| 124 | function errorMatches (actual, expected) { |
no test coverage detected