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

Enable multiple config options for jest-validate #4337

Closed
thymikee opened this issue Aug 23, 2017 · 7 comments
Closed

Enable multiple config options for jest-validate #4337

thymikee opened this issue Aug 23, 2017 · 7 comments

Comments

@thymikee
Copy link
Collaborator

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Currently jest-validate takes real JS object as a configuration sample, which doesn't scale to one config option having multiple possible values

What is the expected behavior?
Being able to validate things like this:

const config = {
  regularValue: string,
  multiValueOption: string | Array<string>
}

This can be fixed by introducing utility functions into jest-validate

// sampleConfig.js
import {multiple} from 'jest-validate';

module.exports = {
  regularOption: 'string',
  multiValueOption: multiple(['string', ['string1', 'string2']])
}

Where multiple would have it's unique $$typeof identifier for which we could test.
This is however just a proposal of the API, so if anyone has better ideas, this is right place to do so :)

cc @rogeliog

@rogeliog
Copy link
Contributor

I like this approach

@cpojer
Copy link
Member

cpojer commented Aug 23, 2017

I'd call it either, and/or mirror React's prop-types API

@rogeliog
Copy link
Contributor

rogeliog commented Sep 1, 2017

@thymikee @cpojer if we are going to support (either|oneOf) what is your suggestion for error messages?

This is what we currently show:

      ● Validation Error:

        Option "displayName" must be of type:
          string
        but instead received:
          number

        Example:
        {
          "displayName": "myProject"
        }

Would it be something like this?

      ● Validation Error:
        Option "displayName" must be one of the following types:
        
            Option can be of type:
              string
            but instead received:
              number

            Example:
            {
              "displayName": "myProject"
            }


            Option can be of type:
              object
            but instead received:
              number

            Example:
            {
              "displayName": { default: "myProject", interactive: "emoji" }
            }

@cpojer
Copy link
Member

cpojer commented Sep 2, 2017

Ideally the example will show both possibilities collapsed in one error message, duplicating it may be easier in code but looks worse.

@SimenB
Copy link
Member

SimenB commented Oct 19, 2018

@thymikee closed by #7207?

@thymikee
Copy link
Collaborator Author

yes!

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants