arunoda / nodemock

Simple Yet Powerful Mocking Framework for NodeJs
http://arunoda.me
MIT License
75 stars 1 forks source link

A way to mock chains #2

Closed dominictarr closed 13 years ago

dominictarr commented 13 years ago

If a method returns this you can chain it's function calls

thing.foo().bar() 

but you can't go

mock = nodemock.mock('foo').returns(mock)

one way to support this would be to ab able to add more functions to a mock

mock = nodemock.mock('foo').returns(mock) nodemock.more(mock).mock('chain').returns(mock)

cheers. Dominic

dominictarr commented 13 years ago

alright, I figured out a way to do this, but you have to make an empty mock function first.

var mock = nodemock.mock('ignore')
mock.mock('chaining').takes('whatever').returns(mock)

no ideal, but it's a feasible work around.

arunoda commented 13 years ago

This is how it's work and :) you are correct,, you've found the correct way of doing that :) or you can try this too.

var mocked = nodemock.mock('foo').returns(nodemock.mock('bar'));`
dominictarr commented 13 years ago

great, that also inforces what order the chains should be called in, cheers!

arunoda commented 13 years ago

Great to hear that you are using nodemock. Happy testing. :-)