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

Add toBeHexadecimal Method #149

Closed
mvpowers opened this issue Jul 14, 2018 · 6 comments
Closed

Add toBeHexadecimal Method #149

mvpowers opened this issue Jul 14, 2018 · 6 comments

Comments

@mvpowers
Copy link
Contributor

Feature Request

Description: Add a method to check whether a string is a valid hexadecimal.

Possible solution:
expect('#e3e3e3').toBeHexadecimal();
expect('#fff').toBeHexadecimal();

This could be helpful for some front-end tests. I'll be happy to submit a PR if this sounds like a good idea.

@mattphillips
Copy link
Member

Hey @mvpowers I like the sound of this matcher, feel free to send a PR 😄

@denizdogan
Copy link
Contributor

@mvpowers @mattphillips Not that I oppose the idea, but shouldn't this be implemented as a simple toMatch? The following seems simple enough (not tested):

const hexadecimal = /^#[a-f0-9]/i
expect('#e3e3e3').toMatch(hexadecimal)
expect('#fff').toMatch(hexadecimal)

@mattphillips
Copy link
Member

@denizdogan I think this matcher is a useful one to save people having to write out the regex and reads nicer than toMatch

@denizdogan
Copy link
Contributor

denizdogan commented Aug 14, 2018

It's too late for this comment I guess, but hexadecimal notation can look different in different languages. CSS is the only one I know of that uses # as the prefix, JS itself uses 0x, HTML uses &#x, etc. It's not obvious in the name toBeHexadecimal that it's the CSS variant that's being tested against. EDIT: It's also not obvious that the value is expected to be 3 or 6 characters in length.

@mattphillips
Copy link
Member

@denizdogan I'm happy to extend out it's behaviour to support other languages if you want to send a PR?

@denizdogan
Copy link
Contributor

@mattphillips I'm not really interested in sending a P.R. for this particular method (I would have just used the regex version I suggested earlier) but I'm just pointing out that "being hexadecimal" is a broad term and if the method is supposed to check that the value is a valid hexadecimal CSS value of length 3 or 6, it would be good if that was reflected somewhere in the documentation too.

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