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

assert.propContains API Implementation & Tests #1668

Merged
merged 2 commits into from Feb 6, 2022

Conversation

izelnakri
Copy link
Contributor

@izelnakri izelnakri commented Jan 14, 2022

I think this is a good addition to the existing QUnit public API. It is rather too common that I need to partially check object values. Also includes notPropContains.

Example:

assert.propContains(new User({ id: 1, firstName: 'Izel' }), { firstName: 'Izel' });
assert.notPropContains(new User({ id: 1, firstName: 'Izel' }), { firstName: 'Timo' });

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 14, 2022

CLA Signed

The committers are authorized under a signed CLA.

@Krinkle
Copy link
Member

Krinkle commented Jan 14, 2022

Thanks @izelnakri, I support inclusion of a method like this. In terms of semantics, I believe this would be most useful as sibling to propEqual rather than deepEqual. In other words, own properties only (ignore constructor) and non-recursive, which I believe is how you've implemented it as well.

I'd propose a slightly different name that incorporates the term "prop" for consistency with propEqual. I note that in other frameworks, a partial assertion like this is often named with "contain" or "include" as the verb. Perhaps assert.propContain() would work here.

@Krinkle Krinkle self-assigned this Jan 14, 2022
@izelnakri
Copy link
Contributor Author

izelnakri commented Jan 14, 2022

In other words, own properties only (ignore constructor) and non-recursive, which I believe is how you've implemented it as well.

Yes.

I'd propose a slightly different name that incorporates the term "prop" for consistency with propEqual. I note that in other frameworks, a partial assertion like this is often named with "contain" or "include" as the verb. Perhaps assert.propContain() would work here.

I agree propContains sounds more explicit, probably a better name. I'm creating a new commit with name changes now!

Copy link
Member

@Krinkle Krinkle left a comment

Choose a reason for hiding this comment

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

LGTM. I'll probably land/release next weekend. Would you be interested in adding a doc page as well?

@izelnakri izelnakri changed the title assert.partialEqual API Implementation & Tests assert.propContains API Implementation & Tests Jan 14, 2022
@izelnakri
Copy link
Contributor Author

I'm going for a holiday tomorrow, but I'll see if I can do it during my trip :)

Krinkle added a commit to izelnakri/qunit that referenced this pull request Feb 6, 2022
Also cross-link with propEqual pages, and improve those as well, in
particular to clarify that these too are recursive in regards to
nested objects being comparable using plain objects.

Ref qunitjs#1668.
test/main/assert.js Outdated Show resolved Hide resolved
test/main/assert.js Outdated Show resolved Hide resolved
Also cross-link with propEqual pages, and improve those as well, in
particular to clarify that these too are recursive in regards to
nested objects being comparable using plain objects.

Ref qunitjs#1668.
@Krinkle Krinkle merged commit f0c346b into qunitjs:main Feb 6, 2022
@Krinkle
Copy link
Member

Krinkle commented Feb 6, 2022

@izelnakri I've landed this now to simplify unrelated code changes I'm doing today.

I made a few judgement calls that I think will align with your intent, but I'd love to hear from you prior to releasing this, I'm open to changing or reconsidering any aspect of it! Thanks again for the PR.

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

Successfully merging this pull request may close these issues.

None yet

2 participants