mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-18 07:51:48 +08:00
[chai] add missing methods to assert
This commit is contained in:
@@ -1677,4 +1677,80 @@ suite('assert', () => {
|
||||
assert.notFrozen(obj);
|
||||
assert.notFrozen(obj, 'message');
|
||||
});
|
||||
|
||||
test('hasAnyKeys', () => {
|
||||
assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
|
||||
assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
|
||||
assert.hasAnyKeys(new Map<any, any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
||||
assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
||||
});
|
||||
|
||||
test('hasAllKeys', () => {
|
||||
assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
|
||||
assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337});
|
||||
assert.hasAllKeys(new Map<any,any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
||||
assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
||||
});
|
||||
|
||||
test('containsAllKeys', () => {
|
||||
assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'baz']);
|
||||
assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
|
||||
assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, baz: 1337});
|
||||
assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337});
|
||||
assert.containsAllKeys(new Map<any,any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}]);
|
||||
assert.containsAllKeys(new Map<any,any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
||||
assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}]);
|
||||
assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
||||
});
|
||||
|
||||
test('doesNotHaveAnyKeys', () => {
|
||||
assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
|
||||
assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
|
||||
assert.doesNotHaveAnyKeys(new Map<any,any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
|
||||
assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{one: 'two'}, 'example']);
|
||||
});
|
||||
|
||||
test('doesNotHaveAllKeys', () => {
|
||||
assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
|
||||
assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
|
||||
assert.doesNotHaveAllKeys(new Map<any,any>([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
|
||||
assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{one: 'two'}, 'example']);
|
||||
});
|
||||
|
||||
test('hasAnyDeepKeys', () => {
|
||||
assert.hasAnyDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
|
||||
assert.hasAnyDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [1, 2]]), [{one: 'one'}, {two: 'two'}]);
|
||||
assert.hasAnyDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
|
||||
assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
|
||||
assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {three: 'three'}]);
|
||||
assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
|
||||
});
|
||||
|
||||
test('hasAllDeepKeys', () => {
|
||||
assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne']]), {one: 'one'});
|
||||
assert.hasAllDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
|
||||
assert.hasAllDeepKeys(new Set([{one: 'one'}]), {one: 'one'});
|
||||
assert.hasAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
|
||||
});
|
||||
|
||||
test('containsAllDeepKeys', () => {
|
||||
assert.containsAllDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
|
||||
assert.containsAllDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
|
||||
assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
|
||||
assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
|
||||
});
|
||||
|
||||
test('doesNotHaveAnyDeepKeys', () => {
|
||||
assert.doesNotHaveAnyDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
|
||||
assert.doesNotHaveAnyDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
|
||||
assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
|
||||
assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
|
||||
});
|
||||
|
||||
test('doesNotHaveAllDeepKeys', () => {
|
||||
assert.doesNotHaveAllDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
|
||||
assert.doesNotHaveAllDeepKeys(new Map<any,any>([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {one: 'one'}]);
|
||||
assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
|
||||
assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {fifty: 'fifty'}]);
|
||||
});
|
||||
});
|
||||
|
||||
130
types/chai/index.d.ts
vendored
130
types/chai/index.d.ts
vendored
@@ -1360,6 +1360,136 @@ declare namespace Chai {
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
isNotEmpty<T>(object: T, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has at least one of the `keys` provided.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
hasAnyKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has all and only all of the `keys` provided.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
hasAllKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has all of the `keys` provided but may have more keys not listed.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
containsAllKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has none of the `keys` provided.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
doesNotHaveAnyKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` does not have at least one of the `keys` provided.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
doesNotHaveAllKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has at least one of the `keys` provided.
|
||||
* Since Sets and Maps can have objects as keys you can use this assertion to perform
|
||||
* a deep comparison.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
hasAnyDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` has all and only all of the `keys` provided.
|
||||
* Since Sets and Maps can have objects as keys you can use this assertion to perform
|
||||
* a deep comparison.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
hasAllDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` contains all of the `keys` provided.
|
||||
* Since Sets and Maps can have objects as keys you can use this assertion to perform
|
||||
* a deep comparison.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
containsAllDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` contains all of the `keys` provided.
|
||||
* Since Sets and Maps can have objects as keys you can use this assertion to perform
|
||||
* a deep comparison.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
doesNotHaveAnyDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
|
||||
/**
|
||||
* Asserts that `object` contains all of the `keys` provided.
|
||||
* Since Sets and Maps can have objects as keys you can use this assertion to perform
|
||||
* a deep comparison.
|
||||
* You can also provide a single object instead of a `keys` array and its keys
|
||||
* will be used as the expected set of keys.
|
||||
*
|
||||
* @type T Type of object.
|
||||
* @param object Object to test.
|
||||
* @param keys Keys to check
|
||||
* @param message Message to display on error.
|
||||
*/
|
||||
doesNotHaveAllDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
|
||||
Reference in New Issue
Block a user