Created
May 10, 2016 21:18
-
-
Save DingoEatingFuzz/52bf5a580df69fb6c2d84e828e8c13fa to your computer and use it in GitHub Desktop.
Chai formatArray when Array.prototype has been modified.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const expect = require('chai').expect; | |
Array.prototype.doubleAll = function() { | |
return this.map(a => a * 2); | |
}; | |
describe("Arrays", function() { | |
describe("doubleAll method", function() { | |
it("should exist on all arrays", function() { | |
expect([].doubleAll).to.be.instanceof(Function); | |
expect(new Array().doubleAll).to.be.instanceof(Function); | |
}); | |
it("should double all values in the array", function() { | |
// intentionally broken | |
expect([ 1, 2, 3, 4 ].doubleAll()).to.eql([ 2, 4, 6, 9 ]); | |
}); | |
}); | |
}); | |
/* Test Output | |
$ mocha test.js -R tap | |
1..2 | |
ok 1 Arrays doubleAll method should exist on all arrays | |
not ok 2 Arrays doubleAll method should double all values in the array | |
AssertionError: expected [ 2, 4, 6, 8, doubleAll: [Function] ] to deeply equal [ 2, 4, 6, 9, doubleAll: [Function] ] | |
at Context.<anonymous> (/Users/michaellange/work/chai-inspect-test/test.js:16:42) | |
at callFn (/usr/local/lib/node_modules/mocha/lib/runnable.js:266:21) | |
at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:259:7) | |
at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:387:10) | |
at /usr/local/lib/node_modules/mocha/lib/runner.js:470:12 | |
at next (/usr/local/lib/node_modules/mocha/lib/runner.js:312:14) | |
at /usr/local/lib/node_modules/mocha/lib/runner.js:322:7 | |
at next (/usr/local/lib/node_modules/mocha/lib/runner.js:257:23) | |
at Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:289:5) | |
at processImmediate [as _immediateCallback] (timers.js:383:17) | |
# tests 2 | |
# pass 1 | |
# fail 1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment