expect-type
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -6,2 +6,11 @@ # Change Log | ||
## [0.4.2](https://github.com/mmkal/ts/compare/expect-type@0.4.1...expect-type@0.4.2) (2020-03-07) | ||
**Note:** Version bump only for package expect-type | ||
## [0.4.1](https://github.com/mmkal/ts/compare/expect-type@0.4.0...expect-type@0.4.1) (2020-03-06) | ||
@@ -8,0 +17,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
it('tests types', () => { | ||
test('Type-check object references', () => { | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 }); | ||
__1.expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 }); | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }); | ||
}); | ||
test('Assertions can be inverted', () => { | ||
__1.expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 }); | ||
__1.expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 }); | ||
}); | ||
test('Catch any/unknown/never types', () => { | ||
__1.expectTypeOf().toBeUnknown(); | ||
__1.expectTypeOf().toBeAny(); | ||
__1.expectTypeOf().toBeNever(); | ||
}); | ||
test('Test for basic javascript types', () => { | ||
__1.expectTypeOf(() => 1).toBeFunction(); | ||
@@ -20,2 +26,4 @@ __1.expectTypeOf({}).toBeObject(); | ||
__1.expectTypeOf(Symbol(1)).toBeSymbol(); | ||
}); | ||
test('Nullable types', () => { | ||
__1.expectTypeOf(undefined).toBeUndefined(); | ||
@@ -30,2 +38,4 @@ __1.expectTypeOf(undefined).toBeNullable(); | ||
__1.expectTypeOf().toBeNullable(); | ||
}); | ||
test('Assertions can be inverted with `.not`', () => { | ||
__1.expectTypeOf(1).not.toBeUnknown(); | ||
@@ -37,2 +47,4 @@ __1.expectTypeOf(1).not.toBeAny(); | ||
__1.expectTypeOf(1).not.toBeNullable(); | ||
}); | ||
test('Make assertions about object properties', () => { | ||
const obj = { a: 1, b: '' }; | ||
@@ -45,5 +57,6 @@ __1.expectTypeOf(obj) | ||
.toEqualTypeOf(); | ||
}); | ||
test('Assert on function parameters (using `.parameter(n)` or `.parameters`) and return values (using `.return`)', () => { | ||
const f = (a) => [a, a]; | ||
__1.expectTypeOf(f).toBeFunction(); | ||
__1.expectTypeOf('hi').not.toBeFunction(); | ||
__1.expectTypeOf(f).toBeCallableWith(1); | ||
@@ -65,4 +78,12 @@ __1.expectTypeOf(f).not.toBeAny(); | ||
__1.expectTypeOf(twoArgFunc).parameters.toEqualTypeOf(); | ||
}); | ||
test('Promise resolution types can be checked with `.resolves`', () => { | ||
const asyncFunc = async () => 123; | ||
__1.expectTypeOf(asyncFunc).returns.resolves.toBeNumber(); | ||
}); | ||
test('Array items can be checked with `.items`', () => { | ||
__1.expectTypeOf([1, 2, 3]).items.toBeNumber(); | ||
__1.expectTypeOf([1, 2, 3]).items.not.toBeString(); | ||
}); | ||
test('Check that functions never return', () => { | ||
const thrower = () => { | ||
@@ -72,4 +93,4 @@ throw Error(); | ||
__1.expectTypeOf(thrower).returns.toBeNever(); | ||
__1.expectTypeOf([1, 2, 3]).items.toBeNumber(); | ||
__1.expectTypeOf([1, 2, 3]).items.not.toBeString(); | ||
}); | ||
test('Generics can be used rather than references', () => { | ||
__1.expectTypeOf().not.toEqualTypeOf(); | ||
@@ -79,40 +100,2 @@ __1.expectTypeOf().not.toEqualTypeOf(); | ||
}); | ||
it('can do boolean type logic', () => { | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
__1.expectTypeOf().toEqualTypeOf(); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
@@ -42,4 +42,16 @@ export declare type Not<T extends boolean> = T extends true ? false : true; | ||
} | ||
/** | ||
* Similar to Jest's `expect`, but with type-awareness. | ||
* Gives you access to a number of type-matchers that let you make assertions about the | ||
* form of a reference or generic type parameter. | ||
* | ||
* @example | ||
* expectTypeOf({a: 1}).toMatchTypeOf({a: 2}) | ||
* expectTypeOf({a: 1}).property('a').toBeNumber() | ||
* | ||
* @description | ||
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. | ||
*/ | ||
export declare const expectTypeOf: <Actual>(actual?: Actual | undefined) => ExpectTypeOf<Actual, true>; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,2 +5,14 @@ "use strict"; | ||
const fn = () => true; | ||
/** | ||
* Similar to Jest's `expect`, but with type-awareness. | ||
* Gives you access to a number of type-matchers that let you make assertions about the | ||
* form of a reference or generic type parameter. | ||
* | ||
* @example | ||
* expectTypeOf({a: 1}).toMatchTypeOf({a: 2}) | ||
* expectTypeOf({a: 1}).property('a').toBeNumber() | ||
* | ||
* @description | ||
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. | ||
*/ | ||
exports.expectTypeOf = (actual) => { | ||
@@ -7,0 +19,0 @@ const nonFunctionProperties = ['parameters', 'returns', 'resolves', 'not', 'items']; |
{ | ||
"name": "expect-type", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"repository": "https://github.com/mmkal/ts", | ||
@@ -16,3 +16,3 @@ "homepage": "https://github.com/mmkal/ts/tree/master/packages/expect-type#readme", | ||
}, | ||
"gitHead": "7ada63d995dad1d5077e8d60de725381a4ae4f4f" | ||
"gitHead": "d9cc762ec6fd4c525d8207d680fbac527b8da7d5" | ||
} |
@@ -41,2 +41,5 @@ # expect-type | ||
![Node CI](https://github.com/mmkal/ts/workflows/Node%20CI/badge.svg) | ||
![codecov](https://codecov.io/gh/mmkal/ts/branch/master/graph/badge.svg) | ||
<!-- codegen:start {preset: jest2md, source: src/__tests__/index.test.ts} --> | ||
@@ -43,0 +46,0 @@ Type-check object references: |
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
191876
21
2970
190