I think Jack is the best mocking framework for JavaScript at the time of this writing. The main reason is that JavaScript right is unlikely, which is suitable for a strongly typed language such as Java.
Many fake JavaScript frames are inspired by Java frameworks (like great JsMockito for example). But the problem is that they require dependency injection , because this is the only reasonable way to use taunts in Java. But in JavaScript, there are many ways to use mockery, and you are not forced to use dependency injection everywhere.
For example, with JsMockito you need to make mocks, and then pass these mocks to your test software (SUT). SUT should directly call ridicule. Therefore, you are forced to encode SUT as a constructor or function that takes parameters in all its dependencies. (Sometimes this is a great way to implement it, but not in every case. The tail wags the dog if your mocking frame design forces your approach to implementation).
JavaScript is very easy to capture any function. Therefore, there are many ways to create something that you can mock particles without explicitly inserting your dependencies into it. For example, Jack allows you to mock any function, regardless of whether it is a public or local object. From there, you can spy on her, drown her out or express expectations on her. The key point is: when you mock a function, ANY calls to this original function will be directed to your layout . In other words, your bullying will continue to be used, even if the original, unmocked function was called. As a result, you are not forced to add dependencies, although you can certainly do so in cases that require it.
JavaScript is a different language than Java (and C #, etc.). It allows you to use different implementation idioms. Injection injection is still one of the valuable toolbar tools in JavaScript, but this is not the only game in the city. Your bold structure should know and respect this fact. Jack and a couple of others, but of those who do, Jack seems to be the most mature and rich in opportunities.
Charlie Flowers Oct 27 '10 at 6:35 2010-10-27 06:35
source share