Gathering detailed insights and metrics for jest-marbles
Gathering detailed insights and metrics for jest-marbles
Gathering detailed insights and metrics for jest-marbles
Gathering detailed insights and metrics for jest-marbles
npm install jest-marbles
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
113 Stars
517 Commits
13 Forks
5 Watching
87 Branches
9 Contributors
Updated on 26 Nov 2024
TypeScript (85.98%)
JavaScript (13.43%)
Shell (0.59%)
Cumulative downloads
Total Downloads
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
1
27
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.
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})
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-----|"
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 });
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:
["-^------------!", "----^---!", "--------^------------!"]
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:
["----^------------!"]
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 })
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
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
8 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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