https://github.com/tjoskar/marble-test
Helps you write marble tests
https://github.com/tjoskar/marble-test
marble rxjs testing
Last synced: 11 months ago
JSON representation
Helps you write marble tests
- Host: GitHub
- URL: https://github.com/tjoskar/marble-test
- Owner: tjoskar
- License: mit
- Created: 2017-02-25T16:07:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-04T10:53:26.000Z (about 7 years ago)
- Last Synced: 2025-07-07T15:17:39.981Z (12 months ago)
- Topics: marble, rxjs, testing
- Language: TypeScript
- Size: 151 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
> Helps you write marble tests
## Install
```
$ npm install --save-dev marble-test
```
## Example usage
```js
import { createRxTestScheduler } from 'marble-test'
const mapToNumber$ = string$ => string$.pipe(map(s => Number(s)))
test('map to number', () => {
// Arrange
const scheduler = createRxTestScheduler()
const values = { a: '1', b: '2', 1: 1, 2: 2 }
const input = 'a--b|'
const output = '1--2|'
const strings$ = scheduler.createColdObservable(input, values)
// Act
const obs = mapToNumber$(strings$)
// Assert
scheduler.expectObservable(obs).toBe(output, values)
scheduler.flush()
})
```
### With jest
```js
import { marble } from 'marble-test/jest'
const mapToNumber$ = string$ => string$.pipe(map(s => Number(s)))
marble('map to number', m => {
// Arrange
const values = { a: '1', b: '2', 1: 1, 2: 2 }
const input = 'a--b|'
const output = '1--2|'
const strings$ = m.cold(input, values)
// Act
const obs = mapToNumber$(strings$)
// Assert
m.expectObservable(obs).toBe(output, values)
})
```
See the [test file](src/__tests__/test.ts) for more examples
Gives detailed outputs on assert failure.
e.g., You will get the following output when changing `output` above to `a--2|`

## API
### createRxTestScheduler()
Returns a `TestScheduler` (https://github.com/ReactiveX/rxjs/blob/master/src/testing/TestScheduler.ts)
See https://github.com/ReactiveX/rxjs/blob/master/doc/writing-marble-tests.md for more info