Skip to content

Commit eb30e74

Browse files
authored
Merge pull request #534 from kwonoj/refactor-test-scheduler
2 parents c2922e5 + 054cea2 commit eb30e74

21 files changed

+2176
-1381
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# [2.0.0-beta.3](https://github.com/kwonoj/rx-sandbox/compare/v2.0.0-beta.2...v2.0.0-beta.3) (2020-11-06)
2+
3+
4+
### Bug Fixes
5+
6+
* **sandboxinstance:** expose scheduler instance ([6ada7a5](https://github.com/kwonoj/rx-sandbox/commit/6ada7a52c7e9bd25ae83b41eba1e786b194ffc93))
7+
8+
9+
### Features
10+
11+
* **creattestscheduler:** support flush with native async tick ([93a99a4](https://github.com/kwonoj/rx-sandbox/commit/93a99a45bf63698f4e721a75f85fbf22f74eea68))
12+
* **marbleassert:** jasmine style toEqual() matcher ([6dcc7f8](https://github.com/kwonoj/rx-sandbox/commit/6dcc7f89936f971da66e0e4d0b286203b0fa68b9))
13+
* **sandbox:** accept config object ([3464710](https://github.com/kwonoj/rx-sandbox/commit/346471048564667c3a41df256467299fcb43eaa0))
14+
* **sandbox:** expose interface to create async flush scheduler ([f20fb40](https://github.com/kwonoj/rx-sandbox/commit/f20fb4088ae3fb2d3ee8501fa38b392685a67063))
15+
* **sandbox:** support to create async flush instance ([b9c5e71](https://github.com/kwonoj/rx-sandbox/commit/b9c5e71281cc3fd7def2c39ea94ab21c767585a8))
16+
17+
18+
### BREAKING CHANGES
19+
20+
* **sandboxinstance:** scheduler no longer expose `maxFrame` property. use
21+
property returned by `sandbox.create()`.
22+
* **sandbox:** no longer directly export signatures for utilities,
23+
such as `getMessages` due to overloaded signature behaviors. Use
24+
`RxSandboxInstance['name']` or `RxAsyncSandboxInstance['name']` instead
25+
to pick up signatures.
26+
27+
28+
129
## [1.0.4](https://github.com/kwonoj/rx-sandbox/compare/v1.0.3...v1.0.4) (2020-11-02)
230

331

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ it('testcase', () => {
121121

122122
```typescript
123123
rxSandbox.create(autoFlush?: boolean, frameTimeFactor?: number, maxFrameValue?: number): RxSandboxInstance
124+
125+
rxSandbox.create({
126+
autoFlush?: boolean,
127+
frameTimeFactor?: number,
128+
maxFrameValue?: boolean,
129+
flushWithAsyncTick?: boolean,
130+
}): RxSandboxInstance | RxAsyncSandboxInstance
124131
```
125132

126133
`frameTimeFactor` allows to override default frame passage `1` to given value.
@@ -232,9 +239,33 @@ expect(messages).to.deep.equal(expected);
232239

233240
//subsequent attempt will throw
234241
expect(() => getMessages(e1.mapTo('y'))).to.throw();
242+
```
243+
244+
### Scheduling flush into native async tick (Experimental)
235245

246+
If you create sandbox instance with `flushWithAsyncTick` option, sandbox will return instance of `RxAsyncSandboxInstance` which all of flush interfaces need to be asynchronously awaited:
247+
248+
```
249+
interface RxAsyncSandboxInstance {
250+
...,
251+
advanceTo(toFrame: number) => Promise<void>;
252+
flush: () => Promise<void>;
253+
getMessages: <T = string>(observable: Observable<T>, unsubscriptionMarbles?: string | null) => Promise<void>;
254+
}
236255
```
237256

257+
It is not uncommon practices chaining native async function or promise inside of observables, especially for inner observables. Let's say if there's a redux-observable epic like below
258+
259+
```
260+
const epic = (actionObservable) => actionObservable.ofType(...).pipe((mergeMap) => {
261+
return new Promise.resolve(...);
262+
})
263+
```
264+
265+
Testing this epic via rxSandbox won't work. Once sandbox flush all internal actions synchronously, promises are still scheduled into next tick so there's no inner observable subscription value collected by flush. `RxAsyncSandboxInstance` in opposite no longer flush actions synchronously but schedule each individual action into promise tick to try to collect values from async functions.
266+
267+
**NOTE: this is beta feature and likely have some issues. Also Until stablized internal implementation can change without semver breaking.**
268+
238269
#### Custom frame time factor
239270

240271
Each timeframe `-` is predefined to `1`, can be overridden.

jest.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ module.exports = {
1111
}
1212
},
1313
"bail": true,
14-
"resetMocks": true,
15-
"clearMocks": true,
16-
"resetModules": true,
1714
"testEnvironment": "node",
1815
"moduleFileExtensions": [
1916
"js",

0 commit comments

Comments
 (0)