forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Added
Faker.unique
test suite #466
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
if (typeof module !== 'undefined') { | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var faker = require('../index'); | ||
} | ||
|
||
describe("unique.js", function () { | ||
describe("unique()", function () { | ||
|
||
it("is able to call a function with no arguments and return a result", function () { | ||
var result = faker.unique(faker.internet.email); | ||
assert.equal(typeof result, 'string'); | ||
}); | ||
|
||
it("is able to call a function with arguments and return a result", function () { | ||
var result = faker.unique(faker.internet.email, ['a', 'b', 'c']); // third argument is provider, or domain for email | ||
assert.ok(result.match(/\@c/)); | ||
}); | ||
|
||
it("is able to call a function with arguments and return a result", function () { | ||
var result = faker.unique(faker.internet.email, ['a', 'b', 'c']); // third argument is provider, or domain for email | ||
assert.ok(result.match(/\@c/)); | ||
}); | ||
|
||
it("is able to exclude results as array", function () { | ||
var result = faker.unique(faker.internet.protocol, [], { exclude: ['https'] }); | ||
assert.equal(result, 'http'); | ||
}); | ||
|
||
it("is able to limit unique call by maxTime in ms", function () { | ||
var result; | ||
try { | ||
result = faker.unique(faker.internet.protocol, [], { maxTime: 1, maxRetries: 9999, exclude: ['https', 'http'] }); | ||
} catch (err) { | ||
assert.equal(err.message.substr(0, 16), 'exceeded maxTime'); | ||
} | ||
}); | ||
|
||
it("is able to limit unique call by maxRetries", function () { | ||
var result; | ||
try { | ||
result = faker.unique(faker.internet.protocol, [], { maxTime: 5000, maxRetries: 5, exclude: ['https', 'http'] }); | ||
} catch (err) { | ||
assert.equal(err.message.substr(0, 19), 'exceeded maxRetries'); | ||
} | ||
}); | ||
|
||
it("is able to call a function with arguments and return a result", function () { | ||
var result = faker.unique(faker.internet.email, ['a', 'b', 'c']); // third argument is provider, or domain for email | ||
assert.ok(result.match(/\@c/)); | ||
}); | ||
|
||
}); | ||
}); |