mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 14:59:37 +08:00
Added type definitions for chai-arrays (#16266)
This commit is contained in:
committed by
Mohamed Hegazy
parent
2c0494ee20
commit
b794bedb72
76
types/chai-arrays/chai-arrays-tests.ts
Normal file
76
types/chai-arrays/chai-arrays-tests.ts
Normal file
@@ -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');
|
||||
37
types/chai-arrays/index.d.ts
vendored
Normal file
37
types/chai-arrays/index.d.ts
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Type definitions for chai-arrays 1.0
|
||||
// Project: https://github.com/GaneshSPatil/chai-arrays
|
||||
// Definitions by: Clément Prévot <https://github.com/clementprevot/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
///<reference types="chai" />
|
||||
|
||||
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<T> {
|
||||
should: Chai.Assertion;
|
||||
}
|
||||
}
|
||||
|
||||
declare function chaiArrays(chai: any, utils: any): void;
|
||||
export = chaiArrays;
|
||||
22
types/chai-arrays/tsconfig.json
Normal file
22
types/chai-arrays/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/chai-arrays/tslint.json
Normal file
1
types/chai-arrays/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user