Skip to content

Commit

Permalink
test: combine chain/wrap into chain-wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Garcia committed Nov 12, 2013
1 parent 93d9edc commit 83e51d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
33 changes: 26 additions & 7 deletions test/wrap.coffee → test/chain-wrap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ _s = require "#{__dirname}/../index"
sinon = require 'sinon'
_ = require 'underscore'

describe '_s(a)', ->
it 'has the methods of _s excluding value/mixin', ->
for obj in [_s(), _s('a')]
assert.deepEqual(
_.chain().functions(obj).without('value').value()
_.chain().functions(_s).without('mixin').value()
)
describe 'methods on wrapped/chained objects are the same as methods on _s', ->
for obj in [_s(), _s('a'), _s().chain(), _s('a').chain()]
assert.deepEqual(
_.chain().functions(obj).without('value').value()
_.chain().functions(_s).without('mixin').value()
)

describe '_s(a)', ->
it 'binds a as the first argument to the next method invoked', ->
spy = sinon.spy ->
_s.mixin fn: spy
Expand Down Expand Up @@ -43,3 +43,22 @@ describe '_s(a)', ->
it '.missing() throws', ->
assert.throws () ->
_s('a').missing()

describe '_s(a).chain()', ->
it '.value() returns a', ->
assert.equal _s().chain().value(), undefined
assert.equal _s('a').chain().value(), 'a'

it '.fn1(b).fn2(c).value() is equivalent to calling _s.fn2(_s.fn1(a, b), c)', ->
spy1 = sinon.spy -> 1
spy2 = sinon.spy -> 2
_s.mixin {fn1: spy1, fn2: spy2}
val = _s('a').chain().fn1('b').fn2('c').value()
assert.equal val, 2
assert.equal val, _s.fn2(_s.fn1('a', 'b'), 'c')
assert.equal spy1.callCount, 2
assert.equal spy2.callCount, 2
assert.deepEqual spy1.args[0], ['a', 'b']
assert.deepEqual spy1.args[1], ['a', 'b']
assert.deepEqual spy2.args[0], [1, 'c']
assert.deepEqual spy2.args[1], [1, 'c']
31 changes: 0 additions & 31 deletions test/chain.coffee

This file was deleted.

0 comments on commit 83e51d4

Please sign in to comment.