From a2dd1972563ad41b3834dcf3c4fba85308b35798 Mon Sep 17 00:00:00 2001 From: Wojciech Zawistowski Date: Tue, 12 Nov 2013 20:40:46 +0100 Subject: [PATCH] fixes the problem with perceived not mocked xhr call in tests --- .../controllers/header_controller_test.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/javascripts/controllers/header_controller_test.js b/test/javascripts/controllers/header_controller_test.js index 9753012eadc..30c51b19553 100644 --- a/test/javascripts/controllers/header_controller_test.js +++ b/test/javascripts/controllers/header_controller_test.js @@ -1,22 +1,28 @@ -var server; - module("Discourse.HeaderController", { setup: function() { - server = sinon.fakeServer.create(); + sinon.stub(Discourse, "ajax"); }, teardown: function() { - server.restore(); + Discourse.ajax.restore(); } }); test("showNotifications action", function() { + var resolveRequestWith; + var request = new Ember.RSVP.Promise(function(resolve) { + resolveRequestWith = resolve; + }); + + var controller = Discourse.HeaderController.create(); var viewSpy = { showDropdownBySelector: sinon.spy() }; Discourse.User.current().set("unread_notifications", 1); - server.respondWith("/notifications", [200, { "Content-Type": "application/json" }, '["notification"]']); + Ember.run(function() { + Discourse.ajax.withArgs("/notifications").returns(request); + }); Ember.run(function() { @@ -28,7 +34,9 @@ test("showNotifications action", function() { ok(viewSpy.showDropdownBySelector.notCalled, "dropdown with notifications is not shown before data has finished loading"); - server.respond(); + Ember.run(function() { + resolveRequestWith(["notification"]); + }); deepEqual(controller.get("notifications"), ["notification"], "notifications are set correctly after data has finished loading"); equal(Discourse.User.current().get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");