All Projects → just-jeb → Jest Marbles

just-jeb / Jest Marbles

Licence: mit
Helpers library for marbles testing with Jest

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Jest Marbles

Rxjs Marbles
An RxJS marble testing library for any test framework
Stars: ✭ 267 (+214.12%)
Mutual labels:  rxjs, jest
ng-nest-cnode
Angular 10 Front-End and Nestjs 7 framework Back-End build Fullstack CNode
Stars: ✭ 17 (-80%)
Mutual labels:  rxjs, jest
React-Redux-Enterprise
A React-Redux boilerplate for enterprise/large scaled web applications
Stars: ✭ 77 (-9.41%)
Mutual labels:  rxjs, jest
Coderplanets web
the most sexiest community for developers, build with React, Mobx/MST, GraphQL, Styled-Components, Rxjs, Ramda ... and ❤️
Stars: ✭ 314 (+269.41%)
Mutual labels:  rxjs, jest
Babel Test
An opinionated library to make testing babel plugins easier.
Stars: ✭ 79 (-7.06%)
Mutual labels:  jest
Tibot
TiBot — The Date and Time Bot
Stars: ✭ 74 (-12.94%)
Mutual labels:  rxjs
Ant Simple Pro
简洁,美观,快速上手,支持3大框架(vue3.0,react,angular,typescript);Concise, beautiful, quick to get started, support 3 big frameworks
Stars: ✭ 73 (-14.12%)
Mutual labels:  rxjs
Karmatic
🦑 Easy automatic (headless) browser testing with Jest's API, but powered by Karma & Webpack.
Stars: ✭ 1,178 (+1285.88%)
Mutual labels:  jest
Fullstack Shopping Cart
MERN stack shopping cart, written in TypeScript
Stars: ✭ 82 (-3.53%)
Mutual labels:  jest
Time
A time driver designed to enable awesome testing and dev tooling
Stars: ✭ 80 (-5.88%)
Mutual labels:  rxjs
Graphql Rxjs
fork of Graphql which adds Observable support
Stars: ✭ 78 (-8.24%)
Mutual labels:  rxjs
Game Music Player
All your music are belong to us
Stars: ✭ 76 (-10.59%)
Mutual labels:  rxjs
Hacker News Resolve
React & Redux & Resolve implementation of Hacker News
Stars: ✭ 79 (-7.06%)
Mutual labels:  jest
Jest Action
Wraps and install Jest test runner in a github action.
Stars: ✭ 74 (-12.94%)
Mutual labels:  jest
Dockest
Docker + Jest integration testing for Node.js
Stars: ✭ 81 (-4.71%)
Mutual labels:  jest
Starter Lapis
Cutting edge starter kit
Stars: ✭ 72 (-15.29%)
Mutual labels:  jest
Mostly
They mostly come at night; mostly.
Stars: ✭ 78 (-8.24%)
Mutual labels:  jest
Alias Hq
The end-to-end solution for configuring, refactoring, maintaining and using path aliases
Stars: ✭ 77 (-9.41%)
Mutual labels:  jest
Gatsby Themes
Get high-quality and customizable Gatsby themes to quickly bootstrap your website! Choose from many professionally created and impressive designs with a wide variety of features and customization options.
Stars: ✭ 1,208 (+1321.18%)
Mutual labels:  jest
Rxjs Book
rxjs-book 책 예제
Stars: ✭ 77 (-9.41%)
Mutual labels:  rxjs

jest-marbles

npm version Build Status Packagist Conventional Commits

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

Usage

For RxJs 5:

npm i [email protected] -D

For RxJs 6:

npm i [email protected] -D

In the test file:

import {cold, hot, time} from 'jest-marbles';

Inside the test:

expect(stream).toBeObservable(expected);
expect(stream).toBeMarble(marbleString);
expect(stream).toHaveSubscriptions(marbleString);
expect(stream).toHaveSubscriptions(marbleStringsArray);
expect(stream).toHaveNoSubscriptions();
expect(stream).toSatisfyOnFlush(() => {
  expect(someMock).toHaveBeenCalled();
})

Examples

toBeObservable

Verifies that the resulting stream emits certain values at certain time frames

    it('Should merge two hot observables and start emitting from the subscription point', () => {
        const e1 = hot('----a--^--b-------c--|', {a: 0});
        const e2 = hot('  ---d-^--e---------f-----|', {a: 0});
        const expected = cold('---(be)----c-f-----|', {a: 0});

        expect(e1.pipe(merge(e2))).toBeObservable(expected);
    });

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

    it('Should concatenate two cold observables into single cold observable', () => {
        const a = cold('-a-|');
        const b = cold('-b-|');
        const expected = '-a--b-|';
        expect(a.pipe(concat(b))).toBeMarble(expected);
    });

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:

  it('Should figure out single subscription points', () => {
    const x = cold('        --a---b---c--|');
    const xsubs = '   ------^-------!';
    const y = cold('                ---d--e---f---|');
    const ysubs = '   --------------^-------------!';
    const e1 = hot('  ------x-------y------|', { x, y });
    const expected = cold('--------a---b----d--e---f---|');

    expect(e1.pipe(switchAll())).toBeObservable(expected);
    expect(x).toHaveSubscriptions(xsubs);
    expect(y).toHaveSubscriptions(ysubs);
  });

The matcher can also accept multiple subscription marbles:

  it('Should figure out multiple subscription points', () => {
    const x = cold('                    --a---b---c--|');

    const y = cold('                ----x---x|', {x});
    const ySubscription1 = '        ----^---!';
    //                                     '--a---b---c--|'
    const ySubscription2 = '        --------^------------!';
    const expectedY = cold('        ------a---a---b---c--|');
	
    const z = cold('                   -x|', {x});
    //                                 '--a---b---c--|'
    const zSubscription = '            -^------------!';
    const expectedZ = cold('           ---a---b---c--|');

    expect(y.pipe(switchAll())).toBeObservable(expectedY);
    expect(z.pipe(switchAll())).toBeObservable(expectedZ);

    expect(x).toHaveSubscriptions([ySubscription1, ySubscription2, zSubscription]);
  });

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:

  it('Should verify that switchMap was not performed due to an error', () => {
    const x = cold('--a---b---c--|');
    const y = cold('---#-x--', {x});
    const result = y.pipe(switchAll());
    expect(result).toBeMarble('---#');
    expect(x).toHaveNoSubscriptions();
  });

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)

  it('should verify mock has been called', () => {
      const mock = jest.fn();
      const stream$ = cold('blah|').pipe(tap(mock));
      expect(stream$).toSatisfyOnFlush(() => {
          expect(mock).toHaveBeenCalledTimes(4);
      });
  })
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].