rxjs-marbles
Advanced tools
Comparing version 2.0.0 to 2.1.0
import { TestContext } from "ava"; | ||
import { NamedCase, UnnamedCase } from "../cases"; | ||
import { Context } from "../context"; | ||
@@ -6,2 +7,6 @@ export { configure } from "../configuration"; | ||
export * from "../expect"; | ||
export declare function marbles(test: (m: Context, t: TestContext) => void): any; | ||
export declare function cases<T extends UnnamedCase>(name: string, func: (context: Context, _case: T, t: TestContext) => void, cases: { | ||
[key: string]: T; | ||
}): void; | ||
export declare function cases<T extends NamedCase>(name: string, func: (context: Context, _case: T, t: TestContext) => void, cases: T[]): void; | ||
export declare function marbles(func: (m: Context, t: TestContext) => void): any; |
@@ -0,1 +1,3 @@ | ||
import { test } from "ava"; | ||
import { _cases } from "../cases"; | ||
import { marbles as _marbles } from "../marbles"; | ||
@@ -5,3 +7,9 @@ export { configure } from "../configuration"; | ||
export * from "../expect"; | ||
export function marbles(test) { | ||
export function cases(name, func, cases) { | ||
_cases(function (c) { | ||
var t = c.only ? test.only : c.skip ? test.skip : test; | ||
t(name + " / " + c.name, marbles(function (m, t) { return func(m, c, t); })); | ||
}, cases); | ||
} | ||
export function marbles(func) { | ||
return _marbles(function (m, t) { | ||
@@ -12,4 +20,4 @@ m.configure({ | ||
}); | ||
test(m, t); | ||
func(m, t); | ||
}); | ||
} |
{ | ||
"main": "../bundles/rxjs-marbles-ava.umd.js", | ||
"module": "./index.js", | ||
"typings": "./index.d.ts" | ||
} |
@@ -0,1 +1,8 @@ | ||
<a name="2.1.0"></a> | ||
## [2.1.0](https://github.com/cartant/rxjs-marbles/compare/v2.0.0...v2.1.0) (2017-10-08) | ||
### Features | ||
* **cases**: Add support for a [`jest-in-case`](https://github.com/Thinkmill/jest-in-case)-style `cases` function. ([4d3559e](https://github.com/cartant/rxjs-marbles/commit/4d3559e)) | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +9,0 @@ ## [2.0.0](https://github.com/cartant/rxjs-marbles/compare/v1.6.0...v2.0.0) (2017-09-11) |
export { configure } from "./configuration"; | ||
export * from "./cases"; | ||
export * from "./context"; | ||
export * from "./expect"; | ||
export * from "./marbles"; |
export { configure } from "./configuration"; | ||
export * from "./cases"; | ||
export * from "./context"; | ||
export * from "./expect"; | ||
export * from "./marbles"; |
import { Context } from "./context"; | ||
export declare function marbles(test: (context: Context) => any): () => any; | ||
export declare function marbles<T1>(test: (context: Context, t1: T1) => any): (t1: T1) => any; | ||
export declare function marbles<T1, T2>(test: (context: Context, t1: T1, t2: T2) => any): (t1: T1, t2: T2) => any; | ||
export declare function marbles<T1, T2, T3>(test: (context: Context, t1: T1, t2: T2, t3: T3) => any): (t1: T1, t2: T2, t3: T3) => any; | ||
export declare function marbles(func: (context: Context) => any): () => any; | ||
export declare function marbles<T1>(func: (context: Context, t1: T1) => any): (t1: T1) => any; | ||
export declare function marbles<T1, T2>(func: (context: Context, t1: T1, t2: T2) => any): (t1: T1, t2: T2) => any; | ||
export declare function marbles<T1, T2, T3>(func: (context: Context, t1: T1, t2: T2, t3: T3) => any): (t1: T1, t2: T2, t3: T3) => any; | ||
export declare function marbles(func: (context: Context, ...rest: any[]) => any): (...rest: any[]) => any; |
@@ -5,11 +5,25 @@ import { TestScheduler } from "rxjs/testing/TestScheduler"; | ||
import { observableMatcher } from "./matcher"; | ||
export function marbles(test) { | ||
export function marbles(func) { | ||
if (func.length > 1) { | ||
return function (first) { | ||
var rest = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
rest[_i - 1] = arguments[_i]; | ||
} | ||
var scheduler = new TestScheduler(function (a, b) { return observableMatcher(a, b, get("assert"), get("assertDeepEqual")); }); | ||
var context = new Context(scheduler); | ||
func.apply(void 0, [context, first].concat(rest)); | ||
if (context.autoFlush) { | ||
scheduler.flush(); | ||
} | ||
}; | ||
} | ||
return function () { | ||
var args = []; | ||
var rest = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
rest[_i] = arguments[_i]; | ||
} | ||
var scheduler = new TestScheduler(function (a, b) { return observableMatcher(a, b, get("assert"), get("assertDeepEqual")); }); | ||
var context = new Context(scheduler); | ||
test.apply(null, [context].concat(args)); | ||
func.apply(void 0, [context].concat(rest)); | ||
if (context.autoFlush) { | ||
@@ -16,0 +30,0 @@ scheduler.flush(); |
@@ -43,4 +43,4 @@ { | ||
"unpkg": "./bundles/rxjs-marbles.umd.js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"ava": {} | ||
} |
@@ -8,2 +8,3 @@ # rxjs-marbles | ||
[![peerDependency Status](https://img.shields.io/david/peer/cartant/rxjs-marbles.svg)](https://david-dm.org/cartant/rxjs-marbles#info=peerDependencies) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/cartant/rxjs-marbles.svg)](https://greenkeeper.io/) | ||
@@ -49,8 +50,3 @@ ### What is it? | ||
const values = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}; | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
@@ -77,8 +73,3 @@ const source = m.hot("--^-a-b-c-|", values); | ||
const values = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}; | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
@@ -109,8 +100,3 @@ const source = m.hot("--^-a-b-c-|", values); | ||
const values = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}; | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
@@ -142,8 +128,3 @@ const source = m.hot("--^-a-b-c-|", values); | ||
const values = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}; | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
@@ -174,2 +155,61 @@ const source = m.hot("--^-a-b-c-|", values); | ||
### Using cases for test variations | ||
In addition to the `marbles` function, the library exports a `cases` function that can be used to reduce test boilerplate by specifying multiple cases for variations of a single test. The API is based on that of [`jest-in-case`](https://github.com/Thinkmill/jest-in-case), but also includes the marbles context. | ||
The `cases` implementation is framework-specific, so the import should specify the framework. For example, with Jasmine, you would import `cases` and use it instead of the `it` function, like this: | ||
```ts | ||
import { cases } from "rxjs-marbles/jasmine"; | ||
describe("rxjs-marbles", () => { | ||
cases("should support cases", (m, c) => { | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
const source = m.hot(c.s, values); | ||
const expected = m.cold(c.e, values); | ||
const destination = source.map((value) => value + 1); | ||
m.expect(destination).toBeObservable(expected); | ||
}, { | ||
"non-empty": { | ||
s: "-a-b-c-|", | ||
e: "-b-c-d-|" | ||
}, | ||
"empty": { | ||
s: "-|", | ||
e: "-|" | ||
} | ||
}); | ||
}); | ||
``` | ||
With AVA and Tape, the `cases` function also receives the test context. For example, with AVA, you would import `cases` and use it instead of the `test` function, like this: | ||
```ts | ||
import { cases } from "rxjs-marbles/ava"; | ||
cases("should support cases", (m, c, t) => { | ||
t.plan(1); | ||
const values = { a: 1, b: 2, c: 3, d: 4 }; | ||
const source = m.hot(c.s, values); | ||
const expected = m.cold(c.e, values); | ||
const destination = source.map((value) => value + 1); | ||
m.expect(destination).toBeObservable(expected); | ||
}, { | ||
"non-empty": { | ||
s: "-a-b-c-|", | ||
e: "-b-c-d-|" | ||
}, | ||
"empty": { | ||
s: "-|", | ||
e: "-|" | ||
} | ||
}); | ||
``` | ||
## API | ||
@@ -176,0 +216,0 @@ |
import * as tape from "tape"; | ||
import { NamedCase, UnnamedCase } from "../cases"; | ||
import { Context } from "../context"; | ||
@@ -6,2 +7,6 @@ export { configure } from "../configuration"; | ||
export * from "../expect"; | ||
export declare function marbles(test: (m: Context, t: tape.Test) => void): any; | ||
export declare function cases<T extends UnnamedCase>(name: string, func: (context: Context, _case: T, t: tape.Test) => void, cases: { | ||
[key: string]: T; | ||
}): void; | ||
export declare function cases<T extends NamedCase>(name: string, func: (context: Context, _case: T, t: tape.Test) => void, cases: T[]): void; | ||
export declare function marbles(func: (m: Context, t: tape.Test) => void): any; |
@@ -0,1 +1,3 @@ | ||
import * as tape from "tape"; | ||
import { _cases } from "../cases"; | ||
import { marbles as _marbles } from "../marbles"; | ||
@@ -5,3 +7,9 @@ export { configure } from "../configuration"; | ||
export * from "../expect"; | ||
export function marbles(test) { | ||
export function cases(name, func, cases) { | ||
_cases(function (c) { | ||
var t = c.only ? tape.only : c.skip ? tape.skip : tape; | ||
t(name + " / " + c.name, marbles(function (m, t) { return func(m, c, t); })); | ||
}, cases); | ||
} | ||
export function marbles(func) { | ||
return _marbles(function (m, t) { | ||
@@ -12,4 +20,4 @@ m.configure({ | ||
}); | ||
test(m, t); | ||
func(m, t); | ||
}); | ||
} |
{ | ||
"main": "../bundles/rxjs-marbles-tape.umd.js", | ||
"module": "./index.js", | ||
"typings": "./index.d.ts" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
438903
43
13127
270
6