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

Integrated chai-subset and added assert-based negation to containSubset #1664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BreadInvasion
Copy link

A revival of @koddsson 's previous attempt at merging the abandoned chai-subset functionality, with some added comments and an assert-style negation of containSubset which was not present in the original package. I know there was some concern about code duplication in the original PR, so I'm happy to respond to feedback! Thanks all.

Fixes #1616

@BreadInvasion BreadInvasion requested a review from a team as a code owner January 17, 2025 20:22
@@ -0,0 +1,206 @@
import {assert, expect} from '../index.js';

describe('plain object', function () {
Copy link
Contributor

@43081j 43081j Jan 18, 2025

Choose a reason for hiding this comment

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

this file should have a root describe('containsSubset', ...) block which these all live below

if (typeof expected !== 'object' || expected === null) {
return expected === actual;
}
if (!!expected && !actual) {
Copy link
Contributor

@43081j 43081j Jan 18, 2025

Choose a reason for hiding this comment

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

at this point, we already know expected is an NonNull<object> and actual is object, so you can avoid the !!

Suggested change
if (!!expected && !actual) {
if(!actual) {
return false;
}

if (typeof actual.length !== 'number') {
return false;
}
var aa = Array.prototype.slice.call(actual);
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we clone the array? and why we don't use Array.isArray(actual) above?

@43081j
Copy link
Contributor

43081j commented Jan 18, 2025

we should also add tests for using this with should and assert style assertions

otherwise looks good so far though 👍

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.

chai-subset is unmaitained
2 participants