mercredi 24 juin 2020

Jest Mock Variables Declared Inside a Function

Problem

I'm trying to test a function I created, but I need to mock two consts declared inside the function.

I've found posts on how to mock a function called in another function, but I would like to avoid having to declare both consts inside of a separate function and calling the separate function inside my function.

Does anyone have any advice on how I can mock the consts windowWidth and WindowHeight inside windowDimensions below?

Code

import { Dimensions } from 'react-native';

interface WindowDimensions {
    minWindowDimension: number;
    maxWindowDimension: number;
}

export function windowDimensions(): WindowDimensions {
         const windowWidth = Math.round(Dimensions.get("window").width);
         const windowHeight = Math.round(
           Dimensions.get("window").height
         );
         const minWindowDimension = Math.min(windowWidth, windowHeight);
         const maxWindowDimension = Math.max(windowWidth, windowHeight);
         return { minWindowDimension, maxWindowDimension };
       }

Aucun commentaire:

Enregistrer un commentaire