Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assertive-ts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assertive-ts

A type-safe fluent assertion library

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

All Contributors

Build

AssertiveTS

A type-safe fluent assertion library written in TypeScript and inspired by Jest assertions and the popular AssertJ.

This library is designed to work in the browser and in Node.js. It ships with a rich set of expressive and flexible matchers that allows chaining multiple assertions. AssertiveTS is framework agnostic and should be used with a test framework such as Jest, Mocha, or Ava.

Type-safe library

A distinctive feature of AssertiveTS with other assertion libraries is that it leverages the TypeScript compiler to avoid type coercions and mismatches. It also infers the static type of the value you want to assert and provides you with intelligent matcher completion and signature help so that you can write code more quickly and correctly.

Features

  • Type safety and intelligent matcher completion
  • Rich set of expressive and flexible matchers
  • Concise, chainable interface inspired by AssertJ
  • Works with any test runner and framework such as Jest, Mocha, or Ava
  • Well tested: more than 300 tests!

Install

npm install --save-dev @stackbuilders/assertive-ts

Or:

yarn add --dev @stackbuilders/assertive-ts

Usage

Import the library in your test script:

import { expect } from "@stackbuilders/assertive-ts"

Use the expect function along with a "matcher" function on the value you want to assert:

expect(sum(1, 2)).toBeEqual(3);

To assert the opposite, just add .not before a matcher:

expect(sum(1, 2)).not.toBeNull();

With assertive-ts you can use fluent assertions, which means you can chain multiple matcher functions to the same value under test:

expect("assertive-ts is awesome!")
  .toStartWith("assertive-ts")
  .not.toContain("unsafe")
  .toEndWith("awesome!");

The matcher functions depend on the type of the value on the expect. If you're using TypeScript, the compiler will let you know if something is not available for that assertion:

// Boolean assertion
expect(isEven(2)).toBeTrue();

// String assertion
expect("foobar").toStartWith("foo");

// Number assertion
expect(sum(1, 2)).toBePositive();

expect(14).toEndWith("4");
           ^ ? type error: `toEndWith` does not exist in `NumberAssertion`

For a list of all matchers and extended documentation, please refer to the API documentation.

Test Runner Integration

API Reference

You can find the full API reference here

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Jose Luis Leon

💻 🚇 🚧 📦 ⚠️

Byron Motoche

💻 ⚠️

Alejandro Vivanco

💻 ⚠️

David Villamarin

💻 ⚠️

Alexander Mejía

💻 ⚠️

Christian Samaniego

📖 💻 ⚠️

Sebastián Estrella

🚇

Daniel Calle

🚇

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT, see the LICENSE file.

Contributing

Do you want to contribute to this project? Please take a look at our contributing guideline to know how you can help us build it.


Stack Builders

Check out our libraries | Join our team

FAQs

Package last updated on 25 Aug 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc