@@ -465,27 +465,28 @@ describe('Filter: filter', function() {
465
465
466
466
describe ( 'should support comparator' , function ( ) {
467
467
468
- it ( 'not consider `object === "[object Object]" ` in non-strict comparison' , function ( ) {
468
+ it ( 'not consider objects without a custom `toString ` in non-strict comparison' , function ( ) {
469
469
var items = [ { test : { } } ] ;
470
470
var expr = '[object' ;
471
471
expect ( filter ( items , expr ) . length ) . toBe ( 0 ) ;
472
472
} ) ;
473
473
474
474
475
- it ( 'should consider custom `toString()` in non-strict comparison' , function ( ) {
475
+ it ( 'should consider objects with custom `toString()` in non-strict comparison' , function ( ) {
476
476
var obj = new Date ( 1970 , 0 ) ;
477
477
var items = [ { test : obj } ] ;
478
478
expect ( filter ( items , '1970' ) . length ) . toBe ( 1 ) ;
479
479
expect ( filter ( items , 1970 ) . length ) . toBe ( 1 ) ;
480
480
481
- obj = { } ;
482
- obj . toString = function ( ) { return 'custom' ; } ;
481
+ obj = {
482
+ toString : function ( ) { return 'custom' ; }
483
+ } ;
483
484
items = [ { test : obj } ] ;
484
485
expect ( filter ( items , 'custom' ) . length ) . toBe ( 1 ) ;
485
486
} ) ;
486
487
487
488
488
- it ( 'should not throw on missing `toString()` in non-strict comparison' , function ( ) {
489
+ it ( 'should cope with objects that have no `toString()` in non-strict comparison' , function ( ) {
489
490
var obj = Object . create ( null ) ;
490
491
var items = [ { test : obj } ] ;
491
492
expect ( function ( ) {
@@ -495,6 +496,18 @@ describe('Filter: filter', function() {
495
496
} ) ;
496
497
497
498
499
+ it ( 'should cope with objects where `toString` is not a function in non-strict comparison' , function ( ) {
500
+ var obj = {
501
+ toString : 'moo'
502
+ } ;
503
+ var items = [ { test : obj } ] ;
504
+ expect ( function ( ) {
505
+ filter ( items , 'foo' ) ;
506
+ } ) . not . toThrow ( ) ;
507
+ expect ( filter ( items , 'foo' ) . length ) . toBe ( 0 ) ;
508
+ } ) ;
509
+
510
+
498
511
it ( 'as equality when true' , function ( ) {
499
512
var items = [ 'misko' , 'adam' , 'adamson' ] ;
500
513
var expr = 'adam' ;
0 commit comments