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

139
Views
Cómo probar una biblioteca React Native usando Jest

Intenté probar una biblioteca React Native usando Jest, pero muestra un error, ¿alguien puede ayudarme a resolver mi problema?

Aquí mi código de función:

 export const createChannel = (): void => { PushNotification.createChannel({ channelId: 'test-channel', channelName: 'Test Channel', vibrate: true, }); };

Estoy usando la biblioteca react-native-push-notification para esta función

y aquí está mi código de prueba:

 import PushNotification from 'react-native-push-notification'; import {createChannel} from '../src/functions/PomodoroFunction'; jest.mock('react-native-push-notification', () => 'PushNotification.createChannel'); describe('Create Channel unit test', () => { it('Should be called',()=>{ const mockFN = createChannel() expect(mockFN).toHaveBeenCalled(); }) });

error mostrado: TypeError: _reactNativePushNotification.default.createChannel no es una función

Alguien me puede ayudar a resolver esto, muchas gracias!

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

0

Probar

 import * as PushNotification from 'react-native-push-notification'; ... const create = jest.fn(); const rnpn = jest.spyOn(PushNotification, 'default').mockImplementation(() => { return { createChannel: create } as any; }); ...

Y luego usa create en tu prueba. No estoy seguro de lo que está probando en la prueba anterior, pero esta es una buena manera de simular funciones que no desea ejecutar en su prueba.

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!