aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/utile/test/utile-test.js
blob: 7dd5b0f9d6bcc802f26c6fca229d2a51a618acba (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * utile-test.js: Tests for `utile` module.
 *
 * (C) 2011, Nodejitsu Inc.
 * MIT LICENSE
 *
 */

var assert = require('assert'),
    vows = require('vows'),
    utile = require('../lib');

var obj1, obj2;

obj1 = {
  foo: true,
  bar: {
    bar1: true,
    bar2: 'bar2'
  }
};

obj2 = {
  baz: true,
  buzz: 'buzz'
};

Object.defineProperties(obj2, {

  'bazz': {
    get: function() {
      return 'bazz';
    },

    set: function() {
      return 'bazz';
    }
  },

  'wat': {
    set: function() {
      return 'wat';
    }
  }

});

vows.describe('utile').addBatch({
  "When using utile": {
    "it should have the same methods as the `util` module": function () {
      Object.keys(require('util')).forEach(function (fn) {
        assert.isFunction(utile[fn]);
      });
    },
    "it should have the correct methods defined": function () {
      assert.isFunction(utile.mixin);
      assert.isFunction(utile.clone);
      assert.isFunction(utile.rimraf);
      assert.isFunction(utile.mkdirp);
      assert.isFunction(utile.cpr);
    },
    "the mixin() method": function () {
      var mixed = utile.mixin({}, obj1, obj2);
      assert.isTrue(mixed.foo);
      assert.isObject(mixed.bar);
      assert.isTrue(mixed.baz);
      assert.isString(mixed.buzz);
      assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').get);
      assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').set);
      assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'wat').set);
      assert.isString(mixed.bazz);
    },
    "the clone() method": function () {
      var clone = utile.clone(obj1);
      assert.isTrue(clone.foo);
      assert.isObject(clone.bar);
      assert.notStrictEqual(obj1, clone);
    },
    "the createPath() method": function () {
      var x = {},
          r = Math.random();

      utile.createPath(x, ['a','b','c'], r)
      assert.equal(x.a.b.c, r)
    },
    "the capitalize() method": function () {
      assert.isFunction(utile.capitalize);
      assert.equal(utile.capitalize('bullet'), 'Bullet');
      assert.equal(utile.capitalize('bullet_train'), 'BulletTrain');
    },
    "the escapeRegExp() method": function () {
      var ans = "\\/path\\/to\\/resource\\.html\\?search=query";
      assert.isFunction(utile.escapeRegExp);
      assert.equal(utile.escapeRegExp('/path/to/resource.html?search=query'), ans);
    },
    "the underscoreToCamel() method": function () {
      var obj = utile.underscoreToCamel({
        key_with_underscore: {
          andNested: 'values',
          several: [1, 2, 3],
          nested_underscores: true
        },
        just_one: 'underscore'
      });

      assert.isObject(obj.keyWithUnderscore);
      assert.isString(obj.justOne);
      assert.isTrue(obj.keyWithUnderscore.nestedUnderscores);
    },
    "the camelToUnderscore() method": function () {
      var obj = utile.camelToUnderscore({
        keyWithCamel: {
          andNested: 'values',
          several: [1, 2, 3],
          nestedCamel: true
        },
        justOne: 'camel'
      });

      assert.isObject(obj.key_with_camel);
      assert.isString(obj.just_one);
      assert.isTrue(obj.key_with_camel.nested_camel);
    }
  }
}).export(module);