Skip to content

Commit

Permalink
Merge pull request #17 from natlibfi-arlehiko/stub-loop-func
Browse files Browse the repository at this point in the history
Add loop toggle functions for stub
  • Loading branch information
jupiter authored Oct 31, 2016
2 parents cd1c47b + 14fd323 commit c160817
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Configures the stub to return a Promise (where available] resolving to this valu

Configures the stub to return a Promise (where available) rejecting with this error. Same as `stub.returnWith(Promise.reject(val))`. You can use a custom Promise-conforming library, i.e. `simple.Promise = require('bluebird')` or `simple.Promise = $q`.

### stub.withLoop & stub.noLoop

Configures the stub to enable/disable [looping](#stubloop).

### stub.actions

An array of behaviours, each having *one* of these properties:
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@
newFn.actions.push({ fn: originalFn })
return newFn // Chainable
}

newFn.withLoop = function () {
newFn.loop = true
return newFn // Chainable
}

newFn.noLoop = function () {
newFn.loop = false
return newFn // Chainable
}
return newFn
}

Expand Down
27 changes: 27 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,33 @@ describe('simple', function () {
})
})
})

describe('#noLoop', function () {

it('should disable looping', function () {

var stub = simple.stub().noLoop().returnWith('foo')

assert.equal(stub(), 'foo')
assert.equal(stub(), undefined)

})

})

describe('#withLoop', function () {

it('should enable looping', function () {

var stub = simple.stub().withLoop().returnWith('foo')

assert.equal(stub(), 'foo')
assert.equal(stub(), 'foo')

})

})

})

describe('restore()', function () {
Expand Down

0 comments on commit c160817

Please sign in to comment.