Skip to content

Commit

Permalink
test: more chain/wrap behavior tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Garcia committed Nov 12, 2013
1 parent 05e42be commit b2808b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
12 changes: 10 additions & 2 deletions test/chain.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ async = require 'async'
_s = require "#{__dirname}/../index"
sinon = require 'sinon'

describe '_s(a).chain().fn1(b).fn2(c).value()', ->
it 'is equivalent to calling _s.fn2(_s.fn1(a, b), c)', ->
describe '_s(a).chain()', ->
it "has the methods of _s", ->

This comment has been minimized.

Copy link
@jonahkagan

jonahkagan Nov 12, 2013

Contributor

could you actually test this? maybe something like:

assert.deepEqual _s().chain(), _.functions(_s)

also curious to know what happens if you do _s.chain().chain()

This comment has been minimized.

Copy link
@rgarcia

rgarcia Nov 12, 2013

Member

This comment has been minimized.

Copy link
@rgarcia

rgarcia Nov 12, 2013

Member

chain().chain() 85b745f

assert _s().chain().each?
assert _s('a').chain().each?

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}
Expand Down
31 changes: 29 additions & 2 deletions test/wrap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@ async = require 'async'
_s = require "#{__dirname}/../index"
sinon = require 'sinon'

describe '_s(a).fn(b)', ->
it 'is equivalent to calling _s.fn(a,b)', ->
describe '_s(a)', ->
it 'has the methods of _s', ->
assert _s().each?
assert _s('a').each?

it 'binds a as the first argument to the next method invoked', ->
spy = sinon.spy ->
_s.mixin fn: spy
_s().fn(10)
_s().fn(10, 20)
_s('a').fn(10)
_s('a').fn(10, 20)
_s('a', 'b').fn(10)
_s('a', 'b').fn(10, 20)
assert.equal spy.callCount, 6
assert.deepEqual spy.args, [
[undefined, 10]
[undefined, 10, 20]
['a', 10]
['a', 10, 20]
['a', 10] # ignores > 1 argument
['a', 10, 20] # ignores > 1 argument
]

it '.fn(b) is equivalent to calling _s.fn(a,b)', ->
spy = sinon.spy ->
_s.mixin fn: spy
_s.fn 'a', 'b'
_s('a').fn('b')
assert.equal spy.callCount, 2
assert.deepEqual spy.args[0], ['a', 'b']
assert.deepEqual spy.args[0], spy.args[1]

it '.missing() throws', ->
assert.throws () ->
_s('a').missing()

1 comment on commit b2808b9

@jonahkagan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Please sign in to comment.