You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -811,6 +811,81 @@ _Why_: Using DI makes testing and refactoring easier.
811
811
812
812
_Why_: You should `$scope.$apply()` as close to the asynchronous event binding as possible.
813
813
814
+
### Testing
815
+
816
+
Our applications are covered by two different types of test:
817
+
- unit tests, which test individual components by asserting that they behave as expected.
818
+
- End to End, or E2E, tests, which load up the application in a browser and interact with it as if a user would, asserting the application behaves expectedly.
819
+
820
+
To write our tests we use [Jasmine BDD](http://jasmine.github.io/2.0/introduction.html) and [ngMock](https://docs.angularjs.org/api/ngMock).
821
+
822
+
#### Unit Testing
823
+
824
+
Every component should have a comprehensive set of unit tests.
825
+
826
+
##### Structure of Unit Tests
827
+
828
+
Tests should be grouped into logical blocks using Jasmine's `describe` function. Tests for a function should all be contained within a `describe` block, and `describe` blocks should also be used to describe different scenarios, or _contexts_:
829
+
830
+
```js
831
+
describe('#update', function() {
832
+
describe('when the data is valid', function() {
833
+
it('shows the success message', function() {…});
834
+
});
835
+
836
+
describe('when the data is invalid', function() {
837
+
it('shows errors', function() {…});
838
+
});
839
+
});
840
+
```
841
+
842
+
##### Dependencies
843
+
844
+
Each component should have its dependencies stubbed in each test.
845
+
846
+
Inject the dependencies and the components being tested in a `beforeEach` function. This encapsulates each test's state, ensuring that they are independent, making them easier to reason about. Tests should never depend on being run in a specific order.
847
+
848
+
```js
849
+
var SomeService;
850
+
851
+
beforeEach(inject(function($injector) {
852
+
SomeService =$injector.get('SomeService');
853
+
}));
854
+
```
855
+
856
+
##### Controllers
857
+
858
+
When injecting controllers for a test, use the `controller as` syntax:
When stubbing an API request using `$httpBackend`, always respond with a correctly formatted object. These responses should be saved individually as `.json` files and imported using the SystemJS JSON plugin:
0 commit comments