From 62ebe0a870238e5c01ebadea1db345b4e00268b6 Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Sun, 23 Dec 2018 14:34:11 +0000 Subject: [PATCH] refactor(types): move types to each matcher --- jasmine-matchers.d.ts | 87 --------------------------------- package.json | 2 +- src/toBeAfter.ts | 17 ++++++- src/toBeArray.ts | 13 ++++- src/toBeArrayOfBooleans.ts | 13 ++++- src/toBeArrayOfNumbers.ts | 13 ++++- src/toBeArrayOfObjects.ts | 13 ++++- src/toBeArrayOfSize.ts | 16 +++++- src/toBeArrayOfStrings.ts | 13 ++++- src/toBeBefore.ts | 15 +++++- src/toBeBoolean.ts | 13 ++++- src/toBeCalculable.ts | 10 ++++ src/toBeDate.ts | 13 ++++- src/toBeEmptyArray.ts | 14 +++++- src/toBeEmptyObject.ts | 13 ++++- src/toBeEmptyString.ts | 12 ++++- src/toBeEvenNumber.ts | 13 ++++- src/toBeFalse.ts | 14 +++++- src/toBeFunction.ts | 13 ++++- src/toBeGreaterThanOrEqualTo.ts | 19 ++++++- src/toBeHtmlString.ts | 12 ++++- src/toBeIso8601.ts | 12 ++++- src/toBeJsonString.ts | 12 ++++- src/toBeLessThanOrEqualTo.ts | 19 ++++++- src/toBeLongerThan.ts | 15 +++++- src/toBeNear.ts | 16 +++++- src/toBeNonEmptyArray.ts | 13 ++++- src/toBeNonEmptyObject.ts | 13 ++++- src/toBeNonEmptyString.ts | 13 ++++- src/toBeNumber.ts | 13 ++++- src/toBeObject.ts | 13 ++++- src/toBeOddNumber.ts | 14 +++++- src/toBeRegExp.ts | 12 ++++- src/toBeSameLengthAs.ts | 15 +++++- src/toBeShorterThan.ts | 15 +++++- src/toBeString.ts | 13 ++++- src/toBeTrue.ts | 14 +++++- src/toBeValidDate.ts | 13 ++++- src/toBeWhitespace.ts | 13 ++++- src/toBeWholeNumber.ts | 12 ++++- src/toBeWithinRange.ts | 16 +++++- src/toEndWith.ts | 15 +++++- src/toHaveArray.ts | 13 ++++- src/toHaveArrayOfBooleans.ts | 18 ++++++- src/toHaveArrayOfNumbers.ts | 18 ++++++- src/toHaveArrayOfObjects.ts | 18 ++++++- src/toHaveArrayOfSize.ts | 16 +++++- src/toHaveArrayOfStrings.ts | 18 ++++++- src/toHaveBoolean.ts | 16 +++++- src/toHaveCalculable.ts | 18 ++++++- src/toHaveDate.ts | 13 ++++- src/toHaveDateAfter.ts | 16 +++++- src/toHaveDateBefore.ts | 16 +++++- src/toHaveEmptyArray.ts | 18 ++++++- src/toHaveEmptyObject.ts | 18 ++++++- src/toHaveEmptyString.ts | 18 ++++++- src/toHaveEvenNumber.ts | 18 ++++++- src/toHaveFalse.ts | 13 ++++- src/toHaveHtmlString.ts | 18 ++++++- src/toHaveIso8601.ts | 16 +++++- src/toHaveJsonString.ts | 18 ++++++- src/toHaveMember.ts | 15 +++++- src/toHaveMethod.ts | 16 +++++- src/toHaveNonEmptyArray.ts | 18 ++++++- src/toHaveNonEmptyObject.ts | 18 ++++++- src/toHaveNonEmptyString.ts | 18 ++++++- src/toHaveNumber.ts | 16 +++++- src/toHaveNumberWithinRange.ts | 23 ++++++++- src/toHaveObject.ts | 16 +++++- src/toHaveOddNumber.ts | 16 +++++- src/toHaveString.ts | 16 +++++- src/toHaveStringLongerThan.ts | 21 +++++++- src/toHaveStringSameLengthAs.ts | 21 +++++++- src/toHaveStringShorterThan.ts | 21 +++++++- src/toHaveTrue.ts | 13 ++++- src/toHaveUndefined.ts | 15 +++++- src/toHaveWhitespaceString.ts | 18 ++++++- src/toHaveWholeNumber.ts | 18 ++++++- src/toStartWith.ts | 15 +++++- src/toThrowAnyError.ts | 12 ++++- src/toThrowErrorOfType.ts | 15 +++++- tslint.json | 1 + 82 files changed, 1126 insertions(+), 172 deletions(-) delete mode 100644 jasmine-matchers.d.ts diff --git a/jasmine-matchers.d.ts b/jasmine-matchers.d.ts deleted file mode 100644 index 5bf4726..0000000 --- a/jasmine-matchers.d.ts +++ /dev/null @@ -1,87 +0,0 @@ -declare namespace jasmine { - interface Matchers { - toBeAfter(otherDate: Date, expectationFailOutput?: any): boolean; - toBeArray(expectationFailOutput?: any): boolean; - toBeArrayOfBooleans(expectationFailOutput?: any): boolean; - toBeArrayOfNumbers(expectationFailOutput?: any): boolean; - toBeArrayOfObjects(expectationFailOutput?: any): boolean; - toBeArrayOfSize(size: number, expectationFailOutput?: any): boolean; - toBeArrayOfStrings(expectationFailOutput?: any): boolean; - toBeBefore(otherDate: Date, expectationFailOutput?: any): boolean; - toBeBoolean(expectationFailOutput?: any): boolean; - toBeCalculable(expectationFailOutput?: any): boolean; - toBeDate(expectationFailOutput?: any): boolean; - toBeEmptyArray(expectationFailOutput?: any): boolean; - toBeEmptyObject(expectationFailOutput?: any): boolean; - toBeEmptyString(expectationFailOutput?: any): boolean; - toBeEvenNumber(expectationFailOutput?: any): boolean; - toBeFalse(expectationFailOutput?: any): boolean; - toBeFunction(expectationFailOutput?: any): boolean; - toBeGreaterThanOrEqualTo(otherNumber: number, expectationFailOutput?: any): boolean; - toBeHtmlString(expectationFailOutput?: any): boolean; - toBeIso8601(expectationFailOutput?: any): boolean; - toBeJsonString(expectationFailOutput?: any): boolean; - toBeLessThanOrEqualTo(otherNumber: number, expectationFailOutput?: any): boolean; - toBeLongerThan(other: string, expectationFailOutput?: any): boolean; - toBeNear(number: number, epsilon: number, expectationFailOutput?: any): boolean; - toBeNonEmptyArray(expectationFailOutput?: any): boolean; - toBeNonEmptyObject(expectationFailOutput?: any): boolean; - toBeNonEmptyString(expectationFailOutput?: any): boolean; - toBeNumber(expectationFailOutput?: any): boolean; - toBeObject(expectationFailOutput?: any): boolean; - toBeOddNumber(expectationFailOutput?: any): boolean; - toBeRegExp(expectationFailOutput?: any): boolean; - toBeSameLengthAs(other: string, expectationFailOutput?: any): boolean; - toBeShorterThan(other: string, expectationFailOutput?: any): boolean; - toBeString(expectationFailOutput?: any): boolean; - toBeTrue(expectationFailOutput?: any): boolean; - toBeValidDate(expectationFailOutput?: any): boolean; - toBeWhitespace(expectationFailOutput?: any): boolean; - toBeWholeNumber(expectationFailOutput?: any): boolean; - toBeWithinRange(floor: number, ceiling: number, expectationFailOutput?: any): boolean; - - toEndWith(subString: string, expectationFailOutput?: any): boolean; - - toHaveArray(key: string, expectationFailOutput?: any): boolean; - toHaveArrayOfBooleans(key: string, expectationFailOutput?: any): boolean; - toHaveArrayOfNumbers(key: string, expectationFailOutput?: any): boolean; - toHaveArrayOfObjects(key: string, expectationFailOutput?: any): boolean; - toHaveArrayOfSize(key: string, size?: number, expectationFailOutput?: any): boolean; - toHaveArrayOfStrings(key: string, expectationFailOutput?: any): boolean; - toHaveBoolean(key: string, expectationFailOutput?: any): boolean; - toHaveCalculable(key: string, expectationFailOutput?: any): boolean; - toHaveDate(key: string, expectationFailOutput?: any): boolean; - toHaveDateAfter(key: string, otherDate: Date, expectationFailOutput?: any): boolean; - toHaveDateBefore(key: string, otherDate: Date, expectationFailOutput?: any): boolean; - toHaveEmptyArray(key: string, expectationFailOutput?: any): boolean; - toHaveEmptyObject(key: string, expectationFailOutput?: any): boolean; - toHaveEmptyString(key: string, expectationFailOutput?: any): boolean; - toHaveEvenNumber(key: string, expectationFailOutput?: any): boolean; - toHaveFalse(key: string, expectationFailOutput?: any): boolean; - toHaveHtmlString(key: string, expectationFailOutput?: any): boolean; - toHaveIso8601(key: string, expectationFailOutput?: any): boolean; - toHaveJsonString(key: string, expectationFailOutput?: any): boolean; - toHaveMember(key: string, expectationFailOutput?: any): boolean; - toHaveMethod(key: string, expectationFailOutput?: any): boolean; - toHaveNonEmptyArray(key: string, expectationFailOutput?: any): boolean; - toHaveNonEmptyObject(key: string, expectationFailOutput?: any): boolean; - toHaveNonEmptyString(key: string, expectationFailOutput?: any): boolean; - toHaveNumber(key: string, expectationFailOutput?: any): boolean; - toHaveNumberWithinRange(key: string, floor: number, ceiling: number, expectationFailOutput?: any): boolean; - toHaveObject(key: string, expectationFailOutput?: any): boolean; - toHaveOddNumber(key: string, expectationFailOutput?: any): boolean; - toHaveString(key: string, expectationFailOutput?: any): boolean; - toHaveStringLongerThan(key: string, other: string, expectationFailOutput?: any): boolean; - toHaveStringSameLengthAs(key: string, other: string, expectationFailOutput?: any): boolean; - toHaveStringShorterThan(key: string, other: string, expectationFailOutput?: any): boolean; - toHaveTrue(key: string, expectationFailOutput?: any): boolean; - toHaveUndefined(key: string, expectationFailOutput?: any): boolean; - toHaveWhitespaceString(key: string, expectationFailOutput?: any): boolean; - toHaveWholeNumber(key: string, expectationFailOutput?: any): boolean; - - toStartWith(subString: string, expectationFailOutput?: any): boolean; - - toThrowAnyError(expectationFailOutput?: any): boolean; - toThrowErrorOfType(type: string, expectationFailOutput?: any): boolean; - } -} diff --git a/package.json b/package.json index fbc2ae4..68f089f 100644 --- a/package.json +++ b/package.json @@ -90,5 +90,5 @@ "test:jest": "jest", "test:local": "karma start karma/base.conf.js --browsers Chrome" }, - "types": "./jasmine-matchers.d.ts" + "types": "dist/index.d.ts" } diff --git a/src/toBeAfter.ts b/src/toBeAfter.ts index d60ce76..6cce9a5 100644 --- a/src/toBeAfter.ts +++ b/src/toBeAfter.ts @@ -1,2 +1,17 @@ import { toBeBefore } from './toBeBefore'; -export const toBeAfter = (otherDate, actual) => toBeBefore(actual, otherDate); + +export type ToBeAfter = ( + otherDate: Date, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeAfter: ToBeAfter; + } + } +} + +export const toBeAfter: ToBeAfter = (otherDate, actual) => + toBeBefore(actual, otherDate); diff --git a/src/toBeArray.ts b/src/toBeArray.ts index 4b5ff65..a000021 100644 --- a/src/toBeArray.ts +++ b/src/toBeArray.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeArray = is.Array; + +export type ToBeArray = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArray: ToBeArray; + } + } +} + +export const toBeArray: ToBeArray = is.Array; diff --git a/src/toBeArrayOfBooleans.ts b/src/toBeArrayOfBooleans.ts index 3735f34..be204d7 100644 --- a/src/toBeArrayOfBooleans.ts +++ b/src/toBeArrayOfBooleans.ts @@ -1,5 +1,16 @@ import { every } from './lib/every'; import { toBeArray } from './toBeArray'; import { toBeBoolean } from './toBeBoolean'; -export const toBeArrayOfBooleans = (actual) => + +export type ToBeArrayOfBooleans = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArrayOfBooleans: ToBeArrayOfBooleans; + } + } +} + +export const toBeArrayOfBooleans: ToBeArrayOfBooleans = (actual) => toBeArray(actual) && every(actual, toBeBoolean); diff --git a/src/toBeArrayOfNumbers.ts b/src/toBeArrayOfNumbers.ts index b8e292c..61f5dc3 100644 --- a/src/toBeArrayOfNumbers.ts +++ b/src/toBeArrayOfNumbers.ts @@ -1,5 +1,16 @@ import { every } from './lib/every'; import { toBeArray } from './toBeArray'; import { toBeNumber } from './toBeNumber'; -export const toBeArrayOfNumbers = (actual) => + +export type ToBeArrayOfNumbers = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArrayOfNumbers: ToBeArrayOfNumbers; + } + } +} + +export const toBeArrayOfNumbers: ToBeArrayOfNumbers = (actual) => toBeArray(actual) && every(actual, toBeNumber); diff --git a/src/toBeArrayOfObjects.ts b/src/toBeArrayOfObjects.ts index 943e1bd..71efda9 100644 --- a/src/toBeArrayOfObjects.ts +++ b/src/toBeArrayOfObjects.ts @@ -1,5 +1,16 @@ import { every } from './lib/every'; import { toBeArray } from './toBeArray'; import { toBeObject } from './toBeObject'; -export const toBeArrayOfObjects = (actual) => + +export type ToBeArrayOfObjects = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArrayOfObjects: ToBeArrayOfObjects; + } + } +} + +export const toBeArrayOfObjects: ToBeArrayOfObjects = (actual) => toBeArray(actual) && every(actual, toBeObject); diff --git a/src/toBeArrayOfSize.ts b/src/toBeArrayOfSize.ts index 40faebe..b75daee 100644 --- a/src/toBeArrayOfSize.ts +++ b/src/toBeArrayOfSize.ts @@ -1,3 +1,17 @@ import { toBeArray } from './toBeArray'; -export const toBeArrayOfSize = (size, actual) => + +export type ToBeArrayOfSize = ( + size: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArrayOfSize: ToBeArrayOfSize; + } + } +} + +export const toBeArrayOfSize: ToBeArrayOfSize = (size, actual) => toBeArray(actual) && actual.length === size; diff --git a/src/toBeArrayOfStrings.ts b/src/toBeArrayOfStrings.ts index 479006d..d102d71 100644 --- a/src/toBeArrayOfStrings.ts +++ b/src/toBeArrayOfStrings.ts @@ -1,5 +1,16 @@ import { every } from './lib/every'; import { toBeArray } from './toBeArray'; import { toBeString } from './toBeString'; -export const toBeArrayOfStrings = (actual) => + +export type ToBeArrayOfStrings = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeArrayOfStrings: ToBeArrayOfStrings; + } + } +} + +export const toBeArrayOfStrings: ToBeArrayOfStrings = (actual) => toBeArray(actual) && every(actual, toBeString); diff --git a/src/toBeBefore.ts b/src/toBeBefore.ts index abffd52..446d85c 100644 --- a/src/toBeBefore.ts +++ b/src/toBeBefore.ts @@ -1,6 +1,19 @@ import { toBeDate } from './toBeDate'; -export const toBeBefore = (otherDate, actual) => +export type ToBeBefore = ( + otherDate: Date, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeBefore: ToBeBefore; + } + } +} + +export const toBeBefore: ToBeBefore = (otherDate, actual) => toBeDate(actual) && toBeDate(otherDate) && actual.getTime() < otherDate.getTime(); diff --git a/src/toBeBoolean.ts b/src/toBeBoolean.ts index f1f1aa0..620fc22 100644 --- a/src/toBeBoolean.ts +++ b/src/toBeBoolean.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeBoolean = is.Boolean; + +export type ToBeBoolean = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeBoolean: ToBeBoolean; + } + } +} + +export const toBeBoolean: ToBeBoolean = is.Boolean; diff --git a/src/toBeCalculable.ts b/src/toBeCalculable.ts index 098fbe4..64d9945 100644 --- a/src/toBeCalculable.ts +++ b/src/toBeCalculable.ts @@ -1,3 +1,13 @@ +export type ToBeCalculable = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeCalculable: ToBeCalculable; + } + } +} + export function toBeCalculable(actual) { return !isNaN(actual * 2); } diff --git a/src/toBeDate.ts b/src/toBeDate.ts index a1a35ae..b6136cb 100644 --- a/src/toBeDate.ts +++ b/src/toBeDate.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeDate = is.Date; + +export type ToBeDate = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeDate: ToBeDate; + } + } +} + +export const toBeDate: ToBeDate = is.Date; diff --git a/src/toBeEmptyArray.ts b/src/toBeEmptyArray.ts index 10a961b..0f68e12 100644 --- a/src/toBeEmptyArray.ts +++ b/src/toBeEmptyArray.ts @@ -1,2 +1,14 @@ import { toBeArrayOfSize } from './toBeArrayOfSize'; -export const toBeEmptyArray = (actual) => toBeArrayOfSize(0, actual); + +export type ToBeEmptyArray = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeEmptyArray: ToBeEmptyArray; + } + } +} + +export const toBeEmptyArray: ToBeEmptyArray = (actual) => + toBeArrayOfSize(0, actual); diff --git a/src/toBeEmptyObject.ts b/src/toBeEmptyObject.ts index c33d63f..568cbc9 100644 --- a/src/toBeEmptyObject.ts +++ b/src/toBeEmptyObject.ts @@ -1,4 +1,15 @@ import { is } from './lib/is'; import { keys } from './lib/keys'; -export const toBeEmptyObject = (actual) => + +export type ToBeEmptyObject = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeEmptyObject: ToBeEmptyObject; + } + } +} + +export const toBeEmptyObject: ToBeEmptyObject = (actual) => is.Object(actual) && keys(actual).length === 0; diff --git a/src/toBeEmptyString.ts b/src/toBeEmptyString.ts index b742bd4..7c8f9e9 100644 --- a/src/toBeEmptyString.ts +++ b/src/toBeEmptyString.ts @@ -1 +1,11 @@ -export const toBeEmptyString = (actual) => actual === ''; +export type ToBeEmptyString = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeEmptyString: ToBeEmptyString; + } + } +} + +export const toBeEmptyString: ToBeEmptyString = (actual) => actual === ''; diff --git a/src/toBeEvenNumber.ts b/src/toBeEvenNumber.ts index 00db2dd..3e2242e 100644 --- a/src/toBeEvenNumber.ts +++ b/src/toBeEvenNumber.ts @@ -1,3 +1,14 @@ import { toBeNumber } from './toBeNumber'; -export const toBeEvenNumber = (actual) => + +export type ToBeEvenNumber = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeEvenNumber: ToBeEvenNumber; + } + } +} + +export const toBeEvenNumber: ToBeEvenNumber = (actual) => toBeNumber(actual) && actual % 2 === 0; diff --git a/src/toBeFalse.ts b/src/toBeFalse.ts index 372db71..2f1f844 100644 --- a/src/toBeFalse.ts +++ b/src/toBeFalse.ts @@ -1,2 +1,14 @@ import { is } from './lib/is'; -export const toBeFalse = (actual) => actual === false || is.False(actual); + +export type ToBeFalse = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeFalse: ToBeFalse; + } + } +} + +export const toBeFalse: ToBeFalse = (actual) => + actual === false || is.False(actual); diff --git a/src/toBeFunction.ts b/src/toBeFunction.ts index 188df5a..d632a87 100644 --- a/src/toBeFunction.ts +++ b/src/toBeFunction.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeFunction = is.Function; + +export type ToBeFunction = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeFunction: ToBeFunction; + } + } +} + +export const toBeFunction: ToBeFunction = is.Function; diff --git a/src/toBeGreaterThanOrEqualTo.ts b/src/toBeGreaterThanOrEqualTo.ts index a4bc2e8..76402db 100644 --- a/src/toBeGreaterThanOrEqualTo.ts +++ b/src/toBeGreaterThanOrEqualTo.ts @@ -1,4 +1,19 @@ import { toBeNumber } from './toBeNumber'; -export const toBeGreaterThanOrEqualTo = (otherNumber, actual) => - toBeNumber(actual) && actual >= otherNumber; +export type ToBeGreaterThanOrEqualTo = ( + otherNumber: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeGreaterThanOrEqualTo: ToBeGreaterThanOrEqualTo; + } + } +} + +export const toBeGreaterThanOrEqualTo: ToBeGreaterThanOrEqualTo = ( + otherNumber, + actual +) => toBeNumber(actual) && actual >= otherNumber; diff --git a/src/toBeHtmlString.ts b/src/toBeHtmlString.ts index 645672a..3e1cef3 100644 --- a/src/toBeHtmlString.ts +++ b/src/toBeHtmlString.ts @@ -1,4 +1,14 @@ import { toBeString } from './toBeString'; -export const toBeHtmlString = (actual) => +export type ToBeHtmlString = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeHtmlString: ToBeHtmlString; + } + } +} + +export const toBeHtmlString: ToBeHtmlString = (actual) => toBeString(actual) && actual.search(/<("[^"]*"|'[^']*'|[^'">])*>/) !== -1; diff --git a/src/toBeIso8601.ts b/src/toBeIso8601.ts index 0184682..4e63c91 100644 --- a/src/toBeIso8601.ts +++ b/src/toBeIso8601.ts @@ -1,7 +1,17 @@ import { toBeString } from './toBeString'; import { toBeValidDate } from './toBeValidDate'; -export const toBeIso8601 = (actual) => +export type ToBeIso8601 = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeIso8601: ToBeIso8601; + } + } +} + +export const toBeIso8601: ToBeIso8601 = (actual) => toBeString(actual) && (isMatch('1999-12-31', actual) || isMatch('1999-12-31T23:59', actual) || diff --git a/src/toBeJsonString.ts b/src/toBeJsonString.ts index 90352b6..ebb6a62 100644 --- a/src/toBeJsonString.ts +++ b/src/toBeJsonString.ts @@ -1,4 +1,14 @@ -export const toBeJsonString = (actual) => { +export type ToBeJsonString = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeJsonString: ToBeJsonString; + } + } +} + +export const toBeJsonString: ToBeJsonString = (actual) => { try { return JSON.parse(actual) !== null; } catch (err) { diff --git a/src/toBeLessThanOrEqualTo.ts b/src/toBeLessThanOrEqualTo.ts index f60f079..194e208 100644 --- a/src/toBeLessThanOrEqualTo.ts +++ b/src/toBeLessThanOrEqualTo.ts @@ -1,4 +1,19 @@ import { toBeNumber } from './toBeNumber'; -export const toBeLessThanOrEqualTo = (otherNumber, actual) => - toBeNumber(actual) && actual <= otherNumber; +export type ToBeLessThanOrEqualTo = ( + otherNumber: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeLessThanOrEqualTo: ToBeLessThanOrEqualTo; + } + } +} + +export const toBeLessThanOrEqualTo: ToBeLessThanOrEqualTo = ( + otherNumber, + actual +) => toBeNumber(actual) && actual <= otherNumber; diff --git a/src/toBeLongerThan.ts b/src/toBeLongerThan.ts index c921406..d0e3275 100644 --- a/src/toBeLongerThan.ts +++ b/src/toBeLongerThan.ts @@ -1,6 +1,19 @@ import { toBeString } from './toBeString'; -export const toBeLongerThan = (otherString, actual) => +export type ToBeLongerThan = ( + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeLongerThan: ToBeLongerThan; + } + } +} + +export const toBeLongerThan: ToBeLongerThan = (otherString, actual) => toBeString(actual) && toBeString(otherString) && actual.length > otherString.length; diff --git a/src/toBeNear.ts b/src/toBeNear.ts index 4c58bda..5d01074 100644 --- a/src/toBeNear.ts +++ b/src/toBeNear.ts @@ -1,4 +1,18 @@ import { toBeNumber } from './toBeNumber'; -export const toBeNear = (value, epsilon, actual) => +export type ToBeNear = ( + value: number, + epsilon: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeNear: ToBeNear; + } + } +} + +export const toBeNear: ToBeNear = (value, epsilon, actual) => toBeNumber(actual) && actual >= value - epsilon && actual <= value + epsilon; diff --git a/src/toBeNonEmptyArray.ts b/src/toBeNonEmptyArray.ts index 30ffd1b..2c852fa 100644 --- a/src/toBeNonEmptyArray.ts +++ b/src/toBeNonEmptyArray.ts @@ -1,3 +1,14 @@ import { is } from './lib/is'; -export const toBeNonEmptyArray = (actual) => + +export type ToBeNonEmptyArray = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeNonEmptyArray: ToBeNonEmptyArray; + } + } +} + +export const toBeNonEmptyArray: ToBeNonEmptyArray = (actual) => is.Array(actual) && actual.length > 0; diff --git a/src/toBeNonEmptyObject.ts b/src/toBeNonEmptyObject.ts index 46da6a9..7ce1c8e 100644 --- a/src/toBeNonEmptyObject.ts +++ b/src/toBeNonEmptyObject.ts @@ -1,4 +1,15 @@ import { is } from './lib/is'; import { keys } from './lib/keys'; -export const toBeNonEmptyObject = (actual) => + +export type ToBeNonEmptyObject = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeNonEmptyObject: ToBeNonEmptyObject; + } + } +} + +export const toBeNonEmptyObject: ToBeNonEmptyObject = (actual) => is.Object(actual) && keys(actual).length > 0; diff --git a/src/toBeNonEmptyString.ts b/src/toBeNonEmptyString.ts index 75c795c..06ecff7 100644 --- a/src/toBeNonEmptyString.ts +++ b/src/toBeNonEmptyString.ts @@ -1,3 +1,14 @@ import { toBeString } from './toBeString'; -export const toBeNonEmptyString = (actual) => + +export type ToBeNonEmptyString = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeNonEmptyString: ToBeNonEmptyString; + } + } +} + +export const toBeNonEmptyString: ToBeNonEmptyString = (actual) => toBeString(actual) && actual.length > 0; diff --git a/src/toBeNumber.ts b/src/toBeNumber.ts index cc9a9fc..cd586bc 100644 --- a/src/toBeNumber.ts +++ b/src/toBeNumber.ts @@ -1,3 +1,14 @@ import { is } from './lib/is'; -export const toBeNumber = (actual) => + +export type ToBeNumber = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeNumber: ToBeNumber; + } + } +} + +export const toBeNumber: ToBeNumber = (actual) => !isNaN(parseFloat(actual)) && !is.String(actual); diff --git a/src/toBeObject.ts b/src/toBeObject.ts index 7f4e251..f6a0b72 100644 --- a/src/toBeObject.ts +++ b/src/toBeObject.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeObject = is.Object; + +export type ToBeObject = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeObject: ToBeObject; + } + } +} + +export const toBeObject: ToBeObject = is.Object; diff --git a/src/toBeOddNumber.ts b/src/toBeOddNumber.ts index bd5196e..8d18272 100644 --- a/src/toBeOddNumber.ts +++ b/src/toBeOddNumber.ts @@ -1,2 +1,14 @@ import { toBeNumber } from './toBeNumber'; -export const toBeOddNumber = (actual) => toBeNumber(actual) && actual % 2 !== 0; + +export type ToBeOddNumber = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeOddNumber: ToBeOddNumber; + } + } +} + +export const toBeOddNumber: ToBeOddNumber = (actual) => + toBeNumber(actual) && actual % 2 !== 0; diff --git a/src/toBeRegExp.ts b/src/toBeRegExp.ts index 274cc5b..1723ad9 100644 --- a/src/toBeRegExp.ts +++ b/src/toBeRegExp.ts @@ -1 +1,11 @@ -export const toBeRegExp = (actual) => actual instanceof RegExp; +export type ToBeRegExp = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeRegExp: ToBeRegExp; + } + } +} + +export const toBeRegExp: ToBeRegExp = (actual) => actual instanceof RegExp; diff --git a/src/toBeSameLengthAs.ts b/src/toBeSameLengthAs.ts index d861aff..b1c2ba0 100644 --- a/src/toBeSameLengthAs.ts +++ b/src/toBeSameLengthAs.ts @@ -1,6 +1,19 @@ import { toBeString } from './toBeString'; -export const toBeSameLengthAs = (otherString, actual) => +export type ToBeSameLengthAs = ( + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeSameLengthAs: ToBeSameLengthAs; + } + } +} + +export const toBeSameLengthAs: ToBeSameLengthAs = (otherString, actual) => toBeString(actual) && toBeString(otherString) && actual.length === otherString.length; diff --git a/src/toBeShorterThan.ts b/src/toBeShorterThan.ts index 821cf2a..bba69e5 100644 --- a/src/toBeShorterThan.ts +++ b/src/toBeShorterThan.ts @@ -1,6 +1,19 @@ import { toBeString } from './toBeString'; -export const toBeShorterThan = (otherString, actual) => +export type ToBeShorterThan = ( + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeShorterThan: ToBeShorterThan; + } + } +} + +export const toBeShorterThan: ToBeShorterThan = (otherString, actual) => toBeString(actual) && toBeString(otherString) && actual.length < otherString.length; diff --git a/src/toBeString.ts b/src/toBeString.ts index 8290ca6..5ce9cdd 100644 --- a/src/toBeString.ts +++ b/src/toBeString.ts @@ -1,2 +1,13 @@ import { is } from './lib/is'; -export const toBeString = is.String; + +export type ToBeString = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeString: ToBeString; + } + } +} + +export const toBeString: ToBeString = is.String; diff --git a/src/toBeTrue.ts b/src/toBeTrue.ts index bd4a7f7..be5d52d 100644 --- a/src/toBeTrue.ts +++ b/src/toBeTrue.ts @@ -1,2 +1,14 @@ import { is } from './lib/is'; -export const toBeTrue = (actual) => actual === true || is.True(actual); + +export type ToBeTrue = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeTrue: ToBeTrue; + } + } +} + +export const toBeTrue: ToBeTrue = (actual) => + actual === true || is.True(actual); diff --git a/src/toBeValidDate.ts b/src/toBeValidDate.ts index 49028cc..712ff28 100644 --- a/src/toBeValidDate.ts +++ b/src/toBeValidDate.ts @@ -1,3 +1,14 @@ import { is } from './lib/is'; -export const toBeValidDate = (actual) => + +export type ToBeValidDate = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeValidDate: ToBeValidDate; + } + } +} + +export const toBeValidDate: ToBeValidDate = (actual) => is.Date(actual) && !isNaN(actual.getTime()); diff --git a/src/toBeWhitespace.ts b/src/toBeWhitespace.ts index 1d0bada..116553e 100644 --- a/src/toBeWhitespace.ts +++ b/src/toBeWhitespace.ts @@ -1,3 +1,14 @@ import { toBeString } from './toBeString'; -export const toBeWhitespace = (actual) => + +export type ToBeWhitespace = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeWhitespace: ToBeWhitespace; + } + } +} + +export const toBeWhitespace: ToBeWhitespace = (actual) => toBeString(actual) && actual.search(/\S/) === -1; diff --git a/src/toBeWholeNumber.ts b/src/toBeWholeNumber.ts index a64be92..e050614 100644 --- a/src/toBeWholeNumber.ts +++ b/src/toBeWholeNumber.ts @@ -1,4 +1,14 @@ import { toBeNumber } from './toBeNumber'; -export const toBeWholeNumber = (actual) => +export type ToBeWholeNumber = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeWholeNumber: ToBeWholeNumber; + } + } +} + +export const toBeWholeNumber: ToBeWholeNumber = (actual) => toBeNumber(actual) && (actual === 0 || actual % 1 === 0); diff --git a/src/toBeWithinRange.ts b/src/toBeWithinRange.ts index f528963..dada758 100644 --- a/src/toBeWithinRange.ts +++ b/src/toBeWithinRange.ts @@ -1,4 +1,18 @@ import { toBeNumber } from './toBeNumber'; -export const toBeWithinRange = (floor, ceiling, actual) => +export type ToBeWithinRange = ( + floor: number, + ceiling: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toBeWithinRange: ToBeWithinRange; + } + } +} + +export const toBeWithinRange: ToBeWithinRange = (floor, ceiling, actual) => toBeNumber(actual) && actual >= floor && actual <= ceiling; diff --git a/src/toEndWith.ts b/src/toEndWith.ts index c389046..d51da98 100644 --- a/src/toEndWith.ts +++ b/src/toEndWith.ts @@ -1,6 +1,19 @@ import { toBeNonEmptyString } from './toBeNonEmptyString'; -export const toEndWith = (subString, actual) => +export type ToEndWith = ( + subString: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toEndWith: ToEndWith; + } + } +} + +export const toEndWith: ToEndWith = (subString, actual) => toBeNonEmptyString(actual) && toBeNonEmptyString(subString) && actual.slice(actual.length - subString.length, actual.length) === subString; diff --git a/src/toHaveArray.ts b/src/toHaveArray.ts index 3354e50..5a0bb5d 100644 --- a/src/toHaveArray.ts +++ b/src/toHaveArray.ts @@ -1,3 +1,14 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeArray } from './toBeArray'; -export const toHaveArray = memberMatcherFor(toBeArray); + +export type ToHaveArray = (key: string, expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArray: ToHaveArray; + } + } +} + +export const toHaveArray: ToHaveArray = memberMatcherFor(toBeArray); diff --git a/src/toHaveArrayOfBooleans.ts b/src/toHaveArrayOfBooleans.ts index df58f80..4ed1cec 100644 --- a/src/toHaveArrayOfBooleans.ts +++ b/src/toHaveArrayOfBooleans.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeArrayOfBooleans } from './toBeArrayOfBooleans'; -export const toHaveArrayOfBooleans = memberMatcherFor(toBeArrayOfBooleans); + +export type ToHaveArrayOfBooleans = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArrayOfBooleans: ToHaveArrayOfBooleans; + } + } +} + +export const toHaveArrayOfBooleans: ToHaveArrayOfBooleans = memberMatcherFor( + toBeArrayOfBooleans +); diff --git a/src/toHaveArrayOfNumbers.ts b/src/toHaveArrayOfNumbers.ts index 10e45f7..0d88d09 100644 --- a/src/toHaveArrayOfNumbers.ts +++ b/src/toHaveArrayOfNumbers.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeArrayOfNumbers } from './toBeArrayOfNumbers'; -export const toHaveArrayOfNumbers = memberMatcherFor(toBeArrayOfNumbers); + +export type ToHaveArrayOfNumbers = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArrayOfNumbers: ToHaveArrayOfNumbers; + } + } +} + +export const toHaveArrayOfNumbers: ToHaveArrayOfNumbers = memberMatcherFor( + toBeArrayOfNumbers +); diff --git a/src/toHaveArrayOfObjects.ts b/src/toHaveArrayOfObjects.ts index 73efbd1..953462f 100644 --- a/src/toHaveArrayOfObjects.ts +++ b/src/toHaveArrayOfObjects.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeArrayOfObjects } from './toBeArrayOfObjects'; -export const toHaveArrayOfObjects = memberMatcherFor(toBeArrayOfObjects); + +export type ToHaveArrayOfObjects = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArrayOfObjects: ToHaveArrayOfObjects; + } + } +} + +export const toHaveArrayOfObjects: ToHaveArrayOfObjects = memberMatcherFor( + toBeArrayOfObjects +); diff --git a/src/toHaveArrayOfSize.ts b/src/toHaveArrayOfSize.ts index c418df0..90819e4 100644 --- a/src/toHaveArrayOfSize.ts +++ b/src/toHaveArrayOfSize.ts @@ -1,5 +1,19 @@ import { toBeArrayOfSize } from './toBeArrayOfSize'; import { toBeObject } from './toBeObject'; -export const toHaveArrayOfSize = (key, size, actual) => +export type ToHaveArrayOfSize = ( + key: string, + size?: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArrayOfSize: ToHaveArrayOfSize; + } + } +} + +export const toHaveArrayOfSize: ToHaveArrayOfSize = (key, size, actual) => toBeObject(actual) && toBeArrayOfSize(size, actual[key]); diff --git a/src/toHaveArrayOfStrings.ts b/src/toHaveArrayOfStrings.ts index f39dd87..75f9521 100644 --- a/src/toHaveArrayOfStrings.ts +++ b/src/toHaveArrayOfStrings.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeArrayOfStrings } from './toBeArrayOfStrings'; -export const toHaveArrayOfStrings = memberMatcherFor(toBeArrayOfStrings); + +export type ToHaveArrayOfStrings = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveArrayOfStrings: ToHaveArrayOfStrings; + } + } +} + +export const toHaveArrayOfStrings: ToHaveArrayOfStrings = memberMatcherFor( + toBeArrayOfStrings +); diff --git a/src/toHaveBoolean.ts b/src/toHaveBoolean.ts index 41c9067..dbd7216 100644 --- a/src/toHaveBoolean.ts +++ b/src/toHaveBoolean.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeBoolean } from './toBeBoolean'; -export const toHaveBoolean = memberMatcherFor(toBeBoolean); + +export type ToHaveBoolean = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveBoolean: ToHaveBoolean; + } + } +} + +export const toHaveBoolean: ToHaveBoolean = memberMatcherFor(toBeBoolean); diff --git a/src/toHaveCalculable.ts b/src/toHaveCalculable.ts index 575c071..1c0861e 100644 --- a/src/toHaveCalculable.ts +++ b/src/toHaveCalculable.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeCalculable } from './toBeCalculable'; -export const toHaveCalculable = memberMatcherFor(toBeCalculable); + +export type ToHaveCalculable = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveCalculable: ToHaveCalculable; + } + } +} + +export const toHaveCalculable: ToHaveCalculable = memberMatcherFor( + toBeCalculable +); diff --git a/src/toHaveDate.ts b/src/toHaveDate.ts index 77b0633..62da3ae 100644 --- a/src/toHaveDate.ts +++ b/src/toHaveDate.ts @@ -1,3 +1,14 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeDate } from './toBeDate'; -export const toHaveDate = memberMatcherFor(toBeDate); + +export type ToHaveDate = (key: string, expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveDate: ToHaveDate; + } + } +} + +export const toHaveDate: ToHaveDate = memberMatcherFor(toBeDate); diff --git a/src/toHaveDateAfter.ts b/src/toHaveDateAfter.ts index f2f6af8..ad0ba32 100644 --- a/src/toHaveDateAfter.ts +++ b/src/toHaveDateAfter.ts @@ -1,5 +1,19 @@ import { toBeAfter } from './toBeAfter'; import { toBeObject } from './toBeObject'; -export const toHaveDateAfter = (key, date, actual) => +export type ToHaveDateAfter = ( + key: string, + otherDate: Date, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveDateAfter: ToHaveDateAfter; + } + } +} + +export const toHaveDateAfter: ToHaveDateAfter = (key, date, actual) => toBeObject(actual) && toBeAfter(date, actual[key]); diff --git a/src/toHaveDateBefore.ts b/src/toHaveDateBefore.ts index b415b07..0c4234d 100644 --- a/src/toHaveDateBefore.ts +++ b/src/toHaveDateBefore.ts @@ -1,5 +1,19 @@ import { toBeBefore } from './toBeBefore'; import { toBeObject } from './toBeObject'; -export const toHaveDateBefore = (key, date, actual) => +export type ToHaveDateBefore = ( + key: string, + otherDate: Date, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveDateBefore: ToHaveDateBefore; + } + } +} + +export const toHaveDateBefore: ToHaveDateBefore = (key, date, actual) => toBeObject(actual) && toBeBefore(date, actual[key]); diff --git a/src/toHaveEmptyArray.ts b/src/toHaveEmptyArray.ts index 7b90bef..302711e 100644 --- a/src/toHaveEmptyArray.ts +++ b/src/toHaveEmptyArray.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeEmptyArray } from './toBeEmptyArray'; -export const toHaveEmptyArray = memberMatcherFor(toBeEmptyArray); + +export type ToHaveEmptyArray = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveEmptyArray: ToHaveEmptyArray; + } + } +} + +export const toHaveEmptyArray: ToHaveEmptyArray = memberMatcherFor( + toBeEmptyArray +); diff --git a/src/toHaveEmptyObject.ts b/src/toHaveEmptyObject.ts index 04376d9..fcec1d4 100644 --- a/src/toHaveEmptyObject.ts +++ b/src/toHaveEmptyObject.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeEmptyObject } from './toBeEmptyObject'; -export const toHaveEmptyObject = memberMatcherFor(toBeEmptyObject); + +export type ToHaveEmptyObject = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveEmptyObject: ToHaveEmptyObject; + } + } +} + +export const toHaveEmptyObject: ToHaveEmptyObject = memberMatcherFor( + toBeEmptyObject +); diff --git a/src/toHaveEmptyString.ts b/src/toHaveEmptyString.ts index 760b531..26ba38a 100644 --- a/src/toHaveEmptyString.ts +++ b/src/toHaveEmptyString.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeEmptyString } from './toBeEmptyString'; -export const toHaveEmptyString = memberMatcherFor(toBeEmptyString); + +export type ToHaveEmptyString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveEmptyString: ToHaveEmptyString; + } + } +} + +export const toHaveEmptyString: ToHaveEmptyString = memberMatcherFor( + toBeEmptyString +); diff --git a/src/toHaveEvenNumber.ts b/src/toHaveEvenNumber.ts index 40c4e17..5fbdc3e 100644 --- a/src/toHaveEvenNumber.ts +++ b/src/toHaveEvenNumber.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeEvenNumber } from './toBeEvenNumber'; -export const toHaveEvenNumber = memberMatcherFor(toBeEvenNumber); + +export type ToHaveEvenNumber = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveEvenNumber: ToHaveEvenNumber; + } + } +} + +export const toHaveEvenNumber: ToHaveEvenNumber = memberMatcherFor( + toBeEvenNumber +); diff --git a/src/toHaveFalse.ts b/src/toHaveFalse.ts index 81b8ffb..2f23ea8 100644 --- a/src/toHaveFalse.ts +++ b/src/toHaveFalse.ts @@ -1,3 +1,14 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeFalse } from './toBeFalse'; -export const toHaveFalse = memberMatcherFor(toBeFalse); + +export type ToHaveFalse = (key: string, expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveFalse: ToHaveFalse; + } + } +} + +export const toHaveFalse: ToHaveFalse = memberMatcherFor(toBeFalse); diff --git a/src/toHaveHtmlString.ts b/src/toHaveHtmlString.ts index 06c5297..2046488 100644 --- a/src/toHaveHtmlString.ts +++ b/src/toHaveHtmlString.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeHtmlString } from './toBeHtmlString'; -export const toHaveHtmlString = memberMatcherFor(toBeHtmlString); + +export type ToHaveHtmlString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveHtmlString: ToHaveHtmlString; + } + } +} + +export const toHaveHtmlString: ToHaveHtmlString = memberMatcherFor( + toBeHtmlString +); diff --git a/src/toHaveIso8601.ts b/src/toHaveIso8601.ts index 273d613..b47cd20 100644 --- a/src/toHaveIso8601.ts +++ b/src/toHaveIso8601.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeIso8601 } from './toBeIso8601'; -export const toHaveIso8601 = memberMatcherFor(toBeIso8601); + +export type ToHaveIso8601 = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveIso8601: ToHaveIso8601; + } + } +} + +export const toHaveIso8601: ToHaveIso8601 = memberMatcherFor(toBeIso8601); diff --git a/src/toHaveJsonString.ts b/src/toHaveJsonString.ts index 4a86a6b..e797f19 100644 --- a/src/toHaveJsonString.ts +++ b/src/toHaveJsonString.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeJsonString } from './toBeJsonString'; -export const toHaveJsonString = memberMatcherFor(toBeJsonString); + +export type ToHaveJsonString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveJsonString: ToHaveJsonString; + } + } +} + +export const toHaveJsonString: ToHaveJsonString = memberMatcherFor( + toBeJsonString +); diff --git a/src/toHaveMember.ts b/src/toHaveMember.ts index 2c5eea4..551416a 100644 --- a/src/toHaveMember.ts +++ b/src/toHaveMember.ts @@ -1,5 +1,18 @@ import { toBeObject } from './toBeObject'; import { toBeString } from './toBeString'; -export const toHaveMember = (key, actual) => +export type ToHaveMember = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveMember: ToHaveMember; + } + } +} + +export const toHaveMember: ToHaveMember = (key, actual) => toBeString(key) && toBeObject(actual) && key in actual; diff --git a/src/toHaveMethod.ts b/src/toHaveMethod.ts index eeb716c..d0d3693 100644 --- a/src/toHaveMethod.ts +++ b/src/toHaveMethod.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeFunction } from './toBeFunction'; -export const toHaveMethod = memberMatcherFor(toBeFunction); + +export type ToHaveMethod = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveMethod: ToHaveMethod; + } + } +} + +export const toHaveMethod: ToHaveMethod = memberMatcherFor(toBeFunction); diff --git a/src/toHaveNonEmptyArray.ts b/src/toHaveNonEmptyArray.ts index 65693d3..703f38b 100644 --- a/src/toHaveNonEmptyArray.ts +++ b/src/toHaveNonEmptyArray.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeNonEmptyArray } from './toBeNonEmptyArray'; -export const toHaveNonEmptyArray = memberMatcherFor(toBeNonEmptyArray); + +export type ToHaveNonEmptyArray = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveNonEmptyArray: ToHaveNonEmptyArray; + } + } +} + +export const toHaveNonEmptyArray: ToHaveNonEmptyArray = memberMatcherFor( + toBeNonEmptyArray +); diff --git a/src/toHaveNonEmptyObject.ts b/src/toHaveNonEmptyObject.ts index c46858b..fa50b82 100644 --- a/src/toHaveNonEmptyObject.ts +++ b/src/toHaveNonEmptyObject.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeNonEmptyObject } from './toBeNonEmptyObject'; -export const toHaveNonEmptyObject = memberMatcherFor(toBeNonEmptyObject); + +export type ToHaveNonEmptyObject = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveNonEmptyObject: ToHaveNonEmptyObject; + } + } +} + +export const toHaveNonEmptyObject: ToHaveNonEmptyObject = memberMatcherFor( + toBeNonEmptyObject +); diff --git a/src/toHaveNonEmptyString.ts b/src/toHaveNonEmptyString.ts index f2d5272..c9fe108 100644 --- a/src/toHaveNonEmptyString.ts +++ b/src/toHaveNonEmptyString.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeNonEmptyString } from './toBeNonEmptyString'; -export const toHaveNonEmptyString = memberMatcherFor(toBeNonEmptyString); + +export type ToHaveNonEmptyString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveNonEmptyString: ToHaveNonEmptyString; + } + } +} + +export const toHaveNonEmptyString: ToHaveNonEmptyString = memberMatcherFor( + toBeNonEmptyString +); diff --git a/src/toHaveNumber.ts b/src/toHaveNumber.ts index 659ede7..294ac40 100644 --- a/src/toHaveNumber.ts +++ b/src/toHaveNumber.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeNumber } from './toBeNumber'; -export const toHaveNumber = memberMatcherFor(toBeNumber); + +export type ToHaveNumber = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveNumber: ToHaveNumber; + } + } +} + +export const toHaveNumber: ToHaveNumber = memberMatcherFor(toBeNumber); diff --git a/src/toHaveNumberWithinRange.ts b/src/toHaveNumberWithinRange.ts index 9b06735..1defd40 100644 --- a/src/toHaveNumberWithinRange.ts +++ b/src/toHaveNumberWithinRange.ts @@ -1,5 +1,24 @@ import { toBeObject } from './toBeObject'; import { toBeWithinRange } from './toBeWithinRange'; -export const toHaveNumberWithinRange = (key, floor, ceiling, actual) => - toBeObject(actual) && toBeWithinRange(floor, ceiling, actual[key]); +export type ToHaveNumberWithinRange = ( + key: string, + floor: number, + ceiling: number, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveNumberWithinRange: ToHaveNumberWithinRange; + } + } +} + +export const toHaveNumberWithinRange: ToHaveNumberWithinRange = ( + key, + floor, + ceiling, + actual +) => toBeObject(actual) && toBeWithinRange(floor, ceiling, actual[key]); diff --git a/src/toHaveObject.ts b/src/toHaveObject.ts index 87927f9..e1d3695 100644 --- a/src/toHaveObject.ts +++ b/src/toHaveObject.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeObject } from './toBeObject'; -export const toHaveObject = memberMatcherFor(toBeObject); + +export type ToHaveObject = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveObject: ToHaveObject; + } + } +} + +export const toHaveObject: ToHaveObject = memberMatcherFor(toBeObject); diff --git a/src/toHaveOddNumber.ts b/src/toHaveOddNumber.ts index 4ff70ea..813a988 100644 --- a/src/toHaveOddNumber.ts +++ b/src/toHaveOddNumber.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeOddNumber } from './toBeOddNumber'; -export const toHaveOddNumber = memberMatcherFor(toBeOddNumber); + +export type ToHaveOddNumber = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveOddNumber: ToHaveOddNumber; + } + } +} + +export const toHaveOddNumber: ToHaveOddNumber = memberMatcherFor(toBeOddNumber); diff --git a/src/toHaveString.ts b/src/toHaveString.ts index 8be45ef..f75fc2f 100644 --- a/src/toHaveString.ts +++ b/src/toHaveString.ts @@ -1,3 +1,17 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeString } from './toBeString'; -export const toHaveString = memberMatcherFor(toBeString); + +export type ToHaveString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveString: ToHaveString; + } + } +} + +export const toHaveString: ToHaveString = memberMatcherFor(toBeString); diff --git a/src/toHaveStringLongerThan.ts b/src/toHaveStringLongerThan.ts index 4172fef..6dc84a6 100644 --- a/src/toHaveStringLongerThan.ts +++ b/src/toHaveStringLongerThan.ts @@ -1,5 +1,22 @@ import { toBeLongerThan } from './toBeLongerThan'; import { toBeObject } from './toBeObject'; -export const toHaveStringLongerThan = (key, other, actual) => - toBeObject(actual) && toBeLongerThan(other, actual[key]); +export type ToHaveStringLongerThan = ( + key: string, + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveStringLongerThan: ToHaveStringLongerThan; + } + } +} + +export const toHaveStringLongerThan: ToHaveStringLongerThan = ( + key, + other, + actual +) => toBeObject(actual) && toBeLongerThan(other, actual[key]); diff --git a/src/toHaveStringSameLengthAs.ts b/src/toHaveStringSameLengthAs.ts index a13c124..d3e188b 100644 --- a/src/toHaveStringSameLengthAs.ts +++ b/src/toHaveStringSameLengthAs.ts @@ -1,5 +1,22 @@ import { toBeObject } from './toBeObject'; import { toBeSameLengthAs } from './toBeSameLengthAs'; -export const toHaveStringSameLengthAs = (key, other, actual) => - toBeObject(actual) && toBeSameLengthAs(other, actual[key]); +export type ToHaveStringSameLengthAs = ( + key: string, + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveStringSameLengthAs: ToHaveStringSameLengthAs; + } + } +} + +export const toHaveStringSameLengthAs: ToHaveStringSameLengthAs = ( + key, + other, + actual +) => toBeObject(actual) && toBeSameLengthAs(other, actual[key]); diff --git a/src/toHaveStringShorterThan.ts b/src/toHaveStringShorterThan.ts index 4795495..4f17e85 100644 --- a/src/toHaveStringShorterThan.ts +++ b/src/toHaveStringShorterThan.ts @@ -1,5 +1,22 @@ import { toBeObject } from './toBeObject'; import { toBeShorterThan } from './toBeShorterThan'; -export const toHaveStringShorterThan = (key, other, actual) => - toBeObject(actual) && toBeShorterThan(other, actual[key]); +export type ToHaveStringShorterThan = ( + key: string, + other: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveStringShorterThan: ToHaveStringShorterThan; + } + } +} + +export const toHaveStringShorterThan: ToHaveStringShorterThan = ( + key, + other, + actual +) => toBeObject(actual) && toBeShorterThan(other, actual[key]); diff --git a/src/toHaveTrue.ts b/src/toHaveTrue.ts index 1fe19de..4d2c026 100644 --- a/src/toHaveTrue.ts +++ b/src/toHaveTrue.ts @@ -1,3 +1,14 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeTrue } from './toBeTrue'; -export const toHaveTrue = memberMatcherFor(toBeTrue); + +export type ToHaveTrue = (key: string, expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveTrue: ToHaveTrue; + } + } +} + +export const toHaveTrue: ToHaveTrue = memberMatcherFor(toBeTrue); diff --git a/src/toHaveUndefined.ts b/src/toHaveUndefined.ts index baa4337..746a23f 100644 --- a/src/toHaveUndefined.ts +++ b/src/toHaveUndefined.ts @@ -1,7 +1,20 @@ import { toBeObject } from './toBeObject'; import { toHaveMember } from './toHaveMember'; -export const toHaveUndefined = (key, actual) => +export type ToHaveUndefined = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveUndefined: ToHaveUndefined; + } + } +} + +export const toHaveUndefined: ToHaveUndefined = (key, actual) => toBeObject(actual) && toHaveMember(key, actual) && typeof actual[key] === 'undefined'; diff --git a/src/toHaveWhitespaceString.ts b/src/toHaveWhitespaceString.ts index e9ae2a4..45aa646 100644 --- a/src/toHaveWhitespaceString.ts +++ b/src/toHaveWhitespaceString.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeWhitespace } from './toBeWhitespace'; -export const toHaveWhitespaceString = memberMatcherFor(toBeWhitespace); + +export type ToHaveWhitespaceString = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveWhitespaceString: ToHaveWhitespaceString; + } + } +} + +export const toHaveWhitespaceString: ToHaveWhitespaceString = memberMatcherFor( + toBeWhitespace +); diff --git a/src/toHaveWholeNumber.ts b/src/toHaveWholeNumber.ts index d77e3da..1e5dc4e 100644 --- a/src/toHaveWholeNumber.ts +++ b/src/toHaveWholeNumber.ts @@ -1,3 +1,19 @@ import { memberMatcherFor } from './lib/memberMatcherFor'; import { toBeWholeNumber } from './toBeWholeNumber'; -export const toHaveWholeNumber = memberMatcherFor(toBeWholeNumber); + +export type ToHaveWholeNumber = ( + key: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toHaveWholeNumber: ToHaveWholeNumber; + } + } +} + +export const toHaveWholeNumber: ToHaveWholeNumber = memberMatcherFor( + toBeWholeNumber +); diff --git a/src/toStartWith.ts b/src/toStartWith.ts index 6d9c58b..07e7f88 100644 --- a/src/toStartWith.ts +++ b/src/toStartWith.ts @@ -1,6 +1,19 @@ import { toBeNonEmptyString } from './toBeNonEmptyString'; -export const toStartWith = (subString, actual) => +export type ToStartWith = ( + subString: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toStartWith: ToStartWith; + } + } +} + +export const toStartWith: ToStartWith = (subString, actual) => toBeNonEmptyString(actual) && toBeNonEmptyString(subString) && actual.slice(0, subString.length) === subString; diff --git a/src/toThrowAnyError.ts b/src/toThrowAnyError.ts index 1e8807a..14d8042 100644 --- a/src/toThrowAnyError.ts +++ b/src/toThrowAnyError.ts @@ -1,4 +1,14 @@ -export const toThrowAnyError = (actual) => { +export type ToThrowAnyError = (expectationFailOutput?: any) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toThrowAnyError: ToThrowAnyError; + } + } +} + +export const toThrowAnyError: ToThrowAnyError = (actual) => { try { actual(); return false; diff --git a/src/toThrowErrorOfType.ts b/src/toThrowErrorOfType.ts index dad82d7..57c34bf 100644 --- a/src/toThrowErrorOfType.ts +++ b/src/toThrowErrorOfType.ts @@ -1,4 +1,17 @@ -export const toThrowErrorOfType = (type, actual) => { +export type ToThrowErrorOfType = ( + type: string, + expectationFailOutput?: any +) => boolean; + +declare global { + namespace jasmine { + interface Matchers { + toThrowErrorOfType: ToThrowErrorOfType; + } + } +} + +export const toThrowErrorOfType: ToThrowErrorOfType = (type, actual) => { try { actual(); return false; diff --git a/tslint.json b/tslint.json index 4ea4eaf..2f35e76 100644 --- a/tslint.json +++ b/tslint.json @@ -1,6 +1,7 @@ { "extends": "tslint:recommended", "rules": { + "interface-name": [false], "no-console": [false], "no-var-requires": [false], "quotemark": [true, "single"],