expect-type
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.7.1](https://github.com/mmkal/ts/compare/expect-type@0.7.0...expect-type@0.7.1) (2020-05-06) | ||
**Note:** Version bump only for package expect-type | ||
# [0.7.0](https://github.com/mmkal/ts/compare/expect-type@0.6.0...expect-type@0.7.0) (2020-05-04) | ||
@@ -8,0 +16,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
test('Type-check object references', () => { | ||
test('Check that two objects have equivalent types to `.toEqualTypeOf`', () => { | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }); | ||
__1.expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 }); | ||
}); | ||
test('`.toEqualTypeOf` succeeds for objects with different values, but the same type', () => { | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }); | ||
}); | ||
test('`.toMatchTypeOf` checks that an object "matches" a type - that is, it has all the expected properties with correct types. This is similar to jest\'s `.toMatchObject`', () => { | ||
__1.expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 }); | ||
}); | ||
test("When there's no instance/runtime variable for the expected type, you can use generics", () => { | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf(); | ||
__1.expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf(); | ||
}); | ||
test('Assertions can be inverted', () => { | ||
@@ -38,3 +46,3 @@ __1.expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 }); | ||
}); | ||
test('Assertions can be inverted with `.not`', () => { | ||
test('Most assertions can be inverted with `.not`', () => { | ||
__1.expectTypeOf(1).not.toBeUnknown(); | ||
@@ -41,0 +49,0 @@ __1.expectTypeOf(1).not.toBeAny(); |
@@ -52,5 +52,15 @@ export declare type Not<T extends boolean> = T extends true ? false : true; | ||
* @example | ||
* expectTypeOf({a: 1}).toMatchTypeOf({a: 2}) | ||
* expectTypeOf({a: 1}).toHaveProperty('a').toBeNumber() | ||
* import {foo, bar} from '../foo' | ||
* import {expectTypeOf} from 'expect-type' | ||
* | ||
* test('foo types', () => { | ||
* // make sure `foo` has type {a: number} | ||
* expectTypeOf(foo).toMatchTypeOf({a: 1}) | ||
* expectTypeOf(foo).toHaveProperty('a').toBeNumber() | ||
* | ||
* // make sure `bar` is a function taking a string: | ||
* expectTypeOf(bar).parameter(0).toBeString() | ||
* expectTypeOf(bar).returns.not.toBeAny() | ||
* }) | ||
* | ||
* @description | ||
@@ -57,0 +67,0 @@ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. |
@@ -11,5 +11,15 @@ "use strict"; | ||
* @example | ||
* expectTypeOf({a: 1}).toMatchTypeOf({a: 2}) | ||
* expectTypeOf({a: 1}).toHaveProperty('a').toBeNumber() | ||
* import {foo, bar} from '../foo' | ||
* import {expectTypeOf} from 'expect-type' | ||
* | ||
* test('foo types', () => { | ||
* // make sure `foo` has type {a: number} | ||
* expectTypeOf(foo).toMatchTypeOf({a: 1}) | ||
* expectTypeOf(foo).toHaveProperty('a').toBeNumber() | ||
* | ||
* // make sure `bar` is a function taking a string: | ||
* expectTypeOf(bar).parameter(0).toBeString() | ||
* expectTypeOf(bar).returns.not.toBeAny() | ||
* }) | ||
* | ||
* @description | ||
@@ -16,0 +26,0 @@ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. |
{ | ||
"name": "expect-type", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"repository": "https://github.com/mmkal/ts", | ||
@@ -21,3 +21,3 @@ "homepage": "https://github.com/mmkal/ts/tree/master/packages/expect-type#readme", | ||
], | ||
"gitHead": "a391629152a361f8d3a724f74d9719b3924e0421" | ||
"gitHead": "050b57202699c8a4ec5f108b944ae1400bdb6d17" | ||
} |
@@ -61,10 +61,27 @@ # expect-type | ||
<!-- codegen:start {preset: markdownFromTests, source: src/__tests__/index.test.ts} --> | ||
Type-check object references: | ||
Check that two objects have equivalent types to `.toEqualTypeOf`: | ||
```typescript | ||
expectTypeOf({a: 1}).toEqualTypeOf({a: 1}) | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf({a: 1}) | ||
``` | ||
`.toEqualTypeOf` succeeds for objects with different values, but the same type: | ||
```typescript | ||
expectTypeOf({a: 1}).toEqualTypeOf({a: 2}) | ||
``` | ||
`.toMatchTypeOf` checks that an object "matches" a type - that is, it has all the expected properties with correct types. This is similar to jest's `.toMatchObject`: | ||
```typescript | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf({a: 1}) | ||
``` | ||
When there's no instance/runtime variable for the expected type, you can use generics: | ||
```typescript | ||
expectTypeOf({a: 1}).toEqualTypeOf<{a: number}>() | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf<{a: number}>() | ||
``` | ||
Assertions can be inverted: | ||
@@ -113,3 +130,3 @@ | ||
Assertions can be inverted with `.not`: | ||
Most assertions can be inverted with `.not`: | ||
@@ -116,0 +133,0 @@ ```typescript |
import {expectTypeOf} from '..' | ||
test('Type-check object references', () => { | ||
test('Check that two objects have equivalent types to `.toEqualTypeOf`', () => { | ||
expectTypeOf({a: 1}).toEqualTypeOf({a: 1}) | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf({a: 1}) | ||
}) | ||
test('`.toEqualTypeOf` succeeds for objects with different values, but the same type', () => { | ||
expectTypeOf({a: 1}).toEqualTypeOf({a: 2}) | ||
}) | ||
test('`.toMatchTypeOf` checks that an object "matches" a type - that is, it has all the expected properties with correct types. This is similar to jest\'s `.toMatchObject`', () => { | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf({a: 1}) | ||
}) | ||
test("When there's no instance/runtime variable for the expected type, you can use generics", () => { | ||
expectTypeOf({a: 1}).toEqualTypeOf<{a: number}>() | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf<{a: number}>() | ||
}) | ||
test('Assertions can be inverted', () => { | ||
@@ -44,3 +55,3 @@ expectTypeOf({a: 1}).not.toMatchTypeOf({b: 1}) | ||
test('Assertions can be inverted with `.not`', () => { | ||
test('Most assertions can be inverted with `.not`', () => { | ||
expectTypeOf(1).not.toBeUnknown() | ||
@@ -47,0 +58,0 @@ expectTypeOf(1).not.toBeAny() |
@@ -74,5 +74,15 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
* @example | ||
* expectTypeOf({a: 1}).toMatchTypeOf({a: 2}) | ||
* expectTypeOf({a: 1}).toHaveProperty('a').toBeNumber() | ||
* import {foo, bar} from '../foo' | ||
* import {expectTypeOf} from 'expect-type' | ||
* | ||
* test('foo types', () => { | ||
* // make sure `foo` has type {a: number} | ||
* expectTypeOf(foo).toMatchTypeOf({a: 1}) | ||
* expectTypeOf(foo).toHaveProperty('a').toBeNumber() | ||
* | ||
* // make sure `bar` is a function taking a string: | ||
* expectTypeOf(bar).parameter(0).toBeString() | ||
* expectTypeOf(bar).returns.not.toBeAny() | ||
* }) | ||
* | ||
* @description | ||
@@ -79,0 +89,0 @@ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218331
3316
253