DEV Community

Cover image for Tutorial: Developing an angular app driven by tests

Tutorial: Developing an angular app driven by tests

Martin Maier on July 30, 2018

This article is a tutorial for developing Angular applications driven by tests (TDD). Introduction For a long time graphical user inter...
Collapse
 
wolfhoundjesse profile image
Jesse M. Holmes

This is great, Martin! So many examples say you should write the tests first, but then demonstrate how the framework works by writing the tests second.

Iā€™m getting better at deciding which questions to ask/which pieces to test, but I would love to find more material on this topic. E.g., if I am going to use a shared module for all of my @angular/material components, what would I test for that module?

Thanks!

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen • Edited

We would import our shared MaterialModule in a TestBed with a declared TestComponent and verify that its template is able to render the Angular Material components that we expect the shared module to re-export.

Here is an example:
stackblitz.com/edit/ngx-module-tes...

Collapse
 
_maimart_ profile image
Martin Maier

Of course, you can do so.

Collapse
 
_maimart_ profile image
Martin Maier • Edited

Thank you very much!

If you use it in all your components, it must handle cross cutting concerns like logging, data management, api access or something like that.

Especially in that case i would develop that module driven by tests more then ever. So i would start with an integration test for that module. Depending on the size and structure of the module, i would maybe break it down in smaller unit/component tests. But anyhow, i would always drive the development by tests.

For my liking the only reason not to test a component or module is that it is really humble and has no own behavior, like the views when using the "MVP Passive View"-pattern. Then, i think it is sufficient to only test it by e2e or system tests.

I think angular itself has a good guideline for testing (angular.io/guide/testing). And for TDD itself i love books about it from e.g. Uncle Bob and Kent Beck

Greets

Collapse
 
siddrc profile image
Siddharth Roychoudhury

Your article is missing a few steps, I am not sure if you did that on purpose...and there are typos as well...but nonetheless it helped me...and I was able to figure out the missing steps..and the typos...Thank you :)

Collapse
 
irek02 profile image
Irek Mirgaleev

Very nice! Here my attempt to show test driven angular: youtube.com/watch?v=oevY4WE1lnw