How to mock Auth0 library in react native using Jest

Viewed 550

I am trying to mock this code for auth0 library

import Auth0 from 'react-native-auth0';
import React, { Component } from 'react';

var credential = {
      clientId: “dummy”,
      domain: “www.dummy.com”
    };

auth0Credentials = credentials;

auth0 = new Auth0(auth0Credentials);

auth0.auth.userInfo({ token: “DUMMY” }).then(profile => {
})

I have wrote unit test case.

  beforeAll(() => {
    global.CLIENT_ID = "dummy";
    global.DOMAIN = "www.dummy.com";
    let promise = Promise.resolve(123);
    let auth0Credentials = {
      clientId: global.CLIENT_ID,
      domain: global.DOMAIN
    };
    var auth0 = new Auth0(auth0Credentials);
    auth0.auth = {
      userInfo: jest.fn(() => promise),
    };
  });

I tried to mock like this it is not working. Can anyone help me on this to mock this auth0.

0 Answers
Related