Skip to content

Commit

Permalink
fix(jest): fix type collisions between jasmine/jest
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Jan 6, 2019
1 parent ed626cd commit e7b6a44
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 55 deletions.
51 changes: 51 additions & 0 deletions projects/spectator/jest/src/matchers-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
declare namespace jest {
interface Matchers<R> {
toExist(): boolean;

toHaveLength(expected: number): boolean;

toHaveId(id: string | number): boolean;

toHaveClass(className: string): boolean;
/**
* @deprecated
*/
toHaveAttr({ attr, val }: { attr: string; val: string }): boolean;
toHaveAttribute(attr: string, val: string): boolean;
/**
* @deprecated
*/
toHaveProp({ prop, val }: { prop: string; val: string }): boolean;
toHaveProperty(prop: string, val: string | boolean): boolean;

toHaveProperty(prop: string, val: string | boolean): boolean;

toHaveText(text: string | Function): boolean;

toHaveValue(value: string): boolean;

toHaveStyle(style: { [styleKey: string]: any }): boolean;

toHaveData({ data, val }: { data: string; val: string }): boolean;

toBeChecked(): boolean;

toBeDisabled(): boolean;

toBeEmpty(): boolean;

toBeHidden(): boolean;

toBeSelected(): boolean;

toBeVisible(): boolean;

toBeFocused(): boolean;

toBeMatchedBy(selector: string | Element): boolean;

toHaveDescendant(selector: string | Element): boolean;

toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): boolean;
}
}
1 change: 1 addition & 0 deletions projects/spectator/jest/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference path="./matchers-types.d.ts" />
export * from './config';
export * from './host';
export * from './http';
Expand Down
52 changes: 0 additions & 52 deletions projects/spectator/src/lib/matchers-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,55 +49,3 @@ declare namespace jasmine {
toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): boolean;
}
}

declare namespace jest {
interface Matchers<R> {
toExist(): boolean;

toHaveLength(expected: number): boolean;

toHaveId(id: string | number): boolean;

toHaveClass(className: string): boolean;
/**
* @deprecated
*/
toHaveAttr({ attr, val }: { attr: string; val: string }): boolean;
toHaveAttribute(attr: string, val: string): boolean;
/**
* @deprecated
*/
toHaveProp({ prop, val }: { prop: string; val: string }): boolean;
toHaveProperty(prop: string, val: string | boolean): boolean;

toHaveProperty(prop: string, val: string | boolean): boolean;

toHaveText(text: string | Function): boolean;

toHaveValue(value: string): boolean;

toHaveStyle(style: { [styleKey: string]: any }): boolean;

toHaveData({ data, val }: { data: string; val: string }): boolean;

toBeChecked(): boolean;

toBeDisabled(): boolean;

toBeEmpty(): boolean;

toBeHidden(): boolean;

toBeSelected(): boolean;

toBeVisible(): boolean;

toBeFocused(): boolean;

toBeMatchedBy(selector: string | Element): boolean;

toHaveDescendant(selector: string | Element): boolean;

toHaveDescendantWithText({ selector, text }: { selector: string; text: string }): boolean;
}
}
5 changes: 2 additions & 3 deletions projects/spectator/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": [
"@types/jest"
],
"typeRoots" : ["./typings"],
"types": ["jasmine", "jest"],
"lib": [
"dom",
"es2018"
Expand Down
23 changes: 23 additions & 0 deletions projects/spectator/typings/jest/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This file was creating to avoid conflicts during building between jasmine and jest.
*
* Projects using @netbasal/spectator should just use either @types/jasmine or @types/jest.
*/

declare namespace jest {
interface Mock<T = {}> extends Function, MockInstance<T> {
new (...args: any[]): T;

(...args: any[]): any;
}

function fn<T>(implementation?: (...args: any[]) => any): Mock<T>;

interface MockInstance<T> {
mockImplementation(fn?: (...args: any[]) => any): Mock<T>;

mockReturnValue(value: any): Mock<T>;

mockReset(): void;
}
}

0 comments on commit e7b6a44

Please sign in to comment.