support `{a:1,b:2}.should.include({a:1})` #230

Merged
merged 3 commits into from Jan 27, 2014

Projects

None yet

6 participants

@jkroso
Contributor
jkroso commented Jan 5, 2014

I also removed some type checking within the assert interface because it was getting in the way a bit. I hope thats ok.

@coveralls

Coverage Status

Coverage remained the same when pulling 2715e95 on jkroso:include into f3ebb09 on chaijs:master.

@jkroso
Contributor
jkroso commented Jan 5, 2014

looks like I need to clone the assertion to fix that test case. Anyone know how to do that properly?

@logicalparadox

You probably want to use util.type here as typeof [] === 'object' which I don't think you want.

@jkroso
Contributor
jkroso commented Jan 5, 2014

I just realized I'm not handling negations properly too so I'll need to refactor anyway

@logicalparadox
Member

To handle negation properly you will need to use: https://github.com/chaijs/chai/blob/master/lib/chai/utils/transferFlags.js

@coveralls

Coverage Status

Coverage remained the same when pulling acbf04d on jkroso:include into f3ebb09 on chaijs:master.

@vesln
Member
vesln commented Jan 5, 2014

karma...

@jkroso
Contributor
jkroso commented Jan 5, 2014

works but needs karma-phantomjs-launcher added to the dependencies list

@vesln
Member
vesln commented Jan 5, 2014

Yeah, we just shouldn't be using canary because these things happen all of the time lately @logicalparadox

@logicalparadox
Member

I had it using canary because karma-sauce wouldn't run alongside the karma in npm. I haven't checked recently to see if this works.

If it still doesn't work with the karma from npm, perhaps we could lock to a commit or tag from gh://karma...

@lbdremy
lbdremy commented Jan 15, 2014

+1 Exactly what I was looking for in chai.

@vbardales

is it possible to add multi-level objects support ?
like here: https://github.com/vbardales/chai-properties (no negation support here)

            subject = {
              a: 'a',
              b: {
                b1: 'b1',
                b2: {
                  b21: 'b21',
                  b22: 'b22',
                },
                b3: {
                  b31: 'b31',
                  b32: 'b32',
                },
              },
            };

subject.should.include({ b: { b2: { b22: 'b22' }}});
subject.should.include({ b: { b2: { b22: 'b22' }, b3: { b32: 'b32' }}});
subject.should.not.include({ b: { b4: 'b4' }});
subject.should.not.include({ b: { b2: { b22: 'x' }}});
@lbdremy
lbdremy commented Jan 16, 2014

What is missing to merge this in master?

@jkroso
Contributor
jkroso commented Jan 27, 2014

@vbardales would definitely be nice to be able to do deep includes. I've wanted it twice now since making this PR

@vesln vesln merged commit a01e40b into chaijs:master Jan 27, 2014

1 check failed

default The Travis CI build could not complete due to an error
Details
@wbyoung wbyoung added a commit to wbyoung/chai that referenced this pull request Feb 8, 2016
@wbyoung wbyoung Update include assertion docs for object properties
Originally added in #230, asserting that an object contains a subset of
properties and values was never documented. Questions like #193 have
popped up asking for this feature even though it's been present since
1.9.0.

The discussion in #193 focused mostly around getting something like
this to work via the `property` assertion, but that discussion should
be considered moot by the existing functionality already present in
`include` that was simply overlooked.

Resolves: #193
78f484a
@lucasfcosta lucasfcosta added a commit to lucasfcosta/chai that referenced this pull request Mar 14, 2016
@wbyoung @lucasfcosta wbyoung + lucasfcosta Update include assertion docs for object properties
Originally added in #230, asserting that an object contains a subset of
properties and values was never documented. Questions like #193 have
popped up asking for this feature even though it's been present since
1.9.0.

The discussion in #193 focused mostly around getting something like
this to work via the `property` assertion, but that discussion should
be considered moot by the existing functionality already present in
`include` that was simply overlooked.

Resolves: #193
75d7774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment