
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@lukemorales/jest-type-matchers
Advanced tools
Custom jest matchers to test the state of your types.
  You write Typescript and want assert various things about the state of your types?
This library provides a set of custom matchers that you can use to extend jest
and assert your test results against expected types.
This library is available as a package on NPM, install with your favorite package manager:
npm install --save-dev @lukemorales/jest-type-matchers
Import @lukemorales/jest-type-matchers once in your tests setup
file:
// In your jest-setup.ts (or any other name)
import '@lukemorales/jest-type-matchers';
// In jest.config.js add (if you haven't already)
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts']
These custom matchers allow you to just check your types. This means that they will never fail your test suite because type-checking happens at compile-time only.
toHaveTypeexpect(true).toHaveType<boolean>();
type Result = { ok: boolean } & { data: null };
expect<Result>({ ok: true, data: null }).toHaveType<{ ok: boolean; data: null }>();
This allows you to check that a variable has an expected type.
toNotHaveTypeexpect('hello world').toNotHaveType<number>();
This allows you to check that a variable does not have a specific type.
toHaveStrictTypeexpect(true).toHaveStrictType<boolean>();
type Result = { ok: boolean } & { data: null };
expect<Result>({ ok: true, data: null }).toHaveStrictType<{ ok: boolean } & { data: null }>();
This allows you to check that a variable is strict equal to an expected type.
toNotHaveStrictTypeexpect('hello world').toNotHaveStrictType<number>();
This allows you to check that a variable is not strict equal to a specific type.
FAQs
Custom jest matchers to test the state of your types
We found that @lukemorales/jest-type-matchers 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.