di.js icon indicating copy to clipboard operation
di.js copied to clipboard

docs(mocks): add recipe for creating mocks with DI

Open jeffbcross opened this issue 11 years ago • 5 comments

I added a recipe for mocking classes with DI. Maybe I'm doing it wrong, so please give a good review before merging :).

Review on Reviewable

jeffbcross avatar Feb 27 '14 22:02 jeffbcross

Can you write it using https://github.com/angular/di.js/blob/master/example/testing/coffee.spec.js ?

vojtajina avatar Feb 28 '14 02:02 vojtajina

I don't think creating mocks manually, is a scalable solution. Every time there is an update in the original class you might have to update your mocks also. I would rather prefer using Stubs. Use a library like - Sinon to stub your requests that are dependent on the XMLHttpRequest object. Any thoughts, where I could be wrong?

tusharmath avatar Oct 12 '14 11:10 tusharmath

@tusharmath sinon actually provides quite a few mocks itself... mocks and stubs sort of solve different problems. Mocking a class which performs async ops is attractive for testing because it lets your tests have a bit more control, and the ability to run synchronously. Stubs are useful for letting you perform assertions at a certain point, or asserting that the particular subroutine was invoked the way you expect it to be.

Both are great for testing, but they don't solve the same problems

caitp avatar Oct 12 '14 13:10 caitp

@caitp After seeing a lil bit here and there I finally got your point. Thanks!

tusharmath avatar Oct 13 '14 04:10 tusharmath

Where would modules like - Mockery fit in? Are both of them solving the same problem?

tusharmath avatar Oct 13 '14 16:10 tusharmath