
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@rxreact/jest-helpers
Advanced tools
RxReact/Jest Helpers are simple tools for testing RxJS observables. This can be useful any project, not just React.
In your project:
npm install @rxreact/jest-helpers --save
or
yarn add @rxreact/jest-helpers
RxJS and Jest are peer dependencies and need to be installed separately.
Then import the library:
import { watchSignal } from "@rxreact/jest-helpers";
This library adds a function for making an observable hot, and adds two matchers to Jest to checking if an observable has emitted a value.
If you have used expect(jest.fn()).toHaveBeenCalled() and expect(jest.fn()).toHaveBeenCalledWith(value), these helpers should feel familiar.
To check if an observable emitted any value:
await expect(of("a")).toEmit();
await expect(of("a")).toEmitValue("a");
await expect(never()).not.toEmit();
await expect(of("a")).not.toEmitValue("b");
Often observables are cold - they will forget any values they might have emitted before something subscribes to them. To get around this, you can use watchSignal to get a hot version of the observable with shareReplay, which will record everything the observable emits.
watchSignal cleans up after itself after every test to prevent memory leaks. So, make sure to only call watchSignal in a beforeEach or a test body.
import { Subject } from "rxjs";
import { watchSignal } from "./jest-helpers";
it("watches a cold signal", async () => {
const subject$ = new Subject<string>();
const hot$ = watchSignal(subject$);
// Hasn't emitted yet
await expect(hot$).not.toEmit();
// Make subject$ emit a value.
subject$.next("a");
// A cold subject loses all values.
await expect(subject$).not.toEmitValue("a");
// A hot watched signal remembers values.
await expect(hot$).toEmitValue("a");
});
To use the expect(observable$).toEmit() and expect(observable$).toEmitValue(value) functions in your test, you must import the library in the test file.
If you need watchSignal (and you probably will), simply importing it will do the job:
import { watchSignal } from "@rxreact/jest-helpers";
If you have a test that only tests hot signals, you will still need to import the library to you test file to get the jest extensions:
import "@rxreact/jest-helpers";
.toEmit() / toEitValue() work by waiting 100 ms for the observable to emit, to account for asynchronous observables. So you must await every expectation, to make sure you catch failures:
await expect(o$).toEmit();
FAQs
Helpers for using Jest to test RxJS observables
The npm package @rxreact/jest-helpers receives a total of 118 weekly downloads. As such, @rxreact/jest-helpers popularity was classified as not popular.
We found that @rxreact/jest-helpers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.