-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Add the ability of creating matchers wrapping a value #8540
Comments
@pedrottimark I'm afraid I fail to understand your request — the general idea is to have a way to extend the Does that clarify? |
It is likely that my lack of experience with fp libraries affects my ability to understand. Here is an example of a limitation I do know which might be analogy to what you need. The
But what if you need to compare like Is the extension ability you need analogy to chain matcher for path followed by matcher for value? |
Kind of — I'm really looking to wrapped values though, let me give you the minimal introduction, maybe that's going to help you
What I'd like to do is const either = operationThatMightFail();
expect(either).success.toMatchObject(expectedData);
expect(either).not.fail.toMatchObject(expectedData); Internally, the |
Yes, that does clarify. Here is a thought that came to mind about a work around:
|
@pedrottimark Yeah I ended up defining my own function https://github.com/stoplightio/prism/pull/323/files#diff-e53e98c10a813d2d271cc0fa5c55ddcaR11 — although I'd say your workaround seems cool as well. In any case, do you think there's going to be a way to have a native way to handle generically wrapped values? |
If I understand correctly that a generic description of the need is be able to extend with methods that can continue the chain, then I will keep that in mind while I explore depths of As an example of another request which has that status: asymmetric matchers do not have access to the matcher utils that are available to application-specific matchers. |
Fantastic, you got my need perfectly! I'll subscribe to the issue, I'm eager to see this moving forward. The workaround you suggested, for now, will just do :) |
Just wondering if this is being considered as a feature or if you'd be interested in having a PR for that. It's not blocking me, but it would simplify a lot of the testing code we currently have in Prism. Cheers! |
I would be wary of adding things to const xpct = (val) => ({
...expect(val),
get right() {
return xpct(val.getWrappedRightSomehow());
}
}) |
@jeysal That would be a good compromise. Now my memory might be flaking but I recall trying the approach and could not get very far, but I might give it another try. Is there a documentation page on how to extend properly the |
Only for the official |
That's be my intention — transform a custom function call into internal expect calls. My idea would be to transform this: export function assertRight<L, A>(e: E.Either<L, A>, onRight: (a: A) => void = noop): asserts e is E.Right<A> {
pipe(
e,
E.fold(l => {
throw new Error('Right expected, got a Left: ' + l);
}, onRight)
);
} Into something that'd be integrated with jest — that'd unwrap the value for me: into The problem is that the proposed const xpct = <L, A>(val: E.Either<L, A>) => ({
...expect(val),
get aRight() {
return pipe(
e,
E.fold(() => {
expect.assertions(Infinity)
return expect(val)
}, expect)
);
}
}) Although I'd have the problem that I'd be handling multiple types, such as Either, Option, TaskEither |
That's similar to my example so something like it should work. Note that I'd recommend returning an |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
Currently there's no way to create a matcher that holds a wrapped value, such as a Promise.
Motivation
This limits the possibility extending jest to work nicely with some fp libraries, forcing me to write repetitive boilerplate code:
Example
The text was updated successfully, but these errors were encountered: