This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +9
-1
lines changed
2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -430,5 +430,13 @@ If your directive uses `templateUrl`, consider using
430
430
to pre-compile HTML templates and thus avoid having to load them over HTTP during test execution.
431
431
Otherwise you may run into issues if the test directory hierarchy differs from the application's.
432
432
433
+ ## Testing Promises
434
+
435
+ When testing promises, it's important to know that the resolution of promises is tied to the {@link ng.$rootScope.Scope#$digest digest cycle}.
436
+ That means a promise's `then`, `catch` and `finally` callback functions are only called after a digest has run.
437
+ In tests, you can trigger a digest by calling a scope's {@link ng.$rootScope.Scope#$apply `$apply` function}.
438
+ If you don't have a scope in your test, you can inject the {@link ng.$rootScope $rootScope} and call `$apply` on it.
439
+ There is also an example of testing promises in the {@link ng.$q#testing `$q` service documentation}.
440
+
433
441
## Sample project
434
442
See the [angular-seed](https://github.com/angular/angular-seed) project for an example.
Original file line number Diff line number Diff line change 186
186
* - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains
187
187
* all the important functionality needed for common async tasks.
188
188
*
189
- * # Testing
189
+ * # Testing
190
190
*
191
191
* ```js
192
192
* it('should simulate promise', inject(function($q, $rootScope) {
You can’t perform that action at this time.
0 commit comments