question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: originalValue in test

See original GitHub issue

🍻 I’d like to propose making the test function a bit more useful for complex tests:

Feature Use Case

We have the need to assert that a string is a valid date, that it isn’t before a particular date, and that it matches a certain format. As such, we’ve chosen to use test for that, and this is what we’ve come up with:

const schema = yup.object().shape({
  untilDate: yup
    .date()
    .min('01-01-2020')
    .test('format', '${path} must match the mm-dd-yyyy format', function () {
      return reDate.test((this.options as any).originalValue);
    }),
});

If we use value there, it contains a full ISO string value. e.g. '2020-08-11T23:58:15.712Z', and we want to validate what was passed, not what the transformed/translated value is.

The (this.options as any) bit there is TypeScript, but it signifies that originalValue is not documented on this.options within the test function. It does exist, but it’s not been officially documented. And as #207 suggests, it may not always be present. That makes using it in our scenario a little dicey.

Feature Proposal

I’d like to propose adding original value to the test function handler parameters. Nearly identical to the signature for transform, so that the test function would resemble:

const schema = yup.object().shape({
  untilDate: yup
    .date()
    .min('01-01-2020')
    .test('format', '${path} must match the mm-dd-yyyy format', function (value, originalValue) {
      return reDate.test(originalValue);
    }),
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shellscapecommented, Aug 12, 2020

Understood. I’ll see about fitting this into our next sprint.

0reactions
abnersajrcommented, Aug 27, 2020

After reading the discussions and also the other closed issue I decided to take and work on this. It’s my First PR here, so any feedback and code review are welcome @shellscape and @jquense

Read more comments on GitHub >

github_iconTop Results From Across the Web

TestComplete Feature Requests - SmartBear Community
Hello we have upgraded to Chrome V107 and find that the latest TestComplete no longer "recognizes" various pop ups and the such when...
Read more >
Feature request: Connection uptime - Gargoyle Forum
Feature request : Connection uptime ... and then subtract the original value where the connection ping test first succeeded from the current time?...
Read more >
[JSWSERVER-7765] Should be able to run JS tests locally and see ...
Currently, unless there is a failure in loading the browser, the JS test is always green in ... Workflow, JIRA PM Feature Request...
Read more >
wonky list editing - Bug reports - Snap! Forums
Please fill out these questions for all feature requests and bug reports. If you're requesting a feature, please let us know why this...
Read more >
This Week In Rails Wrapped: An Overview Of Rails 7.1 ...
A detailed overview of some of the features coming to Rails 7.1. ... pull requests and docs with some modifications, I haven't tested...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found