summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-01-10 17:22:01 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-01-10 17:22:01 +0100
commitf8cfde0eaa38e1bccfa5c47e6c6a8738af19cc9b (patch)
treeb2f54b4f516a5836d7216d0a963d5b484ebf597c
parenta34256eaf1e48659e728a146b876236335734c37 (diff)
downloadbackoffice-f8cfde0eaa38e1bccfa5c47e6c6a8738af19cc9b.tar.gz
backoffice-f8cfde0eaa38e1bccfa5c47e6c6a8738af19cc9b.tar.bz2
backoffice-f8cfde0eaa38e1bccfa5c47e6c6a8738af19cc9b.zip
grouping mocks preparation
-rw-r--r--js/test/main.js43
1 files changed, 23 insertions, 20 deletions
diff --git a/js/test/main.js b/js/test/main.js
index b714a82..2d6d618 100644
--- a/js/test/main.js
+++ b/js/test/main.js
@@ -32,33 +32,36 @@ const swig = require("swig");
const jsdom = require("jsdom");
ava.test.beforeEach(t => {
- // Global XHR mock
- t.context.xhr = sinon.useFakeXMLHttpRequest();
- t.context.requests = [];
- t.context.xhr.onCreate = function(xhr){
- t.context.requests.push(xhr);
+
+ function xhr_mock() {
+ t.context.xhr = sinon.useFakeXMLHttpRequest();
+ t.context.requests = [];
+ t.context.xhr.onCreate = function(xhr){
+ t.context.requests.push(xhr);};
+ global.XMLHttpRequest = t.context.xhr;};
+
+ function document_mock() {
+ var template = swig.compileFile(
+ __dirname + "/" + "../../" +
+ "talerbackoffice/backoffice/" +
+ "templates/backoffice.html");
+ var html = template({instances: ["mock-instance"]});
+ var dom = new jsdom.JSDOM(html);
+ dom.window.document.addEventListener = function(){};
+ global.document = dom.window.document;};
+
+ function minor_mocks() {
+ global.alert = console.log;
};
- global.XMLHttpRequest = t.context.xhr;
- // Global 'document' mock
- var template = swig.compileFile(
- __dirname + "/" + "../../" +
- "talerbackoffice/backoffice/" +
- "templates/backoffice.html");
- var html = template({instances: ["mock-instance"]});
- // fixme: 'document' must be a *parsed* DOM!
- var dom = new jsdom.JSDOM(html);
- dom.window.document.addEventListener = function(){};
- global.document = dom.window.document;
- global.alert = console.log;
+ xhr_mock();
+ document_mock();
+ minor_mocks();
- // Load back-office code (slows down..)
t.context.bo = require("../backoffice");
});
-// 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;