New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lukemorales/jest-type-matchers

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lukemorales/jest-type-matchers - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

45

dist/index.d.ts

@@ -8,3 +8,3 @@ /**

*/
interface TypeMatchers<R, X> {
interface TypeMatchers<Void, Left> {
/**

@@ -14,5 +14,11 @@ * Assert that the received variable has the expected type.

* @example
* expect(true).toHaveType<boolean>()
* expect(true).toHaveType<boolean>();
*
* @example
* type Result = { ok: boolean } & { data: null };
*
* const res: Result = { ok: true, data: null };
* expect(res).toHaveType<{ ok: boolean; data: null }>();
*/
toHaveType<Y extends Equal<X, Y> extends true ? X : never>(): R;
toHaveType<Right extends Alike<Left, Right> extends true ? Left : never>(): Void;
/**

@@ -22,5 +28,25 @@ * Assert that the received variable does not have the expected type.

* @example
* expect('hello world').toNotHaveType<number>()
* expect('hello world').toNotHaveType<number>();
*/
toNotHaveType<Y extends NotEqual<X, Y> extends true ? any : never>(): R;
toNotHaveType<Right extends Unlike<Left, Right> extends true ? any : never>(): Void;
/**
* Assert that the received variable is strictly equal to the expected type.
*
* @example
* expect(true).toHaveStrictType<boolean>();
*
* @example
* type Result = { ok: boolean } & { data: null };
*
* const res: Result = { ok: true, data: null };
* expect(res).toHaveStrictType<{ ok: boolean } & { data: null }>();
*/
toHaveStrictType<Right extends Equal<Left, Right> extends true ? Left : never>(): Void;
/**
* Assert that the received variable is not strictly equal to the expected type.
*
* @example
* expect('hello world').toNotHaveStrictType<number>();
*/
toNotHaveStrictType<Right extends NotEqual<Left, Right> extends true ? any : never>(): Void;
}

@@ -32,4 +58,9 @@ /**

*/
declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
declare type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
declare type Equal<Left, Right> = (<T>() => T extends Left ? 1 : 2) extends <T>() => T extends Right ? 1 : 2 ? true : false;
declare type NotEqual<Left, Right> = true extends Equal<Left, Right> ? false : true;
declare type MergeInsertions<T> = T extends object ? {
[K in keyof T]: MergeInsertions<T[K]>;
} : T;
declare type Alike<Left, Right> = Equal<MergeInsertions<Left>, Right>;
declare type Unlike<Left, Right> = NotEqual<MergeInsertions<Left>, Right>;

@@ -36,0 +67,0 @@ declare global {

2

dist/index.js

@@ -1,2 +0,2 @@

"use strict";var c=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var u=(e,t,p,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!h.call(e,r)&&r!==p&&c(e,r,{get:()=>t[r],enumerable:!(s=n(t,r))||s.enumerable});return e};var d=e=>u(c({},"__esModule",{value:!0}),e);var x={};module.exports=d(x);var a=e=>({pass:!0,message:()=>e}),o={toHaveType(e){return a("received value does not match the expected type")},toNotHaveType(e){return a("received value matches the expected type")}};expect.extend(o);
"use strict";var s=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var d=(e,t,p,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of h(t))!y.call(e,r)&&r!==p&&s(e,r,{get:()=>t[r],enumerable:!(a=n(t,r))||a.enumerable});return e};var u=e=>d(s({},"__esModule",{value:!0}),e);var i={};module.exports=u(i);var c=e=>({pass:!0,message:()=>e}),o={toHaveType(e){return c("received value does not match the expected type")},toNotHaveType(e){return c("received value matches the expected type")},toHaveStrictType(e){return c("received value does not match the expected strict type")},toNotHaveStrictType(e){return c("received value matches the expected strict type")}};expect.extend(o);
//# sourceMappingURL=index.js.map
{
"name": "@lukemorales/jest-type-matchers",
"version": "0.1.0",
"version": "0.2.0",
"author": "Luke Morales <lukemorales@live.com>",

@@ -5,0 +5,0 @@ "description": "Custom jest matchers to test the state of your types",

@@ -52,2 +52,7 @@ <p align="center">

expect(true).toHaveType<boolean>();
type Result = { ok: boolean } & { data: null };
const res: Result = { ok: true, data: null };
expect(res).toHaveType<{ ok: boolean; data: null }>();
```

@@ -61,1 +66,18 @@ This allows you to check that a variable has an expected type.

This allows you to check that a variable does not have a specific type.
#### `toHaveStrictType`
```ts
expect(true).toHaveStrictType<boolean>();
type Result = { ok: boolean } & { data: null };
const res: Result = { ok: true, data: null };
expect(res).toHaveStrictType<{ ok: boolean } & { data: null }>();
```
This allows you to check that a variable is strict equal to an expected type.
#### `toNotHaveStrictType`
```ts
expect('hello world').toNotHaveStrictType<number>();
```
This allows you to check that a variable is not strict equal to a specific type.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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