fixes the problem with perceived not mocked xhr call in tests

This commit is contained in:
Wojciech Zawistowski 2013-11-12 20:40:46 +01:00
parent e9f9d22482
commit a2dd197256
1 changed files with 14 additions and 6 deletions

View File

@ -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");