Installations
npm install jest-marbles
Developer
meltedspark
Developer Guide
Module System
CommonJS
Min. Node Version
>=18
Typescript Support
No
Node Version
18.19.1
NPM Version
10.2.4
Statistics
113 Stars
517 Commits
13 Forks
5 Watching
87 Branches
9 Contributors
Updated on 26 Nov 2024
Languages
TypeScript (85.98%)
JavaScript (13.43%)
Shell (0.59%)
Total Downloads
Cumulative downloads
Total Downloads
10,280,081
Last day
5.7%
13,314
Compared to previous day
Last week
3.2%
65,007
Compared to previous week
Last month
8.6%
268,553
Compared to previous month
Last year
-3.4%
2,814,579
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
27
jest-marbles
A set of helper functions and Jest matchers for RxJs marble testing. This library will help you to test your reactive code in easy and clear way.
Features
- Typescript
- Marblized error messages
Prerequisites
- Jest
- RxJs
- Familiarity with marbles syntax
Not supported (but planning to)
- Time progression syntax
Usage
For RxJs 7:
1npm i jest-marbles@latest -D
For RxJs 6:
1npm i jest-marbles@2 -D
For RxJs 5:
1npm i jest-marbles@1 -D
In the test file:
1import {cold, hot, time, schedule} from 'jest-marbles';
Inside the test:
1expect(stream).toBeObservable(expected); 2expect(stream).toBeMarble(marbleString); 3expect(stream).toHaveSubscriptions(marbleString); 4expect(stream).toHaveSubscriptions(marbleStringsArray); 5expect(stream).toHaveNoSubscriptions(); 6expect(stream).toSatisfyOnFlush(() => { 7 expect(someMock).toHaveBeenCalled(); 8})
Examples
toBeObservable
Verifies that the resulting stream emits certain values at certain time frames
1 it('Should merge two hot observables and start emitting from the subscription point', () => { 2 const e1 = hot('----a--^--b-------c--|', {a: 0}); 3 const e2 = hot(' ---d-^--e---------f-----|', {a: 0}); 4 const expected = cold('---(be)----c-f-----|', {a: 0}); 5 6 expect(e1.pipe(merge(e2))).toBeObservable(expected); 7 });
Sample output when the test fails (if change the expected result to '-d--(be)----c-f-----|'
):
Expected notifications to be:
"-d--(be)----c-f-----|"
But got:
"---(be)----c-f-----|"
toBeMarble
Same as toBeObservable
but receives marble string instead
1 it('Should concatenate two cold observables into single cold observable', () => { 2 const a = cold('-a-|'); 3 const b = cold('-b-|'); 4 const expected = '-a--b-|'; 5 expect(a.pipe(concat(b))).toBeMarble(expected); 6 });
toHaveSubscriptions
Verifies that the observable was subscribed in the provided time frames.
Useful, for example, when you want to verify that particular switchMap
worked as expected:
1 it('Should figure out single subscription points', () => { 2 const x = cold(' --a---b---c--|'); 3 const xsubs = ' ------^-------!'; 4 const y = cold(' ---d--e---f---|'); 5 const ysubs = ' --------------^-------------!'; 6 const e1 = hot(' ------x-------y------|', { x, y }); 7 const expected = cold('--------a---b----d--e---f---|'); 8 9 expect(e1.pipe(switchAll())).toBeObservable(expected); 10 expect(x).toHaveSubscriptions(xsubs); 11 expect(y).toHaveSubscriptions(ysubs); 12 });
The matcher can also accept multiple subscription marbles:
1 it('Should figure out multiple subscription points', () => { 2 const x = cold(' --a---b---c--|'); 3 4 const y = cold(' ----x---x|', {x}); 5 const ySubscription1 = ' ----^---!'; 6 // '--a---b---c--|' 7 const ySubscription2 = ' --------^------------!'; 8 const expectedY = cold(' ------a---a---b---c--|'); 9 10 const z = cold(' -x|', {x}); 11 // '--a---b---c--|' 12 const zSubscription = ' -^------------!'; 13 const expectedZ = cold(' ---a---b---c--|'); 14 15 expect(y.pipe(switchAll())).toBeObservable(expectedY); 16 expect(z.pipe(switchAll())).toBeObservable(expectedZ); 17 18 expect(x).toHaveSubscriptions([ySubscription1, ySubscription2, zSubscription]); 19 });
Sample output when the test fails (if change ySubscription1
to '-----------------^---!'
):
Expected observable to have the following subscription points:
["-----------------^---!", "--------^------------!", "-^------------!"]
But got:
["-^------------!", "----^---!", "--------^------------!"]
toHaveNoSubscriptions
Verifies that the observable was not subscribed during the test. Especially useful when you want to verify that certain chain was not called due to an error:
1 it('Should verify that switchMap was not performed due to an error', () => { 2 const x = cold('--a---b---c--|'); 3 const y = cold('---#-x--', {x}); 4 const result = y.pipe(switchAll()); 5 expect(result).toBeMarble('---#'); 6 expect(x).toHaveNoSubscriptions(); 7 });
Sample output when the test fails (if remove error and change the expected marble to '------a---b---c--|'
):
Expected observable to have no subscription points
But got:
["----^------------!"]
toSatisfyOnFlush
Allows you to assert on certain side effects/conditions that should be satisfied when the observable has been flushed (finished)
1 it('should verify mock has been called', () => { 2 const mock = jest.fn(); 3 const stream$ = cold('blah|').pipe(tap(mock)); 4 expect(stream$).toSatisfyOnFlush(() => { 5 expect(mock).toHaveBeenCalledTimes(4); 6 }); 7 })
schedule
Allows you to schedule task on specified frame
1 it('should verify subject values', () => { 2 const source = new Subject(); 3 const expected = cold('ab'); 4 5 schedule(() => source.next('a'), 1); 6 schedule(() => source.next('b'), 2); 7 8 expect(source).toBeObservable(expected); 9 });
No vulnerabilities found.
Reason
28 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/build.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/just-jeb/jest-marbles/release.yml/master?enable=pin
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Score
4.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More