Skip to content

Commit a2dd197

Browse files
committed
fixes the problem with perceived not mocked xhr call in tests
1 parent e9f9d22 commit a2dd197

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

test/javascripts/controllers/header_controller_test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
var server;
2-
31
module("Discourse.HeaderController", {
42
setup: function() {
5-
server = sinon.fakeServer.create();
3+
sinon.stub(Discourse, "ajax");
64
},
75

86
teardown: function() {
9-
server.restore();
7+
Discourse.ajax.restore();
108
}
119
});
1210

1311
test("showNotifications action", function() {
12+
var resolveRequestWith;
13+
var request = new Ember.RSVP.Promise(function(resolve) {
14+
resolveRequestWith = resolve;
15+
});
16+
17+
1418
var controller = Discourse.HeaderController.create();
1519
var viewSpy = {
1620
showDropdownBySelector: sinon.spy()
1721
};
1822
Discourse.User.current().set("unread_notifications", 1);
19-
server.respondWith("/notifications", [200, { "Content-Type": "application/json" }, '["notification"]']);
23+
Ember.run(function() {
24+
Discourse.ajax.withArgs("/notifications").returns(request);
25+
});
2026

2127

2228
Ember.run(function() {
@@ -28,7 +34,9 @@ test("showNotifications action", function() {
2834
ok(viewSpy.showDropdownBySelector.notCalled, "dropdown with notifications is not shown before data has finished loading");
2935

3036

31-
server.respond();
37+
Ember.run(function() {
38+
resolveRequestWith(["notification"]);
39+
});
3240

3341
deepEqual(controller.get("notifications"), ["notification"], "notifications are set correctly after data has finished loading");
3442
equal(Discourse.User.current().get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");

0 commit comments

Comments
 (0)