forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all.functional.js
61 lines (53 loc) · 1.72 KB
/
all.functional.js
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
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var faker = require('../index');
}
var IGNORED_MODULES = ['locales', 'locale', 'localeFallback', 'definitions', 'fake', 'helpers'];
var IGNORED_METHODS = {
system: ['directoryPath', 'filePath'] // these are TODOs
};
function isTestableModule(mod) {
return IGNORED_MODULES.indexOf(mod) === -1;
}
function isMethodOf(mod) {
return function(meth) {
return typeof faker[mod][meth] === 'function';
};
}
function isTestableMethod(mod) {
return function(meth) {
return !(mod in IGNORED_METHODS && IGNORED_METHODS[mod].indexOf(meth) >= 0);
};
}
function both(pred1, pred2) {
return function(value) {
return pred1(value) && pred2(value);
};
}
// Basic smoke tests to make sure each method is at least implemented and returns a value.
var modules = Object.keys(faker)
.filter(isTestableModule)
.reduce(function(result, mod) {
result[mod] = Object.keys(faker[mod]).filter(both(isMethodOf(mod), isTestableMethod(mod)));
return result;
}, {});
describe("functional tests", function () {
for(var locale in faker.locales) {
faker.locale = locale;
Object.keys(modules).forEach(function (module) {
describe(module, function () {
modules[module].forEach(function (meth) {
it(meth + "()", function () {
var result = faker[module][meth]();
if (meth === 'boolean') {
assert.ok(result === true || result === false);
} else {
assert.ok(result);
}
});
});
});
});
}
});