jupiter / simple-mock

Super simple stubs and spies with 1-step sandbox restore
MIT License
87 stars 12 forks source link

Add stub.callOriginal() that configures a stub to call the unstubbed function #6

Closed HCanber closed 9 years ago

HCanber commented 9 years ago

This PR adds stub.callOriginal() that configures a stub to call the original unstubbed function.

Can be useful for example if you want the stubbed function to throw an error the first time it's called and succeed the second time.

simple.mock(obj, 'example').throwWith(new Error()).callOriginal()

I also added callOriginalFn as an alias for callOriginal(to be similar to callFn that ends in Fn)

Discussion

Unsure about the name "callOriginal". Maybe you have a better suggestion.

jupiter commented 9 years ago

That's really nice. I think the name is fine and the code looks good to me. Thanks.