Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
How to test a library React Native using Jest

I'm tried to test a React Native library using Jest, but it show error, can someone help me to solve my problem.

Here my Fucntion code :

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

I'm using react-native-push-notification library to this function

and here's my testing code :

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 shown : TypeError: _reactNativePushNotification.default.createChannel is not a function

Can someone help me solve this, thankyou so much!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try

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

And then use create in your test. I'm not sure what you're testing in the test above, but this is a good way to mock functions you don't want to run on your test.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda