Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/signpostmarv/ts-assert
https://github.com/signpostmarv/ts-assert
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/signpostmarv/ts-assert
- Owner: SignpostMarv
- License: apache-2.0
- Created: 2024-04-11T09:10:34.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-14T09:07:11.000Z (7 months ago)
- Last Synced: 2024-05-02T01:15:25.745Z (7 months ago)
- Language: TypeScript
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
[![Coverage Status](https://coveralls.io/repos/github/SignpostMarv/ts-assert/badge.svg?branch=main)](https://coveralls.io/github/SignpostMarv/ts-assert?branch=main)
[![Workflow Status](https://github.com/SignpostMarv/ts-assert/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/SignpostMarv/ts-assert/actions/workflows/ci.yml?query=branch%3Amain)# @signpostmarv/ts-assert
Code-generated assertions for TypeScript type guarding functions.
# Usage
```ts
import {describe, it} from 'node:test';
import assert from 'node:assert/strict';
import ts_assert from '@signpostmarv/ts-assert';
import ts from 'typescript';void describe('isIdentifier', () => {
void it('throws', () => {
assert.throws(() =>
ts_assert.isIdentifier(ts.factory.createStringLiteral('foo'))
);
});
});void describe('isEmptyBindingPattern', () => {
void it('throws', () => {
assert.throws(() =>
ts_assert.isEmptyBindingPattern(ts.factory.createIdentifier('foo'))
);
});
});void describe('isBooleanLiteral', () => {
void it('throws', () => {
assert.throws(() =>
ts_assert.isBooleanLiteral(
ts.factory.createStringLiteral('foo'),
true
)
);
assert.throws(() =>
ts_assert.isBooleanLiteral(ts.factory.createFalse(), true)
);
assert.throws(() =>
ts_assert.isBooleanLiteral(ts.factory.createTrue(), false)
);
});
void it('does not throw', () => {
assert.doesNotThrow(() =>
ts_assert.isBooleanLiteral(ts.factory.createTrue(), true)
);
assert.doesNotThrow(() =>
ts_assert.isBooleanLiteral(ts.factory.createFalse(), false)
);
});
});void describe('isTokenWithExpectedKind', () => {
void it('throws', () => {
assert.throws(() =>
ts_assert.isTokenWithExpectedKind(
ts.factory.createStringLiteral('foo'),
ts.SyntaxKind.StringKeyword
)
);
assert.throws(() =>
ts_assert.isTokenWithExpectedKind(
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
ts.SyntaxKind.NumberKeyword
)
);
});
void it('does not throw', () => {
assert.doesNotThrow(() =>
ts_assert.isTokenWithExpectedKind(
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
ts.SyntaxKind.StringKeyword
)
);
});
});
```