File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+ "use strict" ;
6+
57module . exports = function removeAndDo ( collection , thing , action ) {
6- var idx = this [ collection ] . indexOf ( thing ) ;
7- if ( idx >= 0 ) {
8+ const idx = this [ collection ] . indexOf ( thing ) ;
9+ const hasThingInCollection = idx >= 0 ;
10+ if ( hasThingInCollection ) {
811 this [ collection ] . splice ( idx , 1 ) ;
912 thing [ action ] ( this ) ;
10- return true ;
1113 }
12- return false ;
14+ return hasThingInCollection ;
1315} ;
Original file line number Diff line number Diff line change 1+ /* globals describe, it, beforeEach */
2+ "use strict" ;
3+
4+ const should = require ( "should" ) ;
5+ const sinon = require ( "sinon" ) ;
6+ const removeAndDo = require ( "../lib/removeAndDo" ) ;
7+
8+ describe ( "removeAndDo" , ( ) => {
9+ let actionSpy ;
10+ let thingsMock ;
11+ let contextMock ;
12+ let anotherThingsMock ;
13+
14+ beforeEach ( ( ) => {
15+ actionSpy = sinon . spy ( ) ;
16+ thingsMock = {
17+ action : actionSpy
18+ } ;
19+ anotherThingsMock = {
20+ action : actionSpy
21+ } ;
22+ contextMock = {
23+ context : [ thingsMock ]
24+ } ;
25+ } ) ;
26+
27+ it ( "should return true" , ( ) => {
28+ should ( removeAndDo . bind ( contextMock ) ( 'context' , thingsMock , 'action' ) ) . be . eql ( true ) ;
29+ actionSpy . callCount . should . be . exactly ( 1 ) ;
30+ } ) ;
31+
32+ it ( "should return false" , ( ) => {
33+ should ( removeAndDo . bind ( contextMock ) ( 'context' , anotherThingsMock , 'anotherAction' ) ) . be . eql ( false ) ;
34+ actionSpy . callCount . should . be . exactly ( 0 ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments