I'm using jest for writing test cases. One of my function uses uuid and due to which it is not a pure function. The code is something like this:
const myFunc = () => {
const a = uuid();
return a;
}
I'm writing my test case as :
test('should return a unique id value', () => {
const a = uuid();
expect(myFunc()).toEqual(a);
});
Obviously it won't work as it will generate a unique Id every time. How can I write test case for such function.
[EDIT]
I don't want test the uuid
function as it will always generate a new id and it is a library function which is already being tested. I want to test another function which uses uuid
, generates new object and returns that. This function is used by some other function and so on which makes me not able to test any of that because the initial object has an id which is different that the id which I'm using while testing.