Skip to content

Commit

Permalink
test(rule): Add Observable.create fixture.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed May 6, 2017
1 parent 3fc5334 commit 56a8af0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions fixtures/observable-create/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Observable } from "rxjs/Observable";
import "rxjs/add/operator/filter";
import "rxjs/add/operator/map";

// Note that Observable.create is declared as a Function:
// https://github.com/ReactiveX/rxjs/blob/5.3.1/src/Observable.ts#L46-L58
//
// So its result will be any - which will mess with the rules unless the
// variable is explicitly typed:

const ob1 = Observable.create((observer: Observer<number>) => {

observer.next(1);
observer.complete();
});
const ob2 = ob1.filter((value) => value > 1);


const ob3 = ob1 as Observable<number>;
const ob4 = ob3.map((value) => value + 1);
13 changes: 13 additions & 0 deletions fixtures/observable-create/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"lib": ["es2015"],
"noEmit": true,
"paths": {
"rxjs": ["../node_modules/rxjs"]
},
"skipLibCheck": true,
"target": "es5"
},
"include": ["fixture.ts"]
}
11 changes: 11 additions & 0 deletions source/fixtures-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ describe("fixtures", function (): void {
});
});

describe("observable-create", () => {

it("should effect an error unless explicit typing is used", () => {

const result = lint("observable-create");

expect(result).to.have.property("errorCount", 1);
expect(result.failures[0]).to.have.property("ruleName", "rxjs-no-unused-add");
});
});

describe("unused-observable", () => {

it("should effect 'rxjs-no-unused-add' errors", () => {
Expand Down

0 comments on commit 56a8af0

Please sign in to comment.