Permalink
Browse files

[Fixes #39] Uninstall should clear requests / stubs

  • Loading branch information...
1 parent 546549c commit 14ca64b77a3e726f52070c387c78807d750ea4dc pivotal committed Nov 1, 2013
Showing with 23 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 lib/mock-ajax.js
  3. +19 −0 spec/javascripts/mock-ajax-spec.js
View
1 .gitignore
@@ -1,3 +1,4 @@
.idea/
.rvmrc
+*.swp
node_modules
View
3 lib/mock-ajax.js
@@ -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) {
View
19 spec/javascripts/mock-ajax-spec.js
@@ -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 },

0 comments on commit 14ca64b

Please sign in to comment.