pax_global_header00006660000000000000000000000064127343130420014511gustar00rootroot0000000000000052 comment=22a3985d2ec528015774206703332790aec4dea7 check-error-1.0.2/000077500000000000000000000000001273431304200137155ustar00rootroot00000000000000check-error-1.0.2/.gitignore000066400000000000000000000002151273431304200157030ustar00rootroot00000000000000lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results build components node_modules npm-debug.log coverage/ check-error.js check-error-1.0.2/.travis.yml000066400000000000000000000061251273431304200160320ustar00rootroot00000000000000sudo: false language: node_js addons: sauce_connect: true cache: directories: - node_modules node_js: - 0.1 - 4.3 - stable before_install: - npm i -g npm script: - npm t after_success: - 'travis-after-all && npm run semantic-release' env: global: - SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready - LOGS_DIR=/tmp/chai-build/logs - secure: Xrfl4VzQ3C/06kC+KMNMNRxnbJBOamuRnHj+/E8vbQYVNvokvV13Q4P4bMlk+j8ZvR0YUCnM0cUjQPpvEd5W0wHTSj0K1gpUh8EyzH8KI8sOWYX6P4HQQf7N2niqI1zECn0hqi2jsinem3tMtHgB5yTrrwqmob61Nmj2cc+/Am/maR3pF3/Ob9pfBBNZoMPmxWiSLk9lsiMaStFQfODuJU3lrMBlbZivQZ5KEAHYhGPXf9mSrzRO28tX53ZuEZjstoRhNd1hKcO+eUosWcAgSjYGW92n9jGA0ht9bAFnEcHaHRwFGZod5BrfcDBcEYTVHwEBI5z1n+u1enFA25QYw7ORDFg1L4aszw2hGEM0iilM2fv+t086aff+HcFM6ozXYviO05Vuw9oja2Iwu4rblP7xwjFd/LSDUklEeKxXbPAee1HTc1+iZ1LCPO5bgNJqHscrkRb4xL5fq+LBL1oEHBybQcxAkkIjKAEkbrGVahFkNrzySnoHgEgd2XVhPqDq2M8L2lDEfNaNGoN7MrCRbbu8/pLzMGfSXAqWveVx+hksZnryxt4htUZpwuykjm/L6TPppfdzU5A2yH5iusZb7pkgaqe8NJgnGBHq4wagfMxBe8IaAhnPigd6WLu75S68EeoSTXDOMFp6BN4dWv9Ya1oQ+L2e9w8sZQ/2SMw+4gk= - secure: NmCIZ3bBmfg35rD+xY7bbuI9rtVyoZNGvzC5uJW2wzaJlPWURHyLJHJ13QhtXcptLLtseJY6PH6nK+JIjNSoDPK4Wsoxv2Ozp2rq/lFhKDS2umujM6YDPSUlSChdlP1hRio317YzSciXOFtu1WIzKiv0QBtxREnV1V91a5fUyayh9mNM4/VrEFoNQKmYstMJsDuUrE0TPyet4v81ejw5xP2wX3CJuqu/eb5hJezFS2rlhzT8i8RNjb97+lSjNzyR2z3FwLDtrUj8SaWQ07HxJSHRRf41+q7czx0FAQlBF1+EKJ2tf45l/PaHPBCSHSdUoIHoOCSGLEH0JL9H9bxBWwuzM78eywsnVAVVnsokso7t96/2PdKqULWUp9f9eiiWz3vCz5lRqPXVO8If3KemQVtmhVZwssjM43SqloW6HS3PAhSFpypx1Oz25XTpx/u7v641P/Hc+hH++GF/wJ7LR0c417hQrK2dZNG2067WUKM/xyaU3KYPal95LxObqJnhLDsU4zmIpliK0VkaUnYEMFXErE+GPVxcp1FCH6ZO2nnTbd1QKVWg/6unGyOePo3y4fK3ZuygxrEuEwU1RIhruf2+1xlNDMpyTjY65V7g3rpk4OAlfx+5lM3Ws6IXXTkgTMTNFjqDR/53Nv3dJgFYfmXV/SQ1A4vk1I4XufN3s+s= - secure: tjY+Qd/Z/C/n2qkvYg05utkZgtn/o4AcjmP/Pco5ZsuR2/PP7rs0Jz+fnF1YixNVkatAub52/rQ0LyIqTkEqcOq9fjfzRwwDMwW/Cb0lakdZTqYoIp0E5WCNIlQi6uBfk1tPxG9x4edqLHE+GWjNrxdiWTPNEe6jfObRpPa6uV/ewTzYomvtwqPZkoDfAG3zXP87APK43CFtFNwmHc+Apf6D6dfPy+0vgwLYpRmPeB8RsabpV0sWAzy2A0RK+UGIrO6Bx8Yupi4Si6lGuW6Lk5r8TtdGk3gnt9C8zMS+w8UvCQ7gOBKkyQI9bI3t3pAFcEWsL7mbQq2axEdhJJdKS20190ps6ImTxyc1kOPnt5JcAXN72etx7cDhMDw3FtHtBboGydRd0lBpuAgq8gKl9X/CiPfghv1hea8HB2YADEvFmvX5dZ/XxBNg6aI8yhnn7hNM+9gXtVrW0C1D43TbQXE7TqNLCvRlQkamQJH+32rqu6dAPoBtwZF2kZLSfJR+xAr9HJjEtXW9nD3OTfjlQpvJZNwM5yLEw9mob1ukTPadBW3irTYDAyBke0aT66gX4a80EOcptPZExDBz9DFGWoW48wf+VZvrFwaOcNXNp3244epaZUZ68wC4/kWH/21ky8m09+IGI284q3QfGea1drjwZFB/EX1zvY2LXOwB8go= - secure: V7dv1sEDKU9RPAgaJjk7E2PUarMSzf18GVNGmS6LrNZ5HH88Lv8XEpJj2fnvmJNFgqxnjDiXlQC/EfzbsrR+hI+i2gDv3Yti3Uqs02fkfWuZ+g9YEfuGBEW2Iv+L2+klG4OQsKa32HQZvvJWSrPB+DjK5QsAoVkaiovgMzsUXY67IXJ9/OORy+M8dIHjkEL1pq27eD/R9cKK8fxC1Ld7GsJHyNlbj7CN+vuYnPe7WsFwdoI9X5PD4Qrq2w3nzNa13Fp04dD9chjScUHPeoIYl0P0SRm4ySuw5lrvONQ2EHVXjuNdHUeoByebAPcFPbO7XhMSdmsJFF17ejLuRKNPvzLVeLa2LwzQl+e6OizRQe2oxHDtU6MQZP58pq4G50GO9jAjIsEtraY19DX+gMx3YJSt7rB8B0AwrH2efLEJDU8D5lcRpj56e8VZr4PSWpdk8pVMOg6Qi6Qn/PyBJ4U2JkSSME/bResQlZSl3+jdj1Tk1mWHWUHltyU5xoDZ1cOyRfymOlgy9g3dB5xmf773cKQbMqUderZBO/SXhuzMkm6l6pfBFTPBLKlE+SNFa6K+k9cpKRlxhVHcxIy7i6DsOkxIW36Kg/kmMsGIrsGTTt7RvdHt8N7OuG8AP4+EkBEkyObpvY6V27D6QeFNyrASYkVH7V0q4+uJXX6ISkd4E7s= check-error-1.0.2/LICENSE000066400000000000000000000021251273431304200147220ustar00rootroot00000000000000Copyright (c) 2013 Jake Luer (http://alogicalparadox.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. check-error-1.0.2/MAINTAINERS000066400000000000000000000000501273431304200154050ustar00rootroot00000000000000keithamus davelosert lucasfcosta meeber check-error-1.0.2/README.md000066400000000000000000000134411273431304200151770ustar00rootroot00000000000000

ChaiJS check-error

Error comparison and information related utility for node and the browser.

license:mit tag:? build:? coverage:? npm:? dependencies:? devDependencies:?
Selenium Test Status
Join the Slack chat Join the Gitter chat

## What is Check-Error? Check-Error is a module which you can use to retrieve an Error's information such as its `message` or `constructor` name and also to check whether two Errors are compatible based on their messages, constructors or even instances. ## Installation ### Node.js `check-error` is available on [npm](http://npmjs.org). To install it, type: $ npm install check-error ### Browsers You can also use it within the browser; install via npm and use the `check-error.js` file found within the download. For example: ```html ``` ## Usage The primary export of `check-error` is an object which has the following methods: * `compatibleInstance(err, errorLike)` - Checks if an error is compatible with another `errorLike` object. If `errorLike` is an error instance we do a strict comparison, otherwise we return `false` by default, because instances of objects can only be compatible if they're both error instances. * `compatibleConstructor(err, errorLike)` - Checks if an error's constructor is compatible with another `errorLike` object. If `err` has the same constructor as `errorLike` or if `err` is an instance of `errorLike`. * `compatibleMessage(err, errMatcher)` - Checks if an error message is compatible with an `errMatcher` RegExp or String (we check if the message contains the String). * `getConstructorName(errorLike)` - Retrieves the name of a constructor, an error's constructor or `errorLike` itself if it's not an error instance or constructor. * `getMessage(err)` - Retrieves the message of an error or `err` itself if it's a String. If `err` or `err.message` is undefined we return an empty String. ```js var checkError = require('check-error'); ``` #### .compatibleInstance(err, errorLike) ```js var checkError = require('check-error'); var funcThatThrows = function() { throw new TypeError('I am a TypeError') }; var caughtErr; try { funcThatThrows(); } catch(e) { caughtErr = e; } var sameInstance = caughtErr; checkError.compatibleInstance(caughtErr, sameInstance); // true checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false ``` #### .compatibleConstructor(err, errorLike) ```js var checkError = require('check-error'); var funcThatThrows = function() { throw new TypeError('I am a TypeError') }; var caughtErr; try { funcThatThrows(); } catch(e) { caughtErr = e; } checkError.compatibleConstructor(caughtErr, Error); // true checkError.compatibleConstructor(caughtErr, TypeError); // true checkError.compatibleConstructor(caughtErr, RangeError); // false ``` #### .compatibleMessage(err, errMatcher) ```js var checkError = require('check-error'); var funcThatThrows = function() { throw new TypeError('I am a TypeError') }; var caughtErr; try { funcThatThrows(); } catch(e) { caughtErr = e; } var sameInstance = caughtErr; checkError.compatibleMessage(caughtErr, /TypeError$/); // true checkError.compatibleMessage(caughtErr, 'I am a'); // true checkError.compatibleMessage(caughtErr, /unicorn/); // false checkError.compatibleMessage(caughtErr, 'I do not exist'); // false ``` #### .getConstructorName(errorLike) ```js var checkError = require('check-error'); var funcThatThrows = function() { throw new TypeError('I am a TypeError') }; var caughtErr; try { funcThatThrows(); } catch(e) { caughtErr = e; } var sameInstance = caughtErr; checkError.getConstructorName(caughtErr) // 'TypeError' ``` #### .getMessage(err) ```js var checkError = require('check-error'); var funcThatThrows = function() { throw new TypeError('I am a TypeError') }; var caughtErr; try { funcThatThrows(); } catch(e) { caughtErr = e; } var sameInstance = caughtErr; checkError.getMessage(caughtErr) // 'I am a TypeError' ``` check-error-1.0.2/index.js000066400000000000000000000115511273431304200153650ustar00rootroot00000000000000'use strict'; /* ! * Chai - checkError utility * Copyright(c) 2012-2016 Jake Luer * MIT Licensed */ /** * ### .checkError * * Checks that an error conforms to a given set of criteria and/or retrieves information about it. * * @api public */ /** * ### .compatibleInstance(thrown, errorLike) * * Checks if two instances are compatible (strict equal). * Returns false if errorLike is not an instance of Error, because instances * can only be compatible if they're both error instances. * * @name compatibleInstance * @param {Error} thrown error * @param {Error|ErrorConstructor} errorLike object to compare against * @namespace Utils * @api public */ function compatibleInstance(thrown, errorLike) { return errorLike instanceof Error && thrown === errorLike; } /** * ### .compatibleConstructor(thrown, errorLike) * * Checks if two constructors are compatible. * This function can receive either an error constructor or * an error instance as the `errorLike` argument. * Constructors are compatible if they're the same or if one is * an instance of another. * * @name compatibleConstructor * @param {Error} thrown error * @param {Error|ErrorConstructor} errorLike object to compare against * @namespace Utils * @api public */ function compatibleConstructor(thrown, errorLike) { if (errorLike instanceof Error) { // If `errorLike` is an instance of any error we compare their constructors return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor; } else if (errorLike.prototype instanceof Error || errorLike === Error) { // If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly return thrown.constructor === errorLike || thrown instanceof errorLike; } return false; } /** * ### .compatibleMessage(thrown, errMatcher) * * Checks if an error's message is compatible with a matcher (String or RegExp). * If the message contains the String or passes the RegExp test, * it is considered compatible. * * @name compatibleMessage * @param {Error} thrown error * @param {String|RegExp} errMatcher to look for into the message * @namespace Utils * @api public */ function compatibleMessage(thrown, errMatcher) { var comparisonString = typeof thrown === 'string' ? thrown : thrown.message; if (errMatcher instanceof RegExp) { return errMatcher.test(comparisonString); } else if (typeof errMatcher === 'string') { return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers } return false; } /** * ### .getFunctionName(constructorFn) * * Returns the name of a function. * This also includes a polyfill function if `constructorFn.name` is not defined. * * @name getFunctionName * @param {Function} constructorFn * @namespace Utils * @api private */ var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/; function getFunctionName(constructorFn) { var name = ''; if (typeof constructorFn.name === 'undefined') { // Here we run a polyfill if constructorFn.name is not defined var match = String(constructorFn).match(functionNameMatch); if (match) { name = match[1]; } } else { name = constructorFn.name; } return name; } /** * ### .getConstructorName(errorLike) * * Gets the constructor name for an Error instance or constructor itself. * * @name getConstructorName * @param {Error|ErrorConstructor} errorLike * @namespace Utils * @api public */ function getConstructorName(errorLike) { var constructorName = errorLike; if (errorLike instanceof Error) { constructorName = getFunctionName(errorLike.constructor); } else if (typeof errorLike === 'function') { // If `err` is not an instance of Error it is an error constructor itself or another function. // If we've got a common function we get its name, otherwise we may need to create a new instance // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more. constructorName = getFunctionName(errorLike).trim() || getFunctionName(new errorLike()); // eslint-disable-line new-cap } return constructorName; } /** * ### .getMessage(errorLike) * * Gets the error message from an error. * If `err` is a String itself, we return it. * If the error has no message, we return an empty string. * * @name getMessage * @param {Error|String} errorLike * @namespace Utils * @api public */ function getMessage(errorLike) { var msg = ''; if (errorLike && errorLike.message) { msg = errorLike.message; } else if (typeof errorLike === 'string') { msg = errorLike; } return msg; } module.exports = { compatibleInstance: compatibleInstance, compatibleConstructor: compatibleConstructor, compatibleMessage: compatibleMessage, getMessage: getMessage, getConstructorName: getConstructorName, }; check-error-1.0.2/karma.conf.js000066400000000000000000000050701273431304200162740ustar00rootroot00000000000000'use strict'; var packageJson = require('./package.json'); var defaultTimeout = 120000; var browserifyIstanbul = require('browserify-istanbul'); module.exports = function configureKarma(config) { var localBrowsers = [ 'PhantomJS', ]; var sauceLabsBrowsers = { SauceChromeLatest: { base: 'SauceLabs', browserName: 'Chrome', }, SauceFirefoxLatest: { base: 'SauceLabs', browserName: 'Firefox', }, SauceSafariLatest: { base: 'SauceLabs', browserName: 'Safari', platform: 'OS X 10.11', }, SauceInternetExplorerLatest: { base: 'SauceLabs', browserName: 'Internet Explorer', }, SauceInternetExplorerOldestSupported: { base: 'SauceLabs', browserName: 'Internet Explorer', version: 9, }, SauceEdgeLatest: { base: 'SauceLabs', browserName: 'MicrosoftEdge', }, SauceAndroidLatest: { base: 'SauceLabs', browserName: 'Android', }, }; config.set({ basePath: '', browsers: localBrowsers, logLevel: process.env.npm_config_debug ? config.LOG_DEBUG : config.LOG_INFO, frameworks: [ 'browserify', 'mocha' ], files: [ 'test/*.js' ], exclude: [], preprocessors: { 'test/*.js': [ 'browserify' ], }, browserify: { debug: true, bare: true, transform: [ browserifyIstanbul({ ignore: [ '**/node_modules/**', '**/test/**' ] }), ], }, reporters: [ 'progress', 'coverage' ], coverageReporter: { type: 'lcov', dir: 'coverage', }, port: 9876, colors: true, concurrency: 3, autoWatch: false, captureTimeout: defaultTimeout, browserDisconnectTimeout: defaultTimeout, browserNoActivityTimeout: defaultTimeout, singleRun: true, }); if (process.env.SAUCE_ACCESS_KEY && process.env.SAUCE_USERNAME) { var branch = process.env.TRAVIS_BRANCH || 'local'; var build = 'localbuild'; if (process.env.TRAVIS_JOB_NUMBER) { build = 'travis@' + process.env.TRAVIS_JOB_NUMBER; } config.reporters.push('saucelabs'); config.set({ customLaunchers: sauceLabsBrowsers, browsers: localBrowsers.concat(Object.keys(sauceLabsBrowsers)), sauceLabs: { testName: packageJson.name, tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER || new Date().getTime(), recordVideo: true, startConnect: ('TRAVIS' in process.env) === false, tags: [ 'checkError_' + packageJson.version, process.env.SAUCE_USERNAME + '@' + branch, build, ], }, }); } }; check-error-1.0.2/package.json000066400000000000000000000045051273431304200162070ustar00rootroot00000000000000{ "name": "check-error", "description": "Error comparison and information related utility for node and the browser", "keywords": [ "check-error", "error", "chai util" ], "license": "MIT", "author": "Jake Luer (http://alogicalparadox.com)", "contributors": [ "David Losert (https://github.com/davelosert)", "Keith Cirkel (https://github.com/keithamus)", "Miroslav Bajtoš (https://github.com/bajtos)", "Lucas Fernandes da Costa (https://github.com/lucasfcosta)" ], "files": [ "index.js", "check-error.js" ], "main": "./index.js", "repository": { "type": "git", "url": "git+ssh://git@github.com/chaijs/check-error.git" }, "scripts": { "build": "browserify --bare $npm_package_main --standalone checkError -o check-error.js", "lint": "eslint --ignore-path .gitignore .", "prepublish": "npm run build", "semantic-release": "semantic-release pre && npm publish && semantic-release post", "pretest": "npm run lint", "test": "npm run test:node && npm run test:browser && npm run upload-coverage", "test:browser": "karma start --singleRun=true", "test:node": "istanbul cover _mocha", "upload-coverage": "lcov-result-merger 'coverage/**/lcov.info' | coveralls; exit 0" }, "config": { "ghooks": { "commit-msg": "validate-commit-msg" } }, "eslintConfig": { "extends": [ "strict/es5" ], "env": { "es6": true }, "globals": { "HTMLElement": false }, "rules": { "complexity": 0, "max-statements": 0 } }, "dependencies": {}, "devDependencies": { "browserify": "^13.0.0", "browserify-istanbul": "^1.0.0", "coveralls": "2.11.9", "eslint": "^2.4.0", "eslint-config-strict": "^8.5.0", "eslint-plugin-filenames": "^0.2.0", "ghooks": "^1.0.1", "istanbul": "^0.4.2", "karma": "^0.13.22", "karma-browserify": "^5.0.2", "karma-coverage": "^0.5.5", "karma-mocha": "^0.2.2", "karma-phantomjs-launcher": "^1.0.0", "karma-sauce-launcher": "^0.3.1", "lcov-result-merger": "^1.0.2", "mocha": "^2.4.5", "phantomjs-prebuilt": "^2.1.5", "semantic-release": "^4.3.5", "simple-assert": "^1.0.0", "travis-after-all": "^1.4.4", "validate-commit-msg": "^2.3.1" }, "engines": { "node": "*" } } check-error-1.0.2/test/000077500000000000000000000000001273431304200146745ustar00rootroot00000000000000check-error-1.0.2/test/.eslintrc000066400000000000000000000005231273431304200165200ustar00rootroot00000000000000{ "extends": [ "strict/test" ], "env": { "node": true, "browser": true, "es6": true, "mocha": true }, "rules": { "no-new-wrappers": 0, "no-array-constructor": 0, "no-new-object": 0, "no-empty-function": 0, "no-undefined": 0, "complexity": 0, "max-statements": 0, "id-match": 0 } } check-error-1.0.2/test/index.js000066400000000000000000000134631273431304200163500ustar00rootroot00000000000000'use strict'; var assert = require('simple-assert'); var checkError = require('..'); describe('checkError', function () { it('compatibleInstance', function () { var errorInstance = new Error('I am an instance'); var sameInstance = errorInstance; var otherInstance = new Error('I an another instance'); var aNumber = 1337; assert(checkError.compatibleInstance(errorInstance, sameInstance) === true); assert(checkError.compatibleInstance(errorInstance, otherInstance) === false); assert(checkError.compatibleInstance(errorInstance, Error) === false); assert(checkError.compatibleInstance(errorInstance, aNumber) === false); }); it('compatibleConstructor', function () { var errorInstance = new Error('I am an instance'); var sameInstance = errorInstance; var otherInstance = new Error('I an another instance'); var derivedInstance = new TypeError('I inherit from Error'); var anObject = {}; var aNumber = 1337; assert(checkError.compatibleConstructor(errorInstance, sameInstance) === true); assert(checkError.compatibleConstructor(errorInstance, otherInstance) === true); assert(checkError.compatibleConstructor(derivedInstance, errorInstance) === true); assert(checkError.compatibleConstructor(errorInstance, derivedInstance) === false); assert(checkError.compatibleConstructor(errorInstance, Error) === true); assert(checkError.compatibleConstructor(derivedInstance, TypeError) === true); assert(checkError.compatibleConstructor(errorInstance, TypeError) === false); assert(checkError.compatibleConstructor(errorInstance, anObject) === false); assert(checkError.compatibleConstructor(errorInstance, aNumber) === false); }); it('compatibleMessage', function () { var errorInstance = new Error('I am an instance'); var derivedInstance = new TypeError('I inherit from Error'); var thrownMessage = 'Imagine I have been thrown'; assert(checkError.compatibleMessage(errorInstance, /instance$/) === true); assert(checkError.compatibleMessage(derivedInstance, /Error$/) === true); assert(checkError.compatibleMessage(errorInstance, /unicorn$/) === false); assert(checkError.compatibleMessage(derivedInstance, /dinosaur$/) === false); assert(checkError.compatibleMessage(errorInstance, 'instance') === true); assert(checkError.compatibleMessage(derivedInstance, 'Error') === true); assert(checkError.compatibleMessage(errorInstance, 'unicorn') === false); assert(checkError.compatibleMessage(derivedInstance, 'dinosaur') === false); assert(checkError.compatibleMessage(thrownMessage, /thrown$/) === true); assert(checkError.compatibleMessage(thrownMessage, /^Imagine/) === true); assert(checkError.compatibleMessage(thrownMessage, /unicorn$/) === false); assert(checkError.compatibleMessage(thrownMessage, /dinosaur$/) === false); assert(checkError.compatibleMessage(thrownMessage, 'Imagine') === true); assert(checkError.compatibleMessage(thrownMessage, 'thrown') === true); assert(checkError.compatibleMessage(thrownMessage, 'unicorn') === false); assert(checkError.compatibleMessage(thrownMessage, 'dinosaur') === false); assert(checkError.compatibleMessage(thrownMessage, undefined) === false); assert(checkError.compatibleMessage(thrownMessage, null) === false); }); it('constructorName', function () { var errorInstance = new Error('I am an instance'); var derivedInstance = new TypeError('I inherit from Error'); var thrownMessage = 'Imagine I have been thrown'; assert(checkError.getConstructorName(errorInstance) === 'Error'); assert(checkError.getConstructorName(derivedInstance) === 'TypeError'); assert(checkError.getConstructorName(thrownMessage) === 'Imagine I have been thrown'); assert(checkError.getConstructorName(Error) === 'Error'); assert(checkError.getConstructorName(TypeError) === 'TypeError'); assert(checkError.getConstructorName(null) === null); assert(checkError.getConstructorName(undefined) === undefined); // Asserting that `getFunctionName` behaves correctly function /*one*/correctName/*two*/() { // eslint-disable-line no-inline-comments, spaced-comment return 0; } function withoutComments() { return 1; } var anonymousFunc = function () { // eslint-disable-line func-style return 2; }; // See chaijs/chai/issues/45: some poorly-constructed custom errors don't have useful names // on either their constructor or their constructor prototype, but instead // only set the name inside the constructor itself. var PoorlyConstructedError = function () { // eslint-disable-line func-style this.name = 'PoorlyConstructedError'; // eslint-disable-line no-invalid-this }; PoorlyConstructedError.prototype = Object.create(Error.prototype); assert(checkError.getConstructorName(correctName) === 'correctName'); assert(checkError.getConstructorName(withoutComments) === 'withoutComments'); assert(checkError.getConstructorName(anonymousFunc) === ''); assert(checkError.getConstructorName(PoorlyConstructedError) === 'PoorlyConstructedError'); }); it('getMessage', function () { var errorInstance = new Error('I am an instance'); var derivedInstance = new TypeError('I inherit from Error'); var thrownMessage = 'Imagine I have been thrown'; var errorExpMsg = errorInstance.message; var derivedExpMsg = derivedInstance.message; assert(checkError.getMessage(errorInstance) === errorExpMsg); assert(checkError.getMessage(derivedInstance) === derivedExpMsg); assert(checkError.getMessage(thrownMessage) === 'Imagine I have been thrown'); assert(checkError.getMessage(Error) === ''); assert(checkError.getMessage(TypeError) === ''); assert(checkError.getMessage(null) === ''); assert(checkError.getMessage(undefined) === ''); }); });