aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJim Fitzpatrick <[email protected]>2016-05-05 11:12:52 -0400
committerMarak <[email protected]>2017-02-21 12:57:26 -0500
commit4a59e1861d19005affe9d8bcb90e1fd65baa3596 (patch)
tree0fcb337ac6f58afabede33389b3cdfdc1a274cb5 /test
parent59ac9a632bb863e114fb05d241dce463f424c382 (diff)
downloadfaker-4a59e1861d19005affe9d8bcb90e1fd65baa3596.tar.xz
faker-4a59e1861d19005affe9d8bcb90e1fd65baa3596.zip
Functionally test all modules/methods
Walk over the faker object to accumulate all methods for functional testing purposes, blacklisting those that should be ignored. Conflicts: test/all.functional.js
Diffstat (limited to 'test')
-rw-r--r--test/all.functional.js92
1 files changed, 47 insertions, 45 deletions
diff --git a/test/all.functional.js b/test/all.functional.js
index 2fccb10a..99ed0b92 100644
--- a/test/all.functional.js
+++ b/test/all.functional.js
@@ -4,56 +4,58 @@ if (typeof module !== 'undefined') {
var faker = require('../index');
}
-// Basic smoke tests to make sure each method is at least implemented and returns a string.
-
-var modules = {
- address: [
- 'city', 'streetName', 'streetAddress', 'secondaryAddress',
- 'country', 'county', 'state', 'zipCode'
- ],
-
- company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'],
-
- database: ['column', 'collation', 'engine', 'type'],
+var IGNORED_MODULES = ['locales', 'locale', 'localeFallback', 'definitions', 'fake', 'helpers'];
+var IGNORED_METHODS = {
+ system: ['directoryPath', 'filePath'] // these are TODOs
+};
- internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'],
+function isTestableModule(mod) {
+ return IGNORED_MODULES.indexOf(mod) === -1;
+}
- lorem: ['words', 'sentence', 'slug', 'sentences', 'paragraph', 'paragraphs'],
+function isMethodOf(mod) {
+ return function(meth) {
+ return typeof faker[mod][meth] === 'function';
+ };
+}
- name: ['firstName', 'lastName', 'findName', 'jobTitle'],
+function isTestableMethod(mod) {
+ return function(meth) {
+ return !(mod in IGNORED_METHODS && IGNORED_METHODS[mod].indexOf(meth) >= 0);
+ };
+}
- phone: ['phoneNumber'],
+function both(pred1, pred2) {
+ return function(value) {
+ return pred1(value) && pred2(value);
+ };
+}
- finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol']
+// Basic smoke tests to make sure each method is at least implemented and returns a value.
-// commerce: ['color', 'department', 'productName', 'price']
-};
+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 () {
-
- function assertMethodResult(meth, result) {
- if (meth === 'boolean') {
- assert.ok(result === true || result === false);
- } else {
- assert.ok(result);
- }
- }
-
- 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 () {
- assertMethodResult(meth, faker[module][meth]());
- });
-
- it(meth + "() without context", function () {
- assertMethodResult(meth, faker[module][meth].call(null));
- });
- });
- });
- });
- }
-
-});
+ 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);
+ }
+ });
+ });
+ });
+ });
+ }
+}); \ No newline at end of file