Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Mock a function's return value using a Sinon stub

    Josh MockJosh Mock

    When mocking a JavaScript function during a unit test, it can be helpful to force a mock function to return a value of your choosing. This allows you to verify that functions you're testing will behave correctly for every possible use case.

    Much like sinon.spy(), sinon.stub() creates a mock function that prevents a real function from running. But, unlike spy, it also allows you to declare what value you'd like the mock function to return.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson