@@ -91,6 +91,21 @@ describe('findKey', function () {
91
91
expect ( ret ) . to . equal ( 1 )
92
92
done ( )
93
93
} )
94
+ it ( 'should break loop if item is found (weird array)' , function ( done ) {
95
+ var obj = [
96
+ 'foo' ,
97
+ 'bar' ,
98
+ 'baz'
99
+ ]
100
+ obj [ 'wut' ] = 'hello'
101
+ var callback = sinon . spy ( equals ( 'hello' ) )
102
+ var thisArg = { }
103
+ var ret = findKey ( obj , callback , thisArg )
104
+ // assertions
105
+ expect ( callback . callCount ) . to . equal ( 3 )
106
+ expect ( ret ) . to . equal ( undefined )
107
+ done ( )
108
+ } )
94
109
describe ( 'errors' , function ( ) {
95
110
it ( 'should throw an error if obj must be an object' , function ( done ) {
96
111
var obj = 'notObject'
@@ -113,25 +128,53 @@ describe('findKey', function () {
113
128
done ( )
114
129
} )
115
130
} )
116
- describe ( 'use w/ array' , function ( ) {
117
- beforeEach ( function ( done ) {
118
- sinon . spy ( Array . prototype , 'findIndex' )
119
- done ( )
120
- } )
121
- afterEach ( function ( done ) {
122
- Array . prototype . findIndex . restore ( )
123
- done ( )
131
+ if ( Array . prototype . findIndex ) {
132
+ describe ( 'use w/ array' , function ( ) {
133
+ beforeEach ( function ( done ) {
134
+ sinon . spy ( Array . prototype , 'findIndex' )
135
+ done ( )
136
+ } )
137
+ afterEach ( function ( done ) {
138
+ Array . prototype . findIndex . restore ( )
139
+ done ( )
140
+ } )
141
+ it ( 'should use array findIndex' , function ( done ) {
142
+ var arr = [ 1 , 2 , 3 ]
143
+ var callback = noop
144
+ var index = arr . findIndex ( callback , arr )
145
+ expect ( findKey ( arr , callback ) )
146
+ . to . equal ( ~ index ? index : undefined )
147
+ sinon . assert . calledOn ( Array . prototype . findIndex , arr )
148
+ sinon . assert . calledWith ( Array . prototype . findIndex , callback )
149
+ done ( )
150
+ } )
124
151
} )
125
- it ( 'should use array findIndex' , function ( done ) {
126
- var arr = [ 1 , 2 , 3 ]
127
- var callback = noop
128
- var index = arr . findIndex ( callback , arr )
129
- expect ( findKey ( arr , callback ) )
130
- . to . equal ( ~ index ? index : undefined )
131
- sinon . assert . calledOn ( Array . prototype . findIndex , arr )
132
- sinon . assert . calledWith ( Array . prototype . findIndex , callback )
133
- done ( )
152
+ describe ( 'use w/ array' , function ( ) {
153
+ var findIndex = Array . prototype . findIndex
154
+ beforeEach ( function ( done ) {
155
+ delete Array . prototype . findIndex
156
+ done ( )
157
+ } )
158
+ afterEach ( function ( done ) {
159
+ Array . prototype . findIndex = findIndex // eslint-disable-line no-extend-native
160
+ done ( )
161
+ } )
162
+ it ( 'should break loop if item is found (weird array)' , function ( done ) {
163
+ var obj = [
164
+ 'foo' ,
165
+ 'bar' ,
166
+ 'baz'
167
+ ]
168
+ obj [ 'wut' ] = 'hello'
169
+ var callback = sinon . spy ( equals ( 'hello' ) )
170
+ var thisArg = { }
171
+ var ret = findKey ( obj , callback , thisArg )
172
+ // assertions
173
+ expect ( callback . callCount ) . to . equal ( 3 )
174
+ expect ( ret ) . to . equal ( undefined )
175
+ done ( )
176
+ } )
134
177
} )
135
- } )
178
+ }
136
179
} )
137
180
} )
0 commit comments