Skip to content

Commit e87e9e4

Browse files
committed
#122 updated test suite to use version 3.5.0
1 parent d3d2252 commit e87e9e4

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

js/tests/assert.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,22 @@ describe('assert', function () {
855855
}, 'expected [ { b: 3 } ] to have the same members as [ { b: 5 } ]');
856856
});
857857

858+
it('includeDeepMembers', function() {
859+
assert.includeDeepMembers([{a:1}, {b:2}, {c:3}], [{c:3}, {b:2}]);
860+
assert.includeDeepMembers([{a:1}, {b:2}, {c:3}], []);
861+
assert.includeDeepMembers([{a:1}, {b:2}, {c:3}], [{c:3}]);
862+
assert.includeDeepMembers([{a:1}, {b:2}, {c:3}, {c:3}], [{c:3}, {c:3}]);
863+
assert.includeDeepMembers([{a:1}, {b:2}, {c:3}], [{c:3}, {c:3}]);
864+
865+
err(function() {
866+
assert.includeDeepMembers([{e:5}, {f:6}], [{g:7}, {h:8}]);
867+
}, 'expected [ { e: 5 }, { f: 6 } ] to be a superset of [ { g: 7 }, { h: 8 } ]');
868+
869+
err(function() {
870+
assert.includeDeepMembers([{e:5}, {f:6}], [{e:5}, {f:6}, {z:0}]);
871+
}, 'expected [ { e: 5 }, { f: 6 } ] to be a superset of [ { e: 5 }, { f: 6 }, { z: 0 } ]');
872+
});
873+
858874
it('change', function() {
859875
var obj = { value: 10, str: 'foo' },
860876
fn = function() { obj.value += 5 },

js/tests/configuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,6 @@ describe('configuration', function () {
165165
chai.config.showDiff = !chai.config.showDiff;
166166
assert.equal(chai.Assertion.showDiff, chai.config.showDiff);
167167
});
168-
168+
169169
});
170170
});

js/tests/expect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ describe('expect', function () {
492492
err(function(){
493493
expect(deepObj).to.have.deep.property('teas[3].tea', 'bar');
494494
}, "expected { Object (green, teas) } to have a deep property 'teas[3].tea'");
495-
495+
496496
var arr = [
497497
[ 'chai', 'matcha', 'konacha' ]
498498
, [ { tea: 'chai' }

js/tests/utilities.js

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('utilities', function () {
109109
info.value.should.equal(obj.dimensions.units);
110110
info.name.should.equal('units');
111111
info.exists.should.be.true;
112-
});
112+
});
113113

114114
it('should handle non-existent property', function() {
115115
var info = gpi('dimensions.size', obj);
@@ -118,7 +118,7 @@ describe('utilities', function () {
118118
expect(info.value).to.be.undefined;
119119
info.name.should.equal('size');
120120
info.exists.should.be.false;
121-
});
121+
});
122122

123123
it('should handle array index', function() {
124124
var info = gpi('primes[2]', obj);
@@ -127,7 +127,7 @@ describe('utilities', function () {
127127
info.value.should.equal(obj.primes[2]);
128128
info.name.should.equal(2);
129129
info.exists.should.be.true;
130-
});
130+
});
131131

132132
it('should handle dimensional array', function() {
133133
var info = gpi('dimensions.lengths[2][1]', obj);
@@ -136,7 +136,7 @@ describe('utilities', function () {
136136
info.value.should.equal(obj.dimensions.lengths[2][1]);
137137
info.name.should.equal(1);
138138
info.exists.should.be.true;
139-
});
139+
});
140140

141141
it('should handle out of bounds array index', function() {
142142
var info = gpi('dimensions.lengths[3]', obj);
@@ -180,13 +180,13 @@ describe('utilities', function () {
180180
hp(1, arr).should.be.true;
181181
hp(3, arr).should.be.false;
182182
});
183-
183+
184184
it('should handle literal types', function() {
185185
var s = 'string literal';
186186
hp('length', s).should.be.true;
187187
hp(3, s).should.be.true;
188188
hp(14, s).should.be.false;
189-
189+
190190
hp('foo', 1).should.be.false;
191191
});
192192

@@ -342,7 +342,11 @@ describe('utilities', function () {
342342
var obj = {};
343343
_.flag(obj, 'message', 'foo');
344344
expect(_.getMessage(obj, [])).to.contain('foo');
345+
});
346+
});
345347

348+
it('getMessage passed message as function', function () {
349+
chai.use(function (_chai, _) {
346350
var obj = {};
347351
var msg = function() { return "expected a to eql b"; }
348352
var negateMsg = function() { return "expected a not to eql b"; }
@@ -352,6 +356,67 @@ describe('utilities', function () {
352356
});
353357
});
354358

359+
it('getMessage template tag substitution', function () {
360+
chai.use(function (_chai, _) {
361+
var objName = 'trojan horse';
362+
var actualValue = 'an actual value';
363+
var expectedValue = 'an expected value';
364+
[
365+
// known template tags
366+
{
367+
template: 'one #{this} two',
368+
expected: 'one \'' + objName + '\' two'
369+
},
370+
{
371+
template: 'one #{act} two',
372+
expected: 'one \'' + actualValue + '\' two'
373+
},
374+
{
375+
template: 'one #{exp} two',
376+
expected: 'one \'' + expectedValue + '\' two'
377+
},
378+
// unknown template tag
379+
{
380+
template: 'one #{unknown} two',
381+
expected: 'one #{unknown} two'
382+
},
383+
// repeated template tag
384+
{
385+
template: '#{this}#{this}',
386+
expected: '\'' + objName + '\'\'' + objName + '\''
387+
},
388+
// multiple template tags in different order
389+
{
390+
template: '#{this}#{act}#{exp}#{act}#{this}',
391+
expected: '\'' + objName + '\'\'' + actualValue + '\'\'' + expectedValue + '\'\'' + actualValue + '\'\'' + objName + '\''
392+
},
393+
// immune to string.prototype.replace() `$` substitution
394+
{
395+
objName: '-$$-',
396+
template: '#{this}',
397+
expected: '\'-$$-\''
398+
},
399+
{
400+
actualValue: '-$$-',
401+
template: '#{act}',
402+
expected: '\'-$$-\''
403+
},
404+
{
405+
expectedValue: '-$$-',
406+
template: '#{exp}',
407+
expected: '\'-$$-\''
408+
}
409+
].forEach(function (config) {
410+
config.objName = config.objName || objName;
411+
config.actualValue = config.actualValue || actualValue;
412+
config.expectedValue = config.expectedValue || expectedValue;
413+
var obj = {_obj: config.actualValue};
414+
_.flag(obj, 'object', config.objName);
415+
expect(_.getMessage(obj, [null, config.template, null, config.expectedValue])).to.equal(config.expected);
416+
});
417+
});
418+
});
419+
355420
it('inspect with custom object-returning inspect()s', function () {
356421
chai.use(function (_chai, _) {
357422
var obj = {

0 commit comments

Comments
 (0)