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

(feat): expect value to contain oneOf #1242

Merged
merged 3 commits into from
Jun 28, 2019
Merged

Conversation

voliva
Copy link
Contributor

@voliva voliva commented Mar 12, 2019

Previously, doing an assertion such as

expect('The quick brown fox jumps over the lazy dog').to.contain.oneOf(['cat', 'dog', 'bird']);

Would reject with the message expected [ ... ] to be one of ['cat', 'dog', 'bird'], as oneOf doesn't check for contains flag.

This PR adds this additional check to oneOf, so now it can be chained with contain, contains, include and includes.

@voliva voliva requested a review from a team as a code owner March 12, 2019 16:14
@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

Merging #1242 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1242      +/-   ##
==========================================
+ Coverage    94.6%   94.61%   +<.01%     
==========================================
  Files          33       33              
  Lines        1705     1708       +3     
  Branches      415      416       +1     
==========================================
+ Hits         1613     1616       +3     
  Misses         92       92
Impacted Files Coverage Δ
lib/chai/core/assertions.js 99.39% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dc92d8...9d2f6dc. Read the comment docs.

Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 😊

The code LGTM I just think we need some docs. Once that's in it will be G2G on my end.

chai.js Outdated
@@ -3496,16 +3496,27 @@ module.exports = function (chai, _) {
if (msg) flag(this, 'message', msg);
Copy link
Member

Choose a reason for hiding this comment

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

I think the docs above need to specify that this assertion supports the contains flag since it ultimately changes its behaviour. It would also be good to add an example.

@lucasfcosta
Copy link
Member

Hi @voliva, this is just a friendly ping to see if you need help with this PR.

I'd love to get it merged in. Thanks again for the work 😊

@voliva
Copy link
Contributor Author

voliva commented Jun 25, 2019 via email

@voliva
Copy link
Contributor Author

voliva commented Jun 25, 2019

Does that look right? @lucasfcosta

Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

There's only one minor typo I've caught, but I'm happy to merge this in once that's addressed.

I'll have some time to have a second look at this early in the morning tomorrow (UK time). If it's fixed by then and we get another review I'll press the merge button 😄

Thanks!

this.assert(
if(contains) {
this.assert(
list.some(posibility => expected.indexOf(posibility) > -1)
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be a typo here. It should be possibility instead of posibility.

Copy link
Contributor 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 just amended the relevant commit.

lucasfcosta
lucasfcosta previously approved these changes Jun 26, 2019
Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the contribution.

Let's get a second approval and merge this in :)

Copy link
Member

@vieiralucas vieiralucas left a comment

Choose a reason for hiding this comment

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

Thank you so much @voliva for your contribution, everything is looking good to me except for two very small code style issues.
Once that gets fixed, I'll be happy to merge this.

chai.js Outdated
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');

this.assert(
if(contains) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry about this nitpicking but can you add an extra space here?
if (contains) {
Just to keep style consistency.

new Assertion(list, flagMsg, ssfi, true).to.be.an('array');

this.assert(
if(contains) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry about this nitpicking but can you add an extra space here?
if (contains) {
Just to keep style consistency.

Copy link
Member

@vieiralucas vieiralucas left a comment

Choose a reason for hiding this comment

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

Actually I just realize, you shouldn't commit changes to chai.js.
chai.js will be automatically generated when making a release.

@voliva
Copy link
Contributor Author

voliva commented Jun 27, 2019

Hey @vieiralucas thanks for your feedback! I've addressed your comments

Copy link
Member

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

@vieiralucas good catch.

@voliva thanks for the changes 💖

Copy link
Member

@vieiralucas vieiralucas left a comment

Choose a reason for hiding this comment

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

Perfect

Thank you again @voliva, awesome contribution ❤️.

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

Successfully merging this pull request may close these issues.

None yet

3 participants