// Define another test block describe('GET /movies/search', () => { // Test setup. Runs before each test beforeEach(() => { // Stub the service method. We need to make the stub respect the NodeJS' callback convention // So we tell sinon to use the 2nd argument passed (index 1) as a callback // and send it the rest of the arguments (null and mockedMoviesList) sinon.stub(OmdbService, 'search').callsArgWith(1, null, mockedMoviesList); }); afterEach(() => { // Restore the service method, for future usage OmdbService.search.restore(); }); // Define a test it('should respond with a list of movies', done => { chai.request(app) .get('/movies/search?query=anything') .end((err, res) => { expect(res.body).to.be.an('array').and.have.lengthOf(2); expect(res.body).to.deep.equal(mockedMoviesList); done(); }); }); });