@@ -465,27 +465,28 @@ describe('Filter: filter', function() {
465465
466466 describe ( 'should support comparator' , function ( ) {
467467
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 ( ) {
469469 var items = [ { test : { } } ] ;
470470 var expr = '[object' ;
471471 expect ( filter ( items , expr ) . length ) . toBe ( 0 ) ;
472472 } ) ;
473473
474474
475- it ( 'should consider custom `toString()` in non-strict comparison' , function ( ) {
475+ it ( 'should consider objects with custom `toString()` in non-strict comparison' , function ( ) {
476476 var obj = new Date ( 1970 , 0 ) ;
477477 var items = [ { test : obj } ] ;
478478 expect ( filter ( items , '1970' ) . length ) . toBe ( 1 ) ;
479479 expect ( filter ( items , 1970 ) . length ) . toBe ( 1 ) ;
480480
481- obj = { } ;
482- obj . toString = function ( ) { return 'custom' ; } ;
481+ obj = {
482+ toString : function ( ) { return 'custom' ; }
483+ } ;
483484 items = [ { test : obj } ] ;
484485 expect ( filter ( items , 'custom' ) . length ) . toBe ( 1 ) ;
485486 } ) ;
486487
487488
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 ( ) {
489490 var obj = Object . create ( null ) ;
490491 var items = [ { test : obj } ] ;
491492 expect ( function ( ) {
@@ -495,6 +496,18 @@ describe('Filter: filter', function() {
495496 } ) ;
496497
497498
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+
498511 it ( 'as equality when true' , function ( ) {
499512 var items = [ 'misko' , 'adam' , 'adamson' ] ;
500513 var expr = 'adam' ;
0 commit comments