Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
¿Cómo me burlo correctamente de una función pública de clase en broma?

Tengo la siguiente prueba de broma

 it("should return props on stage.e.com", async () => { ((savedStoriesService as unknown) as jest.Mock).mockReturnValue({ getStoriesFromList: jest.fn().mockResolvedValue([]), }); const jwt = mockJwt({ custom_attributes: { CustomerType: "Subscribed" }, }); const result = await getServerSideProps(({ req: { headers: { host: <redacted>, authorization: `Bearer ${jwt}`, }, }, } as unknown) as GetServerSidePropsContext); expect(result).toMatchObject({ props: { stories: [], isSubscriber: true, isLapsed: false, }, }); });

Obtuve el siguiente error

 TypeError: _stories.savedStoriesService.getStoriesFromList is not a function 149 | const parsedJwt = parseJwtFromRequest(ctx.req); 150 | > 151 | const stories = await savedStoriesService.getStoriesFromList( | ^ 152 | ctx.req.headers?.authorization, 153 | { cursor: "" }, 154 | );

Tengo una clase llamada StoriesService así

 export class StoriesService { ... public getStoriesFromList = async ( authToken: string, options: GetStoriesOptions, ): Promise<Story[]> => { ... } ... } export const savedStoriesService = new StoriesService();

¿Cómo haría para burlarme de esta clase?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

puedes simularlo con:

 jest.spyOn(savedStoriesService, 'getStoriesFromList').mockResolvedValueOnce(<the value that you want to return>)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!