gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-backoffice] branch master updated: Define "set up" a


From: gnunet
Subject: [GNUnet-SVN] [taler-backoffice] branch master updated: Define "set up" and "tear down" methods for tests
Date: Wed, 10 Jan 2018 13:15:53 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository backoffice.

The following commit(s) were added to refs/heads/master by this push:
     new a260f27  Define "set up" and "tear down" methods for tests
a260f27 is described below

commit a260f2755ba9532cad599b1a5374b694f169ea57
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Jan 10 13:15:19 2018 +0100

    Define "set up" and "tear down" methods for tests
---
 js/test/main.js | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/js/test/main.js b/js/test/main.js
index 777c020..2ded74e 100644
--- a/js/test/main.js
+++ b/js/test/main.js
@@ -1,19 +1,33 @@
 const ava = require("ava");
 const sinon = require("sinon");
 
-var document = global.document = {};
-document.addEventListener = function(){};
-const bo = require("../backoffice");
-
-ava.test("orders tracking", (t) => {
-  var xhr = sinon.useFakeXMLHttpRequest();
-  var requests = [];
-  xhr.onCreate = function(xhr){
-    requests.push(xhr);
+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);
   };
+  global.XMLHttpRequest = t.context.xhr;
+
+  // Global 'document' mock
+  global.document = {};
+  global.document.addEventListener = function(){};
+
+  // Load back-office code
+  t.context.bo = require("../backoffice");
+});
+
+// Remove mocks from global scope
+ava.test.afterEach(t => {
+  delete global.XMLHttpRequest;
+  delete global.document;
+});
 
-  bo.track_order(22); // Throws: XMLHttpRequest is not defined.
+ava.test("orders tracking", (t) => {
+  t.context.bo.track_order(22);
 
-  xhr.restore();
+  // Clean up
+  t.context.xhr.restore();
   t.pass();
 });

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]