Skip to content

Commit

Permalink
refactor(types): move types to each matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Dec 23, 2018
1 parent 4817738 commit 62ebe0a
Show file tree
Hide file tree
Showing 82 changed files with 1,126 additions and 172 deletions.
87 changes: 0 additions & 87 deletions jasmine-matchers.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
17 changes: 16 additions & 1 deletion src/toBeAfter.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeAfter: ToBeAfter;
}
}
}

export const toBeAfter: ToBeAfter = (otherDate, actual) =>
toBeBefore(actual, otherDate);
13 changes: 12 additions & 1 deletion src/toBeArray.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArray: ToBeArray;
}
}
}

export const toBeArray: ToBeArray = is.Array;
13 changes: 12 additions & 1 deletion src/toBeArrayOfBooleans.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArrayOfBooleans: ToBeArrayOfBooleans;
}
}
}

export const toBeArrayOfBooleans: ToBeArrayOfBooleans = (actual) =>
toBeArray(actual) && every(actual, toBeBoolean);
13 changes: 12 additions & 1 deletion src/toBeArrayOfNumbers.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArrayOfNumbers: ToBeArrayOfNumbers;
}
}
}

export const toBeArrayOfNumbers: ToBeArrayOfNumbers = (actual) =>
toBeArray(actual) && every(actual, toBeNumber);
13 changes: 12 additions & 1 deletion src/toBeArrayOfObjects.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArrayOfObjects: ToBeArrayOfObjects;
}
}
}

export const toBeArrayOfObjects: ToBeArrayOfObjects = (actual) =>
toBeArray(actual) && every(actual, toBeObject);
16 changes: 15 additions & 1 deletion src/toBeArrayOfSize.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArrayOfSize: ToBeArrayOfSize;
}
}
}

export const toBeArrayOfSize: ToBeArrayOfSize = (size, actual) =>
toBeArray(actual) && actual.length === size;
13 changes: 12 additions & 1 deletion src/toBeArrayOfStrings.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeArrayOfStrings: ToBeArrayOfStrings;
}
}
}

export const toBeArrayOfStrings: ToBeArrayOfStrings = (actual) =>
toBeArray(actual) && every(actual, toBeString);
15 changes: 14 additions & 1 deletion src/toBeBefore.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeBefore: ToBeBefore;
}
}
}

export const toBeBefore: ToBeBefore = (otherDate, actual) =>
toBeDate(actual) &&
toBeDate(otherDate) &&
actual.getTime() < otherDate.getTime();
13 changes: 12 additions & 1 deletion src/toBeBoolean.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeBoolean: ToBeBoolean;
}
}
}

export const toBeBoolean: ToBeBoolean = is.Boolean;
10 changes: 10 additions & 0 deletions src/toBeCalculable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export type ToBeCalculable = (expectationFailOutput?: any) => boolean;

declare global {
namespace jasmine {
interface Matchers<T> {
toBeCalculable: ToBeCalculable;
}
}
}

export function toBeCalculable(actual) {
return !isNaN(actual * 2);
}
13 changes: 12 additions & 1 deletion src/toBeDate.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeDate: ToBeDate;
}
}
}

export const toBeDate: ToBeDate = is.Date;
14 changes: 13 additions & 1 deletion src/toBeEmptyArray.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeEmptyArray: ToBeEmptyArray;
}
}
}

export const toBeEmptyArray: ToBeEmptyArray = (actual) =>
toBeArrayOfSize(0, actual);
13 changes: 12 additions & 1 deletion src/toBeEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeEmptyObject: ToBeEmptyObject;
}
}
}

export const toBeEmptyObject: ToBeEmptyObject = (actual) =>
is.Object(actual) && keys(actual).length === 0;
12 changes: 11 additions & 1 deletion src/toBeEmptyString.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export const toBeEmptyString = (actual) => actual === '';
export type ToBeEmptyString = (expectationFailOutput?: any) => boolean;

declare global {
namespace jasmine {
interface Matchers<T> {
toBeEmptyString: ToBeEmptyString;
}
}
}

export const toBeEmptyString: ToBeEmptyString = (actual) => actual === '';
13 changes: 12 additions & 1 deletion src/toBeEvenNumber.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { toBeNumber } from './toBeNumber';
export const toBeEvenNumber = (actual) =>

export type ToBeEvenNumber = (expectationFailOutput?: any) => boolean;

declare global {
namespace jasmine {
interface Matchers<T> {
toBeEvenNumber: ToBeEvenNumber;
}
}
}

export const toBeEvenNumber: ToBeEvenNumber = (actual) =>
toBeNumber(actual) && actual % 2 === 0;
14 changes: 13 additions & 1 deletion src/toBeFalse.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeFalse: ToBeFalse;
}
}
}

export const toBeFalse: ToBeFalse = (actual) =>
actual === false || is.False(actual);
13 changes: 12 additions & 1 deletion src/toBeFunction.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeFunction: ToBeFunction;
}
}
}

export const toBeFunction: ToBeFunction = is.Function;
19 changes: 17 additions & 2 deletions src/toBeGreaterThanOrEqualTo.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
toBeGreaterThanOrEqualTo: ToBeGreaterThanOrEqualTo;
}
}
}

export const toBeGreaterThanOrEqualTo: ToBeGreaterThanOrEqualTo = (
otherNumber,
actual
) => toBeNumber(actual) && actual >= otherNumber;
Loading

0 comments on commit 62ebe0a

Please sign in to comment.