Skip to content

Commit

Permalink
Merge pull request #7 from wheresrhys/reMock
Browse files Browse the repository at this point in the history
added reMock method to allow overriding after mock is setup
  • Loading branch information
wheresrhys committed May 5, 2015
2 parents 77a283f + 264041d commit 9fb27c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/fetch-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ FetchMock.prototype.restore = function () {
theGlobal.fetch.restore();
};

FetchMock.prototype.reMock = function (config) {
this.restore();
this.mock(config);
};

FetchMock.prototype.reset = function () {
this._calls = {};
theGlobal.fetch.reset();
Expand Down
24 changes: 23 additions & 1 deletion test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,29 @@ module.exports = function (fetchMock, theGlobal) {
});
});

it('apply overrides when mock already mocking', function (done) {
fetchMock.registerRoute({
name: 'route1',
matcher: 'http://it.at.here',
response: 'ok'
});
fetchMock.mock();
fetchMock.reMock({
responses: {
route1: 'changed my mind'
}
});
fetch('http://it.at.here')
.then(function (res) {
res.text().then(function (text) {
expect(text).to.equal('changed my mind');
done();
});

});
});

});

});
}
}

0 comments on commit 9fb27c9

Please sign in to comment.