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 isRequired and isNotRequired assertions #65

Merged
merged 9 commits into from
Mar 21, 2018

Conversation

scalvert
Copy link
Collaborator

@scalvert scalvert commented Mar 16, 2018

Implements #56

Fills in the API for

  • isRequired
  • isNotRequired

TODO:

  • implement isRequired
  • implement isNotRequired
  • write tests
  • write docs
  • regenerate docs rendered

@scalvert scalvert changed the title Required assertion [WIP] - Required assertion Mar 16, 2018
@scalvert scalvert changed the title [WIP] - Required assertion [WIP] - Add isRequired and isNotRequired assertions Mar 16, 2018
if (!element) return;

let result = element.required === false;
let actual = element.required === true ? 'required' : 'not required';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just reuse the result variable here instead of comparing the property again

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also updated is-required.js to do the same. FWIW, this is what is-checked does, so we may want to update that too separately.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed. I merged it and planned to do a small cleanup round later :)

@scalvert scalvert changed the title [WIP] - Add isRequired and isNotRequired assertions Add isRequired and isNotRequired assertions Mar 17, 2018
let element = this.findTargetElement();
if (!element) return;

let result = element.required === false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the element is not an <input> element? would required be undefined then and fail this check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I've added a conditional, which will throw if an element is passed that is not one of HTMLInputElement, HTMLTextAreaElement, or HTMLSelectElement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a test...

@scalvert
Copy link
Collaborator Author

@Turbo87 anything else I need to do to push this in?

@Turbo87
Copy link
Collaborator

Turbo87 commented Mar 21, 2018

anything else I need to do to push this in?

remind me about it 😜

Copy link
Collaborator

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks again! 👍

@Turbo87 Turbo87 merged commit 0297e1e into mainmatter:master Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants