Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
purify-asserts
Advanced tools
Jest expectations for the purify-ts library
Purify is an excellent library for functional TypeScript applications, but its algebraic data types are not so obvious to test. Specifically, the following convention examples are not easy to remember in the scope of unit tests.
expect(maybe.isJust()).toBe(true);
expect(maybe.isNothing()).toBe(true);
expect(maybe.extract()).toEqual("value");
expect(either.isLeft()).toBe(false);
expect(either.isRight()).toBe(true);
expect(either.extract()).toEqual("is this success or error?");
Wouldn't it be more satisfying to assert expectations with the same domain language Purify speaks of? I think so.
expect(possiblyNullableMaybe).toBeJust();
expect(justOrNothing).toBeNothing();
expect(justOrNothing).toHaveJustValue(1);
npm install --save-dev purify-asserts
yarn add --dev purify-asserts
Using matchers requires to use the expect.extend()
method of Jest. These should be imported and used at the beginning of your test suite above the first describe()
block.
Import all of the matchers:
import * as matchers from "purify-asserts";
expect.extend(matchers);
Import only selected matchers:
import { toBeJust, toBeNothing } from "purify-asserts";
expect.extend({ toBeJust, toBeNothing });
Maybe<T>
matchersEither<L, R>
matchers (work in progress)MaybeAsync<T>
matchers (work in progress)EitherAsync<L, R>
matchers (work in progress)Tuple<F, S>
matchers (work in progress)NonEmptyList<T>
matchers (work in progress)Codec<T>
matchers (work in progress)👤 Niko Heikkilä yo@nikoheikkila.fi
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
FAQs
Jest expectations for the purify-ts library
The npm package purify-asserts receives a total of 13 weekly downloads. As such, purify-asserts popularity was classified as not popular.
We found that purify-asserts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.