aboutsummaryrefslogtreecommitdiff
path: root/test/word.unit.js
blob: 0dfdf60a2b5c63b60af7a12fde20bb5f44c7283a (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
if (typeof module !== "undefined") {
  var assert = require("assert");
  var faker = require("../index");
}

describe("word.js", function () {
  var methods = [
    "adjective",
    "adverb",
    "conjunction",
    "interjection",
    "noun",
    "preposition",
    "verb",
  ];
  // Perform the same three tests for each method.
  methods.forEach(function (method) {
    describe(method + "()", function () {
      it("returns random value from " + method + " array", function () {
        var word = faker.word[method]();
        assert.ok(faker.definitions.word[method].includes(word));
      });
      it("optional length parameter returns expected result", function () {
        var wordLength = 5;
        var word = faker.word[method](wordLength);
        assert.ok(faker.definitions.word[method].includes(word));
        assert.ok(word.length == wordLength);
      });
      it("unresolvable optional length returns random " + method, function () {
        var wordLength = 1000;
        var word = faker.word[method](wordLength);
        assert.ok(faker.definitions.word[method].includes(word));
      });
    });
  });
});