Skip to content

Commit

Permalink
feat: support "Strict mode"
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed Mar 27, 2018
1 parent c4e49c5 commit 9f86bc6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -43,6 +43,12 @@ function customize (customOptions) {
extend(empowerOptions, options.assertion)
);
poweredAssert.customize = customize;
poweredAssert.strict = extend(poweredAssert, {
equal: poweredAssert.strictEqual,
deepEqual: poweredAssert.deepStrictEqual,
notEqual: poweredAssert.notStrictEqual,
notDeepEqual: poweredAssert.notDeepStrictEqual
});
return poweredAssert;
}

Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Expand Up @@ -12,6 +12,7 @@ module.exports = function (config) {
{ pattern: 'espowered_tests/tobe_instrumented/assertion.js', watched: true, served: true, included: true },
{ pattern: 'espowered_tests/tobe_instrumented/assertion.es6.js', watched: true, served: true, included: true },
{ pattern: 'espowered_tests/tobe_instrumented/customization.js', watched: true, served: true, included: true },
{ pattern: 'espowered_tests/tobe_instrumented/strict_mode.js', watched: true, served: true, included: true },
{ pattern: 'espowered_tests/not_tobe_instrumented/not_instrumented.js', watched: true, served: true, included: true },
{ pattern: 'espowered_tests/tobe_instrumented/modules.js', watched: true, served: true, included: true }
],
Expand Down
52 changes: 52 additions & 0 deletions test/tobe_instrumented/strict_mode.js
@@ -0,0 +1,52 @@
if (typeof window === 'undefined') {
var expect = require('expect.js');
var assert = require('../..');
}

describe('strict mode support', function () {

var legacyModeAssert = assert;

beforeEach(function () {
assert = assert.strict;
});
afterEach(function () {
assert = legacyModeAssert;
});

function expectPowerAssertMessage (body, expectedLines) {
try {
body();
expect().fail("AssertionError should be thrown");
} catch (e) {
if (e.message === 'AssertionError should be thrown') {
throw e;
}
expect(e.message.split('\n').slice(2, -1)).to.eql(expectedLines);
}
};

it('equal becomes strictEqual', function () {
var three = 3, threeInStr = '3';
expectPowerAssertMessage(function () {
assert.equal(three, threeInStr);
},[
' assert.equal(three, threeInStr)',
' | | ',
' 3 "3" '
]);
});

it('deepEqual becomes deepStrictEqual', function () {
var three = 3, threeInStr = '3';
expectPowerAssertMessage(function () {
assert.deepEqual({a: three}, {a: threeInStr});
},[
' assert.deepEqual({ a: three }, { a: threeInStr })',
' | | | | ',
' | | | "3" ',
' | 3 Object{a:"3"} ',
' Object{a:3} '
]);
});
});

0 comments on commit 9f86bc6

Please sign in to comment.