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();
}));
});
...