vendredi 13 mars 2020

How to test nested return functions with jest?

I am trying to figure out how I would go about testing this code:

export const guid = () => {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
    let r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
};

I have no problem testing the returned value of the function, but I can't figure out how test the interior of the guid function. I found this question that was asked before: Jest: How to test function that returns a function

but still can't figure how to resolve the 'expect' properly.

Aucun commentaire:

Enregistrer un commentaire