Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#71972 feat(chai): add containSubset by @pe…
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 authored Mar 5, 2025
1 parent 552bee0 commit b2e39c1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions types/chai-as-promised/chai-as-promised-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ thenableNum = chai.expect(thenableNum).to.eventually.have.ownProperty("foo");
thenableNum = chai.expect(thenableNum).to.eventually.have.ownProperty(Symbol.for("bar"));
thenableNum = chai.expect(thenableNum).to.eventually.have.ownPropertyDescriptor("foo");
thenableNum = chai.expect(thenableNum).to.eventually.have.ownPropertyDescriptor(Symbol.for("bar"));
thenableNum = chai.expect(thenableNum).to.eventually.containSubset({});
thenableNum = chai.expect(thenableNum).to.become(3);
thenableNum = chai.expect(thenableNum).to.be.fulfilled;
thenableNum = chai.expect(thenableNum).to.be.rejected;
Expand All @@ -33,6 +34,7 @@ thenableNum = thenableNum.should.be.fulfilled;
thenableNum = thenableNum.should.eventually.deep.equal(3);
thenableNum = thenableNum.should.eventually.become(3);
thenableNum = thenableNum.should.become(3);
thenableNum = thenableNum.should.eventually.containSubset(3);
thenableNum = thenableNum.should.be.rejected;
thenableNum = thenableNum.should.be.rejectedWith(Error);
thenableNum = thenableNum.should.be.rejectedWith("Error");
Expand Down
5 changes: 5 additions & 0 deletions types/chai-as-promised/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ declare global {
Arguments: PromisedAssertion;
equal: PromisedEqual;
equals: PromisedEqual;
containSubset: PromisedContainSubset;
eq: PromisedEqual;
eql: PromisedEqual;
eqls: PromisedEqual;
Expand Down Expand Up @@ -174,6 +175,10 @@ declare global {
(value: any, message?: string): PromisedAssertion;
}

interface PromisedContainSubset {
(value: any): PromisedAssertion;
}

interface PromisedProperty {
(name: string | symbol, value?: any, message?: string): PromisedAssertion;
}
Expand Down
4 changes: 2 additions & 2 deletions types/chai-subset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"projects": [
"https://github.com/debitoor/chai-subset"
],
"dependencies": {
"@types/chai": "*"
"peerDependencies": {
"@types/chai": "<5.2.0"
},
"devDependencies": {
"@types/chai-subset": "workspace:."
Expand Down
5 changes: 5 additions & 0 deletions types/chai/chai-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ function equal() {
should.equal(undefined, void (0));
}

function containSubset() {
expect({}).to.containSubset({});
({}).should.containSubset({});
}

function _typeof() {
expect("test").to.be.a("string");
"test".should.be.a("string");
Expand Down
14 changes: 14 additions & 0 deletions types/chai/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ declare global {
eq: Equal;
eql: Equal;
eqls: Equal;
containSubset: ContainSubset;
property: Property;
ownProperty: Property;
haveOwnProperty: Property;
Expand Down Expand Up @@ -329,6 +330,10 @@ declare global {
(value: any, message?: string): Assertion;
}

interface ContainSubset {
(expected: any): Assertion;
}

interface Property {
(name: string | symbol, value: any, message?: string): Assertion;
(name: string | symbol, message?: string): Assertion;
Expand Down Expand Up @@ -523,6 +528,15 @@ declare global {
*/
deepStrictEqual<T>(actual: T, expected: T, message?: string): void;

/**
* Partially matches actual and expected.
*
* @param actual Actual value.
* @param expected Potential subset of the value.
* @param message Message to display on error.
*/
containSubset(val: any, exp: any, msg?: string): void;

/**
* Asserts valueToCheck is strictly greater than (>) valueToBeAbove.
*
Expand Down
2 changes: 1 addition & 1 deletion types/chai/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/chai",
"version": "5.0.9999",
"version": "5.2.9999",
"type": "module",
"projects": [
"http://chaijs.com/"
Expand Down

0 comments on commit b2e39c1

Please sign in to comment.