@@ -342,7 +342,11 @@ describe('utilities', function () {
342
342
var obj = { } ;
343
343
_ . flag ( obj , 'message' , 'foo' ) ;
344
344
expect ( _ . getMessage ( obj , [ ] ) ) . to . contain ( 'foo' ) ;
345
+ } ) ;
346
+ } ) ;
345
347
348
+ it ( 'getMessage passed message as function' , function ( ) {
349
+ chai . use ( function ( _chai , _ ) {
346
350
var obj = { } ;
347
351
var msg = function ( ) { return "expected a to eql b" ; }
348
352
var negateMsg = function ( ) { return "expected a not to eql b" ; }
@@ -352,6 +356,67 @@ describe('utilities', function () {
352
356
} ) ;
353
357
} ) ;
354
358
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
+
355
420
it ( 'inspect with custom object-returning inspect()s' , function ( ) {
356
421
chai . use ( function ( _chai , _ ) {
357
422
var obj = {
0 commit comments