aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/q.js
diff options
context:
space:
mode:
authorMiško Hevery2012-12-14 05:49:22 -0800
committerMiško Hevery2012-12-14 05:49:22 -0800
commit039b138042de23852d8b2fdc4ca52ad178c96772 (patch)
treee7b2b137375fa2a36c67b29de5d4930f00d760fa /src/ng/q.js
parent30a9da5dc159dd1e19b677914356925c7ebdf632 (diff)
downloadangular.js-039b138042de23852d8b2fdc4ca52ad178c96772.tar.bz2
docs(q): added testing information
Diffstat (limited to 'src/ng/q.js')
-rw-r--r--src/ng/q.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ng/q.js b/src/ng/q.js
index fd412a33..8b474755 100644
--- a/src/ng/q.js
+++ b/src/ng/q.js
@@ -123,6 +123,30 @@
* you can treat promises attached to a scope as if they were the resulting values.
* - Q has many more features that $q, but that comes at a cost of bytes. $q is tiny, but contains
* all the important functionality needed for common async tasks.
+ *
+ * # Testing
+ *
+ * <pre>
+ * it('should simulate promise', inject(function($q, $rootSCope) {
+ * var deferred = $q.defer();
+ * var promise = deferred.promise;
+ * var resolvedValue;
+ *
+ * promise.then(function(value) { resolvedValue = value; });
+ * expect(resolvedValue).toBeUndefined();
+ *
+ * // Simulate resolving of promise
+ * defered.resolve(123);
+ * // Note that the 'then' function does not get called synchronously.
+ * // This is because we want the promise API to always be async, whether or not
+ * // it got called synchronously or asynchronously.
+ * expect(resolvedValue).toBeUndefined();
+ *
+ * // Propagate promise resolution to 'then' functions using $apply().
+ * $rootScope.$apply();
+ * expect(resolvedValue).toEqual(123);
+ * });
+ * </pre>
*/
function $QProvider() {