But Is It Really Unit Testing?
Learning from the Pros
- Dig into the functions. In his talk above Vojta briefly touched on this pain that I was experience as he says this type of testing is, "a little bit higher level than unit testing" in that it is using this compile and inspecting DOM stuff. He notes that sometimes you can look only at a directive's controller of link function without the html template at all. This is much more in line with that I would traditionally think of as unit testing; testing the public api by calling it's methods and then running assertions on the results. Vojta also mentions that I think when trying to expose bugs with unit testing is can be easier when you are in the functions and closer to it's internal properties and methods. Both testing the link function and controller's methods individually and testing the the isolated directive as a whole can both be extremely useful, and I believe there is a happy place for both approaches in the world of unit testing.
- Protractor has no "inject" method available in its beforeEach's. This is key because when unit testing you pull in all of your controllers, services, filters, etc through DI, even directive link functions. That is what makes it unit testing. When running your test in Protractor it will actually throw an error if you try to use the inject keyword. So if you try to say this: