expect-type
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.7.2](https://github.com/mmkal/ts/compare/expect-type@0.7.1...expect-type@0.7.2) (2020-05-08) | ||
**Note:** Version bump only for package expect-type | ||
## [0.7.1](https://github.com/mmkal/ts/compare/expect-type@0.7.0...expect-type@0.7.1) (2020-05-06) | ||
@@ -8,0 +16,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
test('Check that two objects have equivalent types to `.toEqualTypeOf`', () => { | ||
test('Check that two objects have equivalent types with `.toEqualTypeOf`', () => { | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }); | ||
@@ -10,12 +10,27 @@ }); | ||
}); | ||
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', () => { | ||
test('`.toEqualTypeOf` fails on extra properties', () => { | ||
// @ts-expect-error | ||
__1.expectTypeOf({ a: 1, b: 1 }).toEqualTypeOf({ a: 1 }); | ||
}); | ||
test('To allow for extra properties, use `.toMatchTypeOf`. This checks that an object "matches" a type. This is similar to jest\'s `.toMatchObject`', () => { | ||
__1.expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 }); | ||
}); | ||
test('Another example of the difference between `.toMatchTypeOf` and `.toEqualTypeOf`, using generics. `.toMatchTypeOf` can be used for "is-a" relationships', () => { | ||
__1.expectTypeOf().toMatchTypeOf(); | ||
// @ts-expect-error | ||
__1.expectTypeOf().toMatchTypeOf(); | ||
// @ts-expect-error | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
}); | ||
test('Assertions can be inverted with `.not`', () => { | ||
__1.expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 }); | ||
}); | ||
test('`.not` can be easier than relying on `// @ts-expect-error`', () => { | ||
__1.expectTypeOf().toMatchTypeOf(); | ||
__1.expectTypeOf().not.toMatchTypeOf(); | ||
__1.expectTypeOf().not.toEqualTypeOf(); | ||
}); | ||
test('Catch any/unknown/never types', () => { | ||
@@ -47,3 +62,3 @@ __1.expectTypeOf().toBeUnknown(); | ||
}); | ||
test('Most assertions can be inverted with `.not`', () => { | ||
test('More `.not` examples', () => { | ||
__1.expectTypeOf(1).not.toBeUnknown(); | ||
@@ -50,0 +65,0 @@ __1.expectTypeOf(1).not.toBeAny(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.expectTypeOf = void 0; | ||
const secret = Symbol('secret'); | ||
@@ -4,0 +5,0 @@ const fn = () => true; |
{ | ||
"name": "expect-type", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"repository": "https://github.com/mmkal/ts", | ||
@@ -21,3 +21,3 @@ "homepage": "https://github.com/mmkal/ts/tree/master/packages/expect-type#readme", | ||
], | ||
"gitHead": "050b57202699c8a4ec5f108b944ae1400bdb6d17" | ||
"gitHead": "8c79e64c8aefcab1fca3ec0c60277b0c21926cd4" | ||
} |
@@ -61,3 +61,3 @@ # expect-type | ||
<!-- codegen:start {preset: markdownFromTests, source: src/__tests__/index.test.ts} --> | ||
Check that two objects have equivalent types to `.toEqualTypeOf`: | ||
Check that two objects have equivalent types with `.toEqualTypeOf`: | ||
@@ -74,16 +74,37 @@ ```typescript | ||
`.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`: | ||
When there's no instance/runtime variable for the expected type, you can use generics: | ||
```typescript | ||
expectTypeOf({a: 1}).toEqualTypeOf<{a: number}>() | ||
``` | ||
`.toEqualTypeOf` fails on extra properties: | ||
```typescript | ||
// @ts-expect-error | ||
expectTypeOf({a: 1, b: 1}).toEqualTypeOf({a: 1}) | ||
``` | ||
To allow for extra properties, use `.toMatchTypeOf`. This checks that an object "matches" a type. 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: | ||
Another example of the difference between `.toMatchTypeOf` and `.toEqualTypeOf`, using generics. `.toMatchTypeOf` can be used for "is-a" relationships: | ||
```typescript | ||
expectTypeOf({a: 1}).toEqualTypeOf<{a: number}>() | ||
expectTypeOf({a: 1, b: 1}).toMatchTypeOf<{a: number}>() | ||
type Fruit = {type: 'Fruit'; edible: boolean} | ||
type Apple = {type: 'Fruit'; name: 'Apple'; edible: true} | ||
expectTypeOf<Apple>().toMatchTypeOf<Fruit>() | ||
// @ts-expect-error | ||
expectTypeOf<Fruit>().toMatchTypeOf<Apple>() | ||
// @ts-expect-error | ||
expectTypeOf<Apple>().toEqualTypeOf<Fruit>() | ||
``` | ||
Assertions can be inverted: | ||
Assertions can be inverted with `.not`: | ||
@@ -94,2 +115,14 @@ ```typescript | ||
`.not` can be easier than relying on `// @ts-expect-error`: | ||
```typescript | ||
type Fruit = {type: 'Fruit'; edible: boolean} | ||
type Apple = {type: 'Fruit'; name: 'Apple'; edible: true} | ||
expectTypeOf<Apple>().toMatchTypeOf<Fruit>() | ||
expectTypeOf<Fruit>().not.toMatchTypeOf<Apple>() | ||
expectTypeOf<Apple>().not.toEqualTypeOf<Fruit>() | ||
``` | ||
Catch any/unknown/never types: | ||
@@ -132,3 +165,3 @@ | ||
Most assertions can be inverted with `.not`: | ||
More `.not` examples: | ||
@@ -135,0 +168,0 @@ ```typescript |
import {expectTypeOf} from '..' | ||
test('Check that two objects have equivalent types to `.toEqualTypeOf`', () => { | ||
test('Check that two objects have equivalent types with `.toEqualTypeOf`', () => { | ||
expectTypeOf({a: 1}).toEqualTypeOf({a: 1}) | ||
@@ -11,15 +11,42 @@ }) | ||
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`', () => { | ||
test("When there's no instance/runtime variable for the expected type, you can use generics", () => { | ||
expectTypeOf({a: 1}).toEqualTypeOf<{a: number}>() | ||
}) | ||
test('`.toEqualTypeOf` fails on extra properties', () => { | ||
// @ts-expect-error | ||
expectTypeOf({a: 1, b: 1}).toEqualTypeOf({a: 1}) | ||
}) | ||
test('To allow for extra properties, use `.toMatchTypeOf`. This checks that an object "matches" a type. 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('Another example of the difference between `.toMatchTypeOf` and `.toEqualTypeOf`, using generics. `.toMatchTypeOf` can be used for "is-a" relationships', () => { | ||
type Fruit = {type: 'Fruit'; edible: boolean} | ||
type Apple = {type: 'Fruit'; name: 'Apple'; edible: true} | ||
expectTypeOf<Apple>().toMatchTypeOf<Fruit>() | ||
// @ts-expect-error | ||
expectTypeOf<Fruit>().toMatchTypeOf<Apple>() | ||
// @ts-expect-error | ||
expectTypeOf<Apple>().toEqualTypeOf<Fruit>() | ||
}) | ||
test('Assertions can be inverted', () => { | ||
test('Assertions can be inverted with `.not`', () => { | ||
expectTypeOf({a: 1}).not.toMatchTypeOf({b: 1}) | ||
}) | ||
test('`.not` can be easier than relying on `// @ts-expect-error`', () => { | ||
type Fruit = {type: 'Fruit'; edible: boolean} | ||
type Apple = {type: 'Fruit'; name: 'Apple'; edible: true} | ||
expectTypeOf<Apple>().toMatchTypeOf<Fruit>() | ||
expectTypeOf<Fruit>().not.toMatchTypeOf<Apple>() | ||
expectTypeOf<Apple>().not.toEqualTypeOf<Fruit>() | ||
}) | ||
test('Catch any/unknown/never types', () => { | ||
@@ -56,3 +83,3 @@ expectTypeOf<unknown>().toBeUnknown() | ||
test('Most assertions can be inverted with `.not`', () => { | ||
test('More `.not` examples', () => { | ||
expectTypeOf(1).not.toBeUnknown() | ||
@@ -59,0 +86,0 @@ expectTypeOf(1).not.toBeAny() |
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
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
226072
3479
286