All Projects → LeDDGroup → typescript-test-utils

LeDDGroup / typescript-test-utils

Licence: other
Helper types for testing your package exported types

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to typescript-test-utils

last fm
A simple app to demonstrate a testable, maintainable, and scalable architecture for flutter. flutter_bloc, get_it, hive, and REST API are some of the tech stacks used in this project.
Stars: ✭ 134 (+737.5%)
Mutual labels:  test
html-comment-regex
Regular expression for matching HTML comments
Stars: ✭ 15 (-6.25%)
Mutual labels:  test
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+287.5%)
Mutual labels:  test
jest-retry
Jest retry pattern for flaky E2E tests
Stars: ✭ 36 (+125%)
Mutual labels:  test
awesome-testing
Software Testing for QA.
Stars: ✭ 48 (+200%)
Mutual labels:  test
cypress-maildev
Cypress Maildev is a bunch of Cypress commands in order to test your messages (SMS and Emails) by using Maildev REST API.
Stars: ✭ 19 (+18.75%)
Mutual labels:  test
assert
Go 语言 assert 断言函数
Stars: ✭ 17 (+6.25%)
Mutual labels:  test
mutode
Mutation testing for JavaScript and Node.js
Stars: ✭ 61 (+281.25%)
Mutual labels:  test
sa11y
Salesforce Automated Accessibility Testing Libraries
Stars: ✭ 58 (+262.5%)
Mutual labels:  test
pest-plugin-laravel-octane
⛽ Pest plugin to test Laravel applications powered by Octane.
Stars: ✭ 21 (+31.25%)
Mutual labels:  test
octane-testbench
⛽ Set of utilities to test Laravel applications powered by Octane.
Stars: ✭ 35 (+118.75%)
Mutual labels:  test
lint-html-with-css
Lint HTML with CSS. A collection of CSS snippets from the hashtag #lintHTMLwithCSS on twitter. These CSS snippets intend to warn developers about common mistakes made in HTML.
Stars: ✭ 35 (+118.75%)
Mutual labels:  test
swift-di-explorations
Functional DI explorations in Swift
Stars: ✭ 28 (+75%)
Mutual labels:  typesafe
es-feature-detection
ECMAScript feature and API detection
Stars: ✭ 16 (+0%)
Mutual labels:  test
ngx-testbedder
CLI tool for writing the test bed for Angular integration test
Stars: ✭ 13 (-18.75%)
Mutual labels:  test
J1939-Framework
Framework to work with J1939 Frames used in CAN bus in bus, car and trucks industries
Stars: ✭ 123 (+668.75%)
Mutual labels:  test
raise if
one liner `raise Exception if condition` for Python
Stars: ✭ 15 (-6.25%)
Mutual labels:  test
vue-testing-with-jest-conf17
Examples on how to test Vue with Jest, based on the presentation at VueConf17
Stars: ✭ 37 (+131.25%)
Mutual labels:  test
carina
Carina automation framework: Web, Mobile, API, DB etc testing...
Stars: ✭ 652 (+3975%)
Mutual labels:  test
TestTarget
🐳 Notes on configuring test targets
Stars: ✭ 44 (+175%)
Mutual labels:  test

typescript-test-utils

npm version Conventional Commits code style: prettier Greenkeeper badge

Helper types for testing your package exported types

  • Only depends on typescript installed.
  • Easily extendable

Note

I have notice some issues with typescript if your types are too complex, so I recommend using assertTrue and assertFalse instead of assert

Usage

You test them with the assert method ( wich is just a placeholder, it doesn't run anything ) and the type helpers

import {
  assert,
  assertTrue,
  assertFalse,
  HasProperties
} from "typescript-test-utils";

assertTrue<true>(); // ok
assertTrue<false>(); // nop
assertFalse<true>(); // nop
assertFalse<false>(); // ok

assert<true>(true); // ok
assert<false>(true); // nop

type MyType = { a: string };
assertTrue<HasProperties<MyType, "a">>(); // ok
assertFalse<HasProperties<MyType, "a">>(); // nop
assertTrue<HasProperties<MyType, "b">>(); // nop
assertFalse<HasProperties<MyType, "b">>(); // ok

And just run tsc on your test files to check for type errors

{
  "scripts": {
    "test": "tsc --noEmit src/*.test.ts"
  }
}

Assertions

There are currently some implemented, if you have any idea for a new one send a PR or open an issue

import { assert, HasProperties, Extends, Equals, Not } from "typescript-test-utils";

HasProperties<{ a: string, b: number }, "a" | "b"> // true
HasProperties<{ a: string, b: number }, "a" | "c"> // false

Extends<{ a: string, b: string }, { a: string }> // true
Extends<{ a: string, b: string }, { c: string }> // false

Equals<{ a: string }, { a: string }> // true
Equals<{ a: string, b: string }, { a: string }> // false

Not<true> // false
Not<false> // true

Not<Equals<{ a: string, b: string }, { a: string }>> // true

Adding your own assertions

You only need to make a type that returns true or false, for example:

type Not<T extends boolean> = T extends true ? false : true;

or

type Extends<T, K> = T extends K ? true : false;

These are the definitions of the Not and Extends helpers

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].