Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/test/unit/mocks_helper.js
blob: 40c8689395622eae47943b6362b41d6bce094c7d (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
34
35
36
37
38
39
40
var MocksHelper = function(mocks) {
  this.mocks = mocks;
  this.realWindowObjects = {};
};

MocksHelper.prototype = {

  setup: function mh_setup() {
  },

  suiteSetup: function mh_suiteSetup() {
    this.mocks.forEach(function(objName) {
      var mockName = 'Mock' + objName;
      if (!window[mockName]) {
        throw 'Mock ' + mockName + ' has not been loaded into the test';
      }

      this.realWindowObjects[objName] = window[objName];
      window[objName] = window[mockName];
    }, this);
  },

  suiteTeardown: function mh_suiteTeardown() {
    this.mocks.forEach(function(objName) {
      window[objName] = this.realWindowObjects[objName];
    }, this);
  },

  teardown: function mh_teardown() {
    this.mocks.forEach(function(objName) {
      var mockName = 'Mock' + objName;
      var mock = window[mockName];

      if (mock.mTeardown) {
        mock.mTeardown();
      }
    });
  }
};