(fn, expected)
| 472 | |
| 473 | // Utility for testing whether a function throws an error |
| 474 | function functionThrows (fn, expected) { |
| 475 | |
| 476 | // Try/catch |
| 477 | var thrown = false; |
| 478 | var thrownError; |
| 479 | try { |
| 480 | fn(); |
| 481 | } catch (err) { |
| 482 | thrown = true; |
| 483 | thrownError = err; |
| 484 | } |
| 485 | |
| 486 | // Check error |
| 487 | if (thrown && expected) { |
| 488 | thrown = errorMatches(thrownError, expected); |
| 489 | } |
| 490 | |
| 491 | return thrown; |
| 492 | } |
| 493 | |
| 494 | // Utility for checking whether an error matches a given constructor, regexp or string |
| 495 | function errorMatches (actual, expected) { |
no test coverage detected