DEV Community

Visakh Vijayan
Visakh Vijayan

Posted on

SinonJs - to make the stubvalue random

    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.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs