O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mocking external dependencies

Okay, you can write some integration tests. Is it enough? Not yet. Let's think. We really need to connect to external services? What if they're down? Of course, our test will fail but not for some application error. To avoid this, we will use Mocks.

Mocking is the technique used to simulate some object/service/component and return a predefined response when its called. We'll not connect with real services, so we'll be using sinon.mock to create a mock model for our Teams schema, and we'll test the expected result:

// Test will pass if we get all teams
        it("should return football teams",(done) => {
            var TeamMock = sinon.mock(Team);
            var expectedResult = {status: true, team: []};
            TeamMock.expects('find').yields(

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required