summaryrefslogtreecommitdiff
path: root/js/test/main.js
blob: 2ded74eb6a2893833fa951e2b8327dde7dc1d3dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const ava = require("ava");
const sinon = require("sinon");

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;
});

ava.test("orders tracking", (t) => {
  t.context.bo.track_order(22);

  // Clean up
  t.context.xhr.restore();
  t.pass();
});