Skip to content

Commit

Permalink
[test] Added Faker.unique test suite #466
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Sep 8, 2017
1 parent 633412c commit 0e542a8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/unique.unit.js
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/));
});

});
});

0 comments on commit 0e542a8

Please sign in to comment.