Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add .toHaveProperty() matcher #36

Merged
merged 26 commits into from
Dec 3, 2023
Merged

Conversation

mrazauskas
Copy link
Member

@mrazauskas mrazauskas commented Nov 28, 2023

The .toHaveProperty() matcher is useful to test generic types. Also the negated .not.toHaveProperty() will help to reduce .toRaiseError() usage, which is clumsy because of red highlights in code editors.

Usage:

import { expect } from "tstyche";

type Worker<T> = {
  [K in keyof T as Exclude<K, "setup" | "teardown">]: T[K];
};

interface Sample {
  isBusy?: boolean | undefined;
  runTest: (a: string, b: number) => void;
  setup: () => void;
  teardown: () => void;
}

expect<Worker<Sample>>().type.toHaveProperty("isBusy");
expect<Worker<Sample>>().type.toHaveProperty("runTest");

expect<Worker<Sample>>().type.not.toHaveProperty("setup");
expect<Worker<Sample>>().type.not.toHaveProperty("teardown");

@mrazauskas mrazauskas added this to the TSTyche 1.0 milestone Nov 28, 2023
Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (5053ea9) 90.93% compared to head (7c7a8a9) 90.37%.

❗ Current head 7c7a8a9 differs from pull request most recent head a93134f. Consider uploading reports for the commit a93134f to get more accurate results

Files Patch % Lines
src/checker/Checker.ts 81.53% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
- Coverage   90.93%   90.37%   -0.57%     
==========================================
  Files          83       83              
  Lines        5329     5392      +63     
  Branches      744      750       +6     
==========================================
+ Hits         4846     4873      +27     
- Misses        480      516      +36     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrazauskas mrazauskas marked this pull request as ready for review December 3, 2023 14:37
@mrazauskas mrazauskas enabled auto-merge (squash) December 3, 2023 15:19
@mrazauskas mrazauskas enabled auto-merge (squash) December 3, 2023 15:21
@mrazauskas mrazauskas merged commit 774ee1c into main Dec 3, 2023
26 checks passed
@mrazauskas mrazauskas deleted the add-toHaveProperty-matcher branch December 3, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant