SinonJs - to make the stubvalue random

Visakh Vijayan - Apr 21 '23 - - Dev Community
    sinonSandbox
    .stub(LobService, 'createPostcard')
    .callsFake(() => {
      const postcard = new Postcard({ id: `psc_${faker.random.alphaNumeric(16)}` });
      return Promise.resolve(postcard);
    });
Enter fullscreen mode Exit fullscreen mode

Everytime the function createPostcard is called, which is mocked btw, the function is called a new postcard is made.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .