Skip to content

Instantly share code, notes, and snippets.

@joachimhs
Last active December 15, 2015 15:19
Show Gist options
  • Save joachimhs/5280678 to your computer and use it in GitHub Desktop.
Save joachimhs/5280678 to your computer and use it in GitHub Desktop.
Sinon FakeServer test
var alertAdminController;
module("EurekaJ.AdministrationAlertsController", {
setup: function() {
this.server = sinon.fakeServer.create();
Ember.run(function() {
alertAdminController = EurekaJ.__container__.lookup("controller:administrationAlerts");
});
},
teardown: function() {
this.server.restore();
delete this.server;
}
});
asyncTest("Create a new Alert and verify that it is shown", 3, function() {
EurekaJ.reset();
ok(alertAdminController, "Exepcting a non-null AdministrationAlertsController");
alertAdminController.set('newAlertName', 'New Alert');
alertAdminController.createNewAlert();
var newAlert = alertAdminController.get('newAlert');
newAlert.one('didCreate', function() {
console.log('later: ' + alertAdminController.get('content.length'));
strictEqual(1, alertAdminController.get('content.length'), "Expecting one alert. Got: " + alertAdminController.get('content.length'));
start();
});
console.log('committing');
EurekaJ.store.commit();
//Set up the response
this.server.respondWith("POST", "/alert_models",
[200, { "Content-Type": "text/json" },
'{"alert_model":{"alert_source":"null","id":"New Alert","alert_delay":0,"alert_plugin_ids":[],"alert_notifications":"","alert_activated":false,"alert_type":"greater_than"}}']);
console.log('responding');
this.server.respond();
strictEqual(1, this.server.requests.length, "Expecting a total of 1 XHR");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment