What should I check in AngularJS?

Nowadays, especially in the world of corner testing, there are many manuals for conducting various kinds of tests, such as Unit-testing, Midway Testing and E2E Testing, where you can learn how to make these different tests for controllers, factories, etc. .

Does the topic have something to check? I can verify that in my modular application there are controllers, directives, successful logins, checking backend calls, etc. But what should I test ?, because you can test everything, and probably this is not a good practice doing “easy tests”.

Can someone give me any suggestions? Thanks.

+4
source share
2 answers

For a general answer, you can look at question .

Assuming your unit tests for angular are written in Jasmine or something similar, note that Jasmine is focused on "Behavior Driven Development".

From this presentation : "Behavior-Driven-Development is an application implementation that describes its behavior from the perspective of its stakeholders."

Another good source, but more rigorous (TDD or test oriented) is Bob Martin Clean code. My biggest takeaways test:

  • Let the tests be your documentation.
  • Your tests let you reorganize
  • Test next to the user or consumer and drive your way inside if necessary

I.e

  • , , . , , BDD.
  • , , , , .
  • , . , , .

:

, , . : " , , 5 ". , :

  describe('Given a set of weather data'....
      ...
      describe('when I enter Los Angeles', function() {
          it('should return 5 days of forecast data for Los Angeles', 
          mocks.inject(function(weatherService) {
          var result = weatherService.getForecast('Los Angeles');
            expect(result.DayToForecast.lenth).toEqual(5);
          }));
      });
      ...

, , , : " , , "

      ...
      describe('When I enter Los Angeles and Monday', function() {
          it('should return humidity data for Los Angeles on Monday', 
          mocks.inject(function(weatherService) {
          var result = weatherService.getForecast('Los Angeles');
            expect(result.DayToForecast['Monday'].humidity).not.toBe(null);
          }));
      });
      ...

, , - . (, , -). - , :

      ...
      describe('when I enter Los Angeles and Monday', function() {
          it('should return humidity data for Los Angeles on Monday', 
          mocks.inject(function(weatherService) {
          var result = weatherService.getForecast('Los Angeles','Monday');
            expect(result.humidity).not.toBe(null);
          }));
      });
      ...

, " " - , , , . , , : " , , 4 ", , , , .

. , , - -, : " , , " :

      ...
      describe('when I enter Los Angeles and EigthDay', function() {
          it('should throw an exception', 
          mocks.inject(function(weatherService) {
          var weatherServiceCall = function(){
                weatherService.getForecast('Los Angeles','EighthDay');
              };
              expect(weatherServiceCall).toThrow();
          }));
      });
      ...
+5

.

unit- /, . , , , , - , . - - ? , .

, , . , , , , ? , ? - . .

Year Of Moo angularjs- - http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html

- , , . , , .

  • ?
  • - ?
  • ?
  • ?

, - , , , , E2E, . , E2E , , , / undefined, , , .

, -.

+1

Source: https://habr.com/ru/post/1528091/


All Articles