From b794bedb72d3b88ccb3acc107076e05d242cc03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vot?= Date: Wed, 3 May 2017 19:57:45 +0200 Subject: [PATCH] Added type definitions for chai-arrays (#16266) --- types/chai-arrays/chai-arrays-tests.ts | 76 ++++++++++++++++++++++++++ types/chai-arrays/index.d.ts | 37 +++++++++++++ types/chai-arrays/tsconfig.json | 22 ++++++++ types/chai-arrays/tslint.json | 1 + 4 files changed, 136 insertions(+) create mode 100644 types/chai-arrays/chai-arrays-tests.ts create mode 100644 types/chai-arrays/index.d.ts create mode 100644 types/chai-arrays/tsconfig.json create mode 100644 types/chai-arrays/tslint.json diff --git a/types/chai-arrays/chai-arrays-tests.ts b/types/chai-arrays/chai-arrays-tests.ts new file mode 100644 index 0000000000..7fabaacbca --- /dev/null +++ b/types/chai-arrays/chai-arrays-tests.ts @@ -0,0 +1,76 @@ +import { expect } from 'chai'; +import { assert } from 'chai'; + +import chai = require('chai'); +import ChaiArrays = require('chai-arrays'); + +chai.use(ChaiArrays); +chai.should(); + +const arr: any[] = [1, 2, 3]; +const str: string = 'abcdef'; + +const otherArr: number[] = [1, 2, 3]; +const anotherArr: number[] = [2, 4]; +const yetAnotherArr: number[] = [8, 5, 7]; + +arr.should.be.array(); +str.should.not.be.array(); + +expect(arr).to.be.array(); +expect(str).not.to.be.array(); + +assert.array(arr, 'is array'); + +arr.should.be.ofSize(3); +arr.should.not.be.ofSize(4); + +expect(arr).to.be.ofSize(3); +expect(str).not.to.be.ofSize(4); + +assert.ofSize(arr, 3, 'has 3 elements'); + +arr.should.be.equalTo(otherArr); +arr.should.not.be.equalTo(anotherArr); + +expect(arr).to.be.equalTo(otherArr); +expect(str).to.be.not.equalTo(anotherArr); + +assert.equalTo(arr, otherArr, 'is equal to'); + +arr.should.be.containing(1); +arr.should.not.be.containing(4); + +expect(arr).to.be.containing(1); +expect(str).to.be.not.containing(4); + +assert.containing(arr, 1, 'contains'); + +arr.should.be.containingAllOf(otherArr); +arr.should.not.be.containingAllOf(anotherArr); + +expect(arr).to.be.containingAllOf(otherArr); +expect(str).to.be.not.containingAllOf(anotherArr); + +assert.containingAllOf(arr, otherArr, 'contains all of'); + +arr.should.be.containingAnyOf(otherArr); +arr.should.be.containingAnyOf(anotherArr); +arr.should.not.be.containingAnyOf(yetAnotherArr); + +expect(arr).to.be.containingAnyOf(otherArr); +expect(str).to.be.containingAnyOf(anotherArr); +expect(str).to.be.not.containingAnyOf(yetAnotherArr); + +assert.containingAnyOf(arr, otherArr, 'contains any of'); +assert.containingAnyOf(arr, anotherArr, 'contains any of'); + +arr.should.be.sorted(); +anotherArr.should.be.sorted(); +yetAnotherArr.should.be.sorted(); + +expect(arr).to.be.sorted(); +expect(anotherArr).to.be.sorted(); +expect(yetAnotherArr).to.be.not.sorted(); + +assert.sorted(arr, 'sorted'); diff --git a/types/chai-arrays/index.d.ts b/types/chai-arrays/index.d.ts new file mode 100644 index 0000000000..d387d1614d --- /dev/null +++ b/types/chai-arrays/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions for chai-arrays 1.0 +// Project: https://github.com/GaneshSPatil/chai-arrays +// Definitions by: Clément Prévot +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare global { + namespace Chai { + interface Assertion extends LanguageChains, NumericComparison, TypeComparison { + array(): Assertion; + ofSize(size: number): Assertion; + equalTo(arr: any[]): Assertion; + containing(value: any): Assertion; + containingAllOf(values: any[]): Assertion; + containingAnyOf(values: any[]): Assertion; + sorted(): Assertion; + } + + interface Assert { + array(val: any[], msg?: string): void; + ofSize(val: any[], size: number, msg?: string): void; + equalTo(val: any[], array: any[], msg?: string): void; + containing(val: any[], value: any, msg?: string): void; + containingAllOf(val: any[], values: any[], msg?: string): void; + containingAnyOf(val: any[], values: any[], msg?: string): void; + sorted(val: any[], msg?: string): void; + } + } + + interface Array { + should: Chai.Assertion; + } +} + +declare function chaiArrays(chai: any, utils: any): void; +export = chaiArrays; diff --git a/types/chai-arrays/tsconfig.json b/types/chai-arrays/tsconfig.json new file mode 100644 index 0000000000..a555dfb8e2 --- /dev/null +++ b/types/chai-arrays/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "chai-arrays-tests.ts" + ] +} diff --git a/types/chai-arrays/tslint.json b/types/chai-arrays/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/chai-arrays/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }