mjackson / expect

Write better assertions
MIT License
2.29k stars 117 forks source link

Spies that are placed in the 'before' or in the 'describe' directly only work with the first 'it' #129

Closed MariusBaci closed 8 years ago

MariusBaci commented 8 years ago

They seem to work only with the first 'it', as from the second on, the call is made to the original function, and not to the spy.

Is this how it's implemented (to only work if they are placed in the 'beforeEach' or 'it'), or is this an issue ?

ljharb commented 8 years ago

Certainly any code in the scope of the "describe" will only run once for all tests within it, just like "before". You may want to define it inside "beforeEach"?

This is a thing common to most test frameworks in most languages. It's the same in ruby's rspec, for example, unless you're using the "let" constructs.

MariusBaci commented 8 years ago

Sorry about that, it was an error in my code, I used expect.restoreSpies() instead of spy.restore(). The framework works fine. Thank you for the prompt answer.