As a professional software developer I have had the luxury of being able to work on successful professional projects in AngularJS, React, and now the modern Angular. To me it's so funny how similar the two frameworks are in terms of the problem they are trying to solve and even the way they do it.
Angular's dependency injection is great because it allows you to say "For any of my services anywhere using JimHttp, just use JimHttpMock instead". All you need to do is put an object for it in the providers array when setting up your test, as in the example below:
By allowing a framework to create and instantiate dependencies we don't have to put all that in our code, and after injecting a service we just immediately start using it. This makes everything super decoupled and allows us to easily substitute in Mocks or spy on functions without even needing to know the "compositional inheritance chain" of how exactly how that asynchronous side effect class is related to each individual component or service.
Angular comes with jasmine out of the box as the framework used for unit testing. Personally, I like the jasmine syntax much better than mocha / chai, especially the syntax for spying on a function, etc. so for me it's a win that Angular uses jasmine, but I do know some people who don't like the syntax.
I was an AngularJS developer and then I switched over to React, but now I think I'm liking new Angular even better, simply because of the DI and how much easier it makes testing. haha. What do you guys think? Are you liking testing in Angular as well? Are you a React dev who is totally fine testing without dependency injection? Let me know! ?
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
Sign up here:
- Triple Gainers
- Rippers N' Dippers
- Growingest Growers