Skip to content

Commit

Permalink
jasmine: preserve 'this' test context
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Sivade committed Apr 26, 2018
1 parent 9202ab2 commit be32253
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions fixtures/jasmine/passing-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
import { map } from "rxjs/operators";
import { cases, marbles } from "../../dist/jasmine";

interface TestContext {
myVariable: number;
}

describe("rxjs-marbles", () => {

beforeEach(function(this: TestContext): void {
this.myVariable = 57;
});

it("should preserve test context", marbles(function(this: TestContext, m: any): void {
expect(this.myVariable).toBe(57);
}));

it("should support marble tests", marbles((m) => {

const values = {
Expand Down
4 changes: 2 additions & 2 deletions source/marbles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function marbles(func: (context: Context, ...rest: any[]) => any): (...re
}
};
}
return (...rest: any[]) => {
return function(this: any, ...rest: any[]): any {

const scheduler = new TestScheduler((a, b) => observableMatcher(a, b,
get("assert"),
Expand All @@ -42,7 +42,7 @@ export function marbles(func: (context: Context, ...rest: any[]) => any): (...re
const context = new Context(scheduler);

try {
return func(context, ...rest);
return func.call(this, context, ...rest);
} finally {
context.teardown();
}
Expand Down

0 comments on commit be32253

Please sign in to comment.