aboutsummaryrefslogtreecommitdiff
path: root/test/fake.unit.js
blob: 2ab6b4c01c9c7d268f04786a838450410e837c7f (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
if (typeof module !== 'undefined') {
  var assert = require('assert');
  var sinon = require('sinon');
  var faker = require('../index');
}

describe("fake.js", function () {
  describe("fake()", function () {
    it("replaces a token with a random value for a method with no parameters", function () {
      var name = faker.fake('{{phone.phoneNumber}}');
      assert.ok(name.match(/\d/));
    });

    it("replaces multiple tokens with random values for methods with no parameters", function () {
      var name = faker.fake('{{helpers.randomize}}{{helpers.randomize}}{{helpers.randomize}}');
      assert.ok(name.match(/[abc]{3}/));
    });

    it("replaces a token with a random value for a methods with a simple parameter", function () {
      var arr = ["one", "two", "three"];
      var random = faker.fake('{{helpers.slugify("Will This Work")}}');
      assert.ok(random === "Will-This-Work");
    });

    it("replaces a token with a random value for a method with an array parameter", function () {
      var arr = ["one", "two", "three"];
      var random = faker.fake('{{helpers.randomize(["one", "two", "three"])}}');
      assert.ok(arr.indexOf(random) > -1);
    });

    it("does not allow undefined parameters", function () {
      assert.throws(function () {
        faker.fake()
      }, Error);
    });

    it("does not allow invalid module name", function () {
      assert.throws(function () {
        faker.fake('{{foo.bar}}')
      }, Error);
    });

    it("does not allow invalid method name", function () {
      assert.throws(function () {
        faker.fake('{{address.foo}}')
      }, Error);
    });


  });
});