marchaos / jest-mock-extended

Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
MIT License
828 stars 57 forks source link

Mocking objects with non-function values #48

Open PEZO19 opened 3 years ago

PEZO19 commented 3 years ago

Hi! Is it possible to mock simple objects somehow based on interfaces where the value is not a function?

Instead

interface PartyProvider {
   getPartyType: () => string;
   getSongs: (type: string) => string[];
}

I'd like to mock

interface PartyProvider {
   getPartyType: string;
   getSongs: string[];
}

(and also being able to do that in nested form).

anrolmar commented 3 years ago

Hi, @PEZO19. I would want to do the same. Any progress?

Nightbr commented 3 years ago

This is working for me, but can't make it work with Date props.

interface MyObj {
   expiredAt: Date;
   test: string;
}

const obj = mock<MyObj>();

obj.expiredtAt = mock<Date>(new Date()); // not working
obj.test = "mockString";