[Fixes #39] Uninstall should clear requests / stubs
This commit is contained in:
parent
546549cb5f
commit
14ca64b77a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.idea/
|
||||
.rvmrc
|
||||
*.swp
|
||||
node_modules
|
||||
|
@ -50,6 +50,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
this.uninstall = function() {
|
||||
global.XMLHttpRequest = realAjaxFunction;
|
||||
|
||||
this.stubs.reset();
|
||||
this.requests.reset();
|
||||
};
|
||||
|
||||
this.stubRequest = function(url) {
|
||||
|
@ -25,6 +25,25 @@ describe("mockAjax", function() {
|
||||
expect(fakeXmlHttpRequest).toHaveBeenCalledWith('foo');
|
||||
});
|
||||
|
||||
it("clears requests and stubs upon uninstall", function() {
|
||||
var fakeXmlHttpRequest = jasmine.createSpy('fakeXmlHttpRequest'),
|
||||
fakeGlobal = { XMLHttpRequest: fakeXmlHttpRequest },
|
||||
mockAjax = new MockAjax(fakeGlobal);
|
||||
|
||||
mockAjax.install();
|
||||
|
||||
mockAjax.requests.track({url: '/testurl'});
|
||||
mockAjax.stubs.addStub({url: '/bobcat'});
|
||||
|
||||
expect(mockAjax.requests.count()).toEqual(1);
|
||||
expect(mockAjax.stubs.findStub('/bobcat')).toBeDefined();
|
||||
|
||||
mockAjax.uninstall();
|
||||
|
||||
expect(mockAjax.requests.count()).toEqual(0);
|
||||
expect(mockAjax.stubs.findStub('/bobcat')).not.toBeDefined();
|
||||
});
|
||||
|
||||
it("allows the httpRequest to be retrieved", function() {
|
||||
var fakeXmlHttpRequest = jasmine.createSpy('fakeXmlHttpRequest'),
|
||||
fakeGlobal = { XMLHttpRequest: fakeXmlHttpRequest },
|
||||
|
Loading…
Reference in New Issue
Block a user