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

Custom examples for property(..., context(), ...)? #1825

Closed
ion1 opened this issue May 4, 2021 · 7 comments
Closed

Custom examples for property(..., context(), ...)? #1825

ion1 opened this issue May 4, 2021 · 7 comments

Comments

@ion1
Copy link

ion1 commented May 4, 2021

💬 Question and Help

It is unclear to me how to provide a custom example for the following:

fc.assert(
  fc.property(fc.string(), fc.context(), (str, ctx) => /* ... */),
  { examples: [["x", /* what here? */]] }
);

context() seems to instantiate an class which is not exported. I would prefer not to make my own implementation of ContextValue.

It would be the most convenient not to have to include a value corresponding to the context in the examples at all – maybe the arbitraries provided to the property call could be used if there are more of them than elements in the example tuples – but any solution that gets this to work is good enough. Thanks!

@dubzzz
Copy link
Owner

dubzzz commented May 4, 2021

Hello,

There is today no way to build partial or incomplete examples. A proposal to do so was suggested in the issue #710 (comment) but for the moment it has not been implemented.

Regarding ContextValue for the moment, the implementation is not exposed to the user. I should probably either expose the class or add something like fc.contextFor() as I did for fc.scheduler() (see fc.schedulerFor()).

Given what has been released so far, the only trick I'd have is:

const buildContext = () => fc.sample(fc.context(), {numRuns:1})[0];
fc.assert(
  fc.property(fc.string(), fc.context(), (str, ctx) => /* ... */),
  { examples: [["x", buildContext()]] }
);

Not perfect but it should work well.

@stale
Copy link

stale bot commented Jul 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 6, 2021
@stale stale bot closed this as completed Jul 13, 2021
@tskj

This comment was marked as off-topic.

@dubzzz

This comment was marked as off-topic.

@tskj

This comment was marked as off-topic.

@dubzzz

This comment was marked as off-topic.

@tskj
Copy link
Contributor

tskj commented Dec 8, 2022

Sure thing!

I have submitted a proper bug report here, and also two suggestions for improving the docs if fixing the bug will never be on the roadmap here and here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants