forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(facade): added support for observables
- Loading branch information
Showing
10 changed files
with
187 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el, | ||
SpyObject, AsyncTestCompleter, inject, IS_DARTIUM} from 'angular2/test_lib'; | ||
|
||
import {ObservableWrapper, Observable, ObservableController, PromiseWrapper} from 'angular2/src/facade/async'; | ||
|
||
export function main() { | ||
describe('Observable', () => { | ||
var obs:Observable; | ||
var controller:ObservableController; | ||
|
||
beforeEach(() => { | ||
controller = ObservableWrapper.createController(); | ||
obs = ObservableWrapper.createObservable(controller); | ||
}); | ||
|
||
it("should call the next callback", inject([AsyncTestCompleter], (async) => { | ||
ObservableWrapper.subscribe(obs, (value) => { | ||
expect(value).toEqual(99); | ||
async.done(); | ||
}); | ||
|
||
ObservableWrapper.callNext(controller, 99); | ||
})); | ||
|
||
it("should call the throw callback", inject([AsyncTestCompleter], (async) => { | ||
ObservableWrapper.subscribe(obs, (_) => {}, (error) => { | ||
expect(error).toEqual("Boom"); | ||
async.done(); | ||
}); | ||
ObservableWrapper.callThrow(controller, "Boom"); | ||
})); | ||
|
||
it("should call the return callback", inject([AsyncTestCompleter], (async) => { | ||
ObservableWrapper.subscribe(obs, (_) => {}, (_) => {}, () => { | ||
async.done(); | ||
}); | ||
|
||
ObservableWrapper.callReturn(controller); | ||
})); | ||
|
||
it("should subscribe to the wrapper asynchronously", () => { | ||
var called = false; | ||
ObservableWrapper.subscribe(obs, (value) => { | ||
called = true; | ||
}); | ||
|
||
ObservableWrapper.callNext(controller, 99); | ||
expect(called).toBe(false); | ||
}); | ||
|
||
if (!IS_DARTIUM) { | ||
// See here: https://github.com/jhusain/observable-spec | ||
describe("Generator", () => { | ||
var generator; | ||
|
||
beforeEach(() => { | ||
generator = new SpyObject(); | ||
generator.spy("next"); | ||
generator.spy("throw"); | ||
generator.spy("return"); | ||
}); | ||
|
||
it("should call next on the given generator", inject([AsyncTestCompleter], (async) => { | ||
generator.spy("next").andCallFake((value) => { | ||
expect(value).toEqual(99); | ||
async.done(); | ||
}); | ||
|
||
ObservableWrapper.subscribe(obs, generator); | ||
ObservableWrapper.callNext(controller, 99); | ||
})); | ||
|
||
it("should call throw on the given generator", inject([AsyncTestCompleter], (async) => { | ||
generator.spy("throw").andCallFake((error) => { | ||
expect(error).toEqual("Boom"); | ||
async.done(); | ||
}); | ||
ObservableWrapper.subscribe(obs, generator); | ||
ObservableWrapper.callThrow(controller, "Boom"); | ||
})); | ||
|
||
it("should call return on the given generator", inject([AsyncTestCompleter], (async) => { | ||
generator.spy("return").andCallFake(() => { | ||
async.done(); | ||
}); | ||
ObservableWrapper.subscribe(obs, generator); | ||
ObservableWrapper.callReturn(controller); | ||
})); | ||
}); | ||
} | ||
|
||
//TODO: vsavkin: add tests cases | ||
//should call dispose on the subscription if generator returns {done:true} | ||
//should call dispose on the subscription on throw | ||
//should call dispose on the subscription on return | ||
}); | ||
} | ||
|
||
//make sure rx observables are async |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
System.paths = { | ||
'*': '/*.js' | ||
'*': '/*.js', | ||
'rx/dist/*': '*.js' | ||
}; | ||
register(System); | ||
cjs(System); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters