(shouldThrow, block, expected, message)
| 8697 | } |
| 8698 | |
| 8699 | function _throws(shouldThrow, block, expected, message) { |
| 8700 | var actual; |
| 8701 | |
| 8702 | if (typeof block !== 'function') { |
| 8703 | throw new TypeError('"block" argument must be a function'); |
| 8704 | } |
| 8705 | |
| 8706 | if (typeof expected === 'string') { |
| 8707 | message = expected; |
| 8708 | expected = null; |
| 8709 | } |
| 8710 | |
| 8711 | actual = _tryBlock(block); |
| 8712 | |
| 8713 | message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + |
| 8714 | (message ? ' ' + message : '.'); |
| 8715 | |
| 8716 | if (shouldThrow && !actual) { |
| 8717 | fail(actual, expected, 'Missing expected exception' + message); |
| 8718 | } |
| 8719 | |
| 8720 | var userProvidedMessage = typeof message === 'string'; |
| 8721 | var isUnwantedException = !shouldThrow && util.isError(actual); |
| 8722 | var isUnexpectedException = !shouldThrow && actual && !expected; |
| 8723 | |
| 8724 | if ((isUnwantedException && |
| 8725 | userProvidedMessage && |
| 8726 | expectedException(actual, expected)) || |
| 8727 | isUnexpectedException) { |
| 8728 | fail(actual, expected, 'Got unwanted exception' + message); |
| 8729 | } |
| 8730 | |
| 8731 | if ((shouldThrow && actual && expected && |
| 8732 | !expectedException(actual, expected)) || (!shouldThrow && actual)) { |
| 8733 | throw actual; |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | // 11. Expected to throw an error: |
| 8738 | // assert.throws(block, Error_opt, message_opt); |
no test coverage detected