From f5bca274a91bc9eadb9e6c521fde723649eed405 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 10 Jan 2018 13:53:53 +0100 Subject: testing the reaction to a order id not found --- js/test/main.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/js/test/main.js b/js/test/main.js index 2ded74e..e898210 100644 --- a/js/test/main.js +++ b/js/test/main.js @@ -13,6 +13,7 @@ ava.test.beforeEach(t => { // Global 'document' mock global.document = {}; global.document.addEventListener = function(){}; + global.alert = console.log; // Load back-office code t.context.bo = require("../backoffice"); @@ -20,14 +21,22 @@ ava.test.beforeEach(t => { // Remove mocks from global scope ava.test.afterEach(t => { + // Is this done by the garbage collector anyway? delete global.XMLHttpRequest; delete global.document; + delete global.alert; + delete t.context.xhr; + delete t.context.requests; }); -ava.test("orders tracking", (t) => { +ava.test("Order id not found", (t) => { + /** + * FIXME: improve the reaction to a order id not found. + * Alerting a message is not acceptable. + */ + var alert = sinon.spy(global, "alert"); t.context.bo.track_order(22); - - // Clean up - t.context.xhr.restore(); + t.context.requests[0].respond(404); + sinon.assert.calledWith(alert, "Order ID unknown"); t.pass(); }); -- cgit v1.2.3