Skip to content

Commit

Permalink
fix: export MockProps type
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Sep 23, 2020
1 parent c0d01a7 commit b39e66f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { IsMockProp, SpyOnProp } from "jest-mock-props";
import { IsMockProp, SpyOnProp } from "./types";

declare global {
namespace jest {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsMockProp, Obj, Spyable, SpyOnProp, ValueOf } from "jest-mock-props";
import { IsMockProp, Obj, Spyable, SpyOnProp, ValueOf } from "./types";

export const messages = {
error: {
Expand Down Expand Up @@ -36,7 +36,7 @@ const getAllSpies = () => {
return spies;
};

class MockProp<T> implements MockProp<T> {
export class MockProp<T> implements MockProp<T> {
private initialPropDescriptor: PropertyDescriptor;
private initialPropValue: T;
private object: Obj<T>;
Expand Down
36 changes: 17 additions & 19 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
declare module "jest-mock-props" {
export type Obj<T> = Record<string, T>;
export type Obj<T> = Record<string, T>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Spyable = Obj<any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Spyable = Obj<any>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ValueOf<O> = O extends Record<infer _, infer T> ? T : any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ValueOf<O> = O extends Record<infer _, infer T> ? T : any;

export interface MockProp<T> {
mockClear(): void;
mockReset(): void;
mockRestore(): void;
mockValue(v: T): MockProp<T>;
mockValueOnce(v: T): MockProp<T>;
}

export type IsMockProp = <T>(object: Obj<T>, propName: string) => boolean;
export type SpyOnProp = (
object: Spyable,
propName: string,
) => MockProp<ValueOf<typeof object>>;
export interface MockProp<T> {
mockClear(): void;
mockReset(): void;
mockRestore(): void;
mockValue(v: T): MockProp<T>;
mockValueOnce(v: T): MockProp<T>;
}

export type IsMockProp = <T>(object: Obj<T>, propName: string) => boolean;
export type SpyOnProp = (
object: Spyable,
propName: string,
) => MockProp<ValueOf<typeof object>>;
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Obj } from "jest-mock-props";
import { Obj } from "src/types";
import * as mockProps from "src/index";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit b39e66f

Please sign in to comment.