From a37f7afd13bcf7404396c7daadee4aab6512ea8c Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Fri, 19 Oct 2018 16:53:51 +0200 Subject: [PATCH] Change arrays to be ReadonlyArray for frozen parameter support --- types/chai/chai-tests.ts | 18 ++++++++++++++++++ types/chai/index.d.ts | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/types/chai/chai-tests.ts b/types/chai/chai-tests.ts index ae8a71766e..36002d9bfa 100644 --- a/types/chai/chai-tests.ts +++ b/types/chai/chai-tests.ts @@ -808,6 +808,24 @@ function frozen() { expect(Object.freeze({})).to.be.frozen; ({}).should.be.not.frozen; Object.freeze({}).should.be.frozen; + + expect([1, 2, 3]).to.have.all.members([1, 2, 3]); + expect([1, 2, 3]).to.have.all.members(Object.freeze([1, 2, 3])); + + expect({1: "", 2: "", 3: ""}).to.have.all.keys([1, 2, 3]); + expect({1: "", 2: "", 3: ""}).to.have.all.keys(Object.freeze([1, 2, 3])); + + assert.notDeepInclude([1, 2, 3], 1); + assert.notDeepInclude(Object.freeze([1, 2, 3]), 1); + + assert.include([1, 2, 3], 1); + assert.include(Object.freeze([1, 2, 3]), 1); + + assert.notInclude([1, 2, 3], 1); + assert.notInclude(Object.freeze([1, 2, 3]), 1); + + expect([1, 2, 3]).to.have.oneOf([1, 2, 3]); + expect([1, 2, 3]).to.have.oneOf(Object.freeze([1, 2, 3])); } class PoorlyConstructedError { diff --git a/types/chai/index.d.ts b/types/chai/index.d.ts index 72ebc0191d..5f73803757 100644 --- a/types/chai/index.d.ts +++ b/types/chai/index.d.ts @@ -118,7 +118,7 @@ declare namespace Chai { extensible: Assertion; sealed: Assertion; frozen: Assertion; - oneOf(list: any[], message?: string): Assertion; + oneOf(list: ReadonlyArray, message?: string): Assertion; } interface LanguageChains { @@ -235,7 +235,7 @@ declare namespace Chai { interface Keys { (...keys: string[]): Assertion; - (keys: any[]|Object): Assertion; + (keys: ReadonlyArray|Object): Assertion; } interface Throw { @@ -252,7 +252,7 @@ declare namespace Chai { } interface Members { - (set: any[], message?: string): Assertion; + (set: ReadonlyArray, message?: string): Assertion; } interface PropertyChange { @@ -696,7 +696,7 @@ declare namespace Chai { * @param needle Potential value contained in haystack. * @param message Message to display on error. */ - include(haystack: T[], needle: T, message?: string): void; + include(haystack: ReadonlyArray, needle: T, message?: string): void; /** * Asserts that haystack does not include needle. @@ -705,7 +705,7 @@ declare namespace Chai { * @param needle Potential expected substring of haystack. * @param message Message to display on error. */ - notInclude(haystack: string | any[], needle: any, message?: string): void; + notInclude(haystack: string | ReadonlyArray, needle: any, message?: string): void; /** * Asserts that haystack includes needle. Can be used to assert the inclusion of a value in an array or a subset of properties in an object. Deep equality is used. @@ -732,7 +732,7 @@ declare namespace Chai { * @param needle Potential expected substring of haystack. * @param message Message to display on error. */ - notDeepInclude(haystack: string | any[], needle: any, message?: string): void; + notDeepInclude(haystack: string | ReadonlyArray, needle: any, message?: string): void; /** * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the inclusion of a subset of properties in an object.