Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 039b138

Browse files
committed
docs(q): added testing information
1 parent 30a9da5 commit 039b138

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/ng/q.js

+24
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@
123123
* you can treat promises attached to a scope as if they were the resulting values.
124124
* - Q has many more features that $q, but that comes at a cost of bytes. $q is tiny, but contains
125125
* all the important functionality needed for common async tasks.
126+
*
127+
* # Testing
128+
*
129+
* <pre>
130+
* it('should simulate promise', inject(function($q, $rootSCope) {
131+
* var deferred = $q.defer();
132+
* var promise = deferred.promise;
133+
* var resolvedValue;
134+
*
135+
* promise.then(function(value) { resolvedValue = value; });
136+
* expect(resolvedValue).toBeUndefined();
137+
*
138+
* // Simulate resolving of promise
139+
* defered.resolve(123);
140+
* // Note that the 'then' function does not get called synchronously.
141+
* // This is because we want the promise API to always be async, whether or not
142+
* // it got called synchronously or asynchronously.
143+
* expect(resolvedValue).toBeUndefined();
144+
*
145+
* // Propagate promise resolution to 'then' functions using $apply().
146+
* $rootScope.$apply();
147+
* expect(resolvedValue).toEqual(123);
148+
* });
149+
* </pre>
126150
*/
127151
function $QProvider() {
128152

0 commit comments

Comments
 (0)