aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/address.unit.js964
-rw-r--r--test/all.functional.js48
-rw-r--r--test/animal.unit.js8
-rw-r--r--test/commerce.unit.js116
-rw-r--r--test/company.unit.js178
-rw-r--r--test/database.unit.js72
-rw-r--r--test/datatype.unit.js560
-rw-r--r--test/date.unit.js276
-rw-r--r--test/fake.unit.js86
-rw-r--r--test/finance_iban.unit.js222
-rw-r--r--test/helpers.unit.js268
-rw-r--r--test/image.unit.js446
-rw-r--r--test/internet.unit.js350
-rw-r--r--test/locales.unit.js20
-rw-r--r--test/lorem.unit.js138
-rw-r--r--test/music.unit.js20
-rw-r--r--test/name.unit.js422
-rw-r--r--test/phone_number.unit.js72
-rw-r--r--test/random.unit.js10
-rwxr-xr-xtest/run.js66
-rw-r--r--test/system.unit.js62
-rw-r--r--test/time.unit.js38
-rw-r--r--test/unique.unit.js94
-rw-r--r--test/vehicle.unit.js78
24 files changed, 2307 insertions, 2307 deletions
diff --git a/test/address.unit.js b/test/address.unit.js
index 0306f4f1..57f4c8d7 100644
--- a/test/address.unit.js
+++ b/test/address.unit.js
@@ -1,558 +1,558 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("address.js", function () {
- describe("city()", function () {
- beforeEach(function () {
- sinon.spy(faker.address, 'cityPrefix');
- sinon.spy(faker.name, 'firstName');
- sinon.spy(faker.name, 'lastName');
- sinon.spy(faker.address, 'citySuffix');
- });
+ describe("city()", function () {
+ beforeEach(function () {
+ sinon.spy(faker.address, 'cityPrefix');
+ sinon.spy(faker.name, 'firstName');
+ sinon.spy(faker.name, 'lastName');
+ sinon.spy(faker.address, 'citySuffix');
+ });
- afterEach(function () {
- faker.datatype.number.restore();
- faker.address.cityPrefix.restore();
- faker.name.firstName.restore();
- faker.name.lastName.restore();
- faker.address.citySuffix.restore();
- });
+ afterEach(function () {
+ faker.datatype.number.restore();
+ faker.address.cityPrefix.restore();
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ faker.address.citySuffix.restore();
+ });
- it("occasionally returns prefix + first name + suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(0);
+ it("occasionally returns prefix + first name + suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
- var city = faker.address.city();
- assert.ok(city);
+ var city = faker.address.city();
+ assert.ok(city);
- assert.ok(faker.address.cityPrefix.calledOnce);
- assert.ok(faker.name.firstName.calledOnce);
- assert.ok(faker.address.citySuffix.calledOnce);
- });
+ assert.ok(faker.address.cityPrefix.calledOnce);
+ assert.ok(faker.name.firstName.calledOnce);
+ assert.ok(faker.address.citySuffix.calledOnce);
+ });
- it("occasionally returns prefix + first name", function () {
- sinon.stub(faker.datatype, 'number').returns(1);
+ it("occasionally returns prefix + first name", function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
- var city = faker.address.city();
- assert.ok(city);
+ var city = faker.address.city();
+ assert.ok(city);
- assert.ok(faker.address.cityPrefix.calledOnce);
- assert.ok(faker.name.firstName.calledOnce);
- });
+ assert.ok(faker.address.cityPrefix.calledOnce);
+ assert.ok(faker.name.firstName.calledOnce);
+ });
- it("occasionally returns first name + suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(2);
+ it("occasionally returns first name + suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(2);
- var city = faker.address.city();
- assert.ok(city);
+ var city = faker.address.city();
+ assert.ok(city);
- assert.ok(faker.address.citySuffix.calledOnce);
- });
+ assert.ok(faker.address.citySuffix.calledOnce);
+ });
- it("occasionally returns last name + suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(3);
+ it("occasionally returns last name + suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(3);
- var city = faker.address.city();
- assert.ok(city);
+ var city = faker.address.city();
+ assert.ok(city);
- assert.ok(!faker.address.cityPrefix.called);
- assert.ok(!faker.name.firstName.called);
- assert.ok(faker.name.lastName.calledOnce);
- assert.ok(faker.address.citySuffix.calledOnce);
- });
+ assert.ok(!faker.address.cityPrefix.called);
+ assert.ok(!faker.name.firstName.called);
+ assert.ok(faker.name.lastName.calledOnce);
+ assert.ok(faker.address.citySuffix.calledOnce);
});
+ });
- describe("streetName()", function () {
- beforeEach(function () {
- sinon.spy(faker.name, 'firstName');
- sinon.spy(faker.name, 'lastName');
- sinon.spy(faker.address, 'streetSuffix');
- });
+ describe("streetName()", function () {
+ beforeEach(function () {
+ sinon.spy(faker.name, 'firstName');
+ sinon.spy(faker.name, 'lastName');
+ sinon.spy(faker.address, 'streetSuffix');
+ });
- afterEach(function () {
- faker.name.firstName.restore();
- faker.name.lastName.restore();
- faker.address.streetSuffix.restore();
- });
+ afterEach(function () {
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ faker.address.streetSuffix.restore();
+ });
- it("occasionally returns last name + suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(0);
+ it("occasionally returns last name + suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
- var street_name = faker.address.streetName();
- assert.ok(street_name);
- assert.ok(!faker.name.firstName.called);
- assert.ok(faker.name.lastName.calledOnce);
- assert.ok(faker.address.streetSuffix.calledOnce);
+ var street_name = faker.address.streetName();
+ assert.ok(street_name);
+ assert.ok(!faker.name.firstName.called);
+ assert.ok(faker.name.lastName.calledOnce);
+ assert.ok(faker.address.streetSuffix.calledOnce);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("occasionally returns first name + suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(1);
+ it("occasionally returns first name + suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
- var street_name = faker.address.streetName();
- assert.ok(street_name);
+ var street_name = faker.address.streetName();
+ assert.ok(street_name);
- assert.ok(faker.name.firstName.calledOnce);
- assert.ok(!faker.name.lastName.called);
- assert.ok(faker.address.streetSuffix.calledOnce);
+ assert.ok(faker.name.firstName.calledOnce);
+ assert.ok(!faker.name.lastName.called);
+ assert.ok(faker.address.streetSuffix.calledOnce);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("trims trailing whitespace from the name", function() {
- faker.address.streetSuffix.restore();
+ it("trims trailing whitespace from the name", function() {
+ faker.address.streetSuffix.restore();
- sinon.stub(faker.address, 'streetSuffix').returns("")
- var street_name = faker.address.streetName();
- assert.ok(!street_name.match(/ $/));
- });
+ sinon.stub(faker.address, 'streetSuffix').returns("")
+ var street_name = faker.address.streetName();
+ assert.ok(!street_name.match(/ $/));
});
+ });
- describe("streetAddress()", function () {
+ describe("streetAddress()", function () {
- var errorExpectDigits = function(expected){
- return "The street number should be had " + expected + " digits"
- }
+ var errorExpectDigits = function(expected){
+ return "The street number should be had " + expected + " digits"
+ }
- beforeEach(function () {
- sinon.spy(faker.address, 'streetName');
- sinon.spy(faker.address, 'secondaryAddress');
- });
+ beforeEach(function () {
+ sinon.spy(faker.address, 'streetName');
+ sinon.spy(faker.address, 'secondaryAddress');
+ });
- afterEach(function () {
- faker.address.streetName.restore();
- faker.address.secondaryAddress.restore();
- });
+ afterEach(function () {
+ faker.address.streetName.restore();
+ faker.address.secondaryAddress.restore();
+ });
- it("occasionally returns a 5-digit street number", function () {
- sinon.stub(faker.datatype, 'number').returns(0);
- var address = faker.address.streetAddress();
- var expected = 5
- var parts = address.split(' ');
+ it("occasionally returns a 5-digit street number", function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
+ var address = faker.address.streetAddress();
+ var expected = 5
+ var parts = address.split(' ');
- assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
- assert.ok(faker.address.streetName.called);
+ assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
+ assert.ok(faker.address.streetName.called);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("occasionally returns a 4-digit street number", function () {
- sinon.stub(faker.datatype, 'number').returns(1);
- var address = faker.address.streetAddress();
- var parts = address.split(' ');
- var expected = 4
+ it("occasionally returns a 4-digit street number", function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
+ var address = faker.address.streetAddress();
+ var parts = address.split(' ');
+ var expected = 4
- assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
- assert.ok(faker.address.streetName.called);
+ assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
+ assert.ok(faker.address.streetName.called);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("occasionally returns a 3-digit street number", function () {
- sinon.stub(faker.datatype, 'number').returns(2);
- var address = faker.address.streetAddress();
- var parts = address.split(' ');
- var expected = 3
+ it("occasionally returns a 3-digit street number", function () {
+ sinon.stub(faker.datatype, 'number').returns(2);
+ var address = faker.address.streetAddress();
+ var parts = address.split(' ');
+ var expected = 3
- assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
- assert.ok(faker.address.streetName.called);
- assert.ok(!faker.address.secondaryAddress.called);
+ assert.strictEqual(parts[0].length, expected, errorExpectDigits(expected));
+ assert.ok(faker.address.streetName.called);
+ assert.ok(!faker.address.secondaryAddress.called);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- context("when useFulladdress is true", function () {
- it("adds a secondary address to the result", function () {
- faker.address.streetAddress(true);
+ context("when useFulladdress is true", function () {
+ it("adds a secondary address to the result", function () {
+ faker.address.streetAddress(true);
- assert.ok(faker.address.secondaryAddress.called);
- });
- });
- });
-
-
- describe("secondaryAddress()", function () {
- it("randomly chooses an Apt or Suite number", function () {
- sinon.spy(faker.random, 'arrayElement');
-
- var address = faker.address.secondaryAddress();
-
- var expected_array = [
- 'Apt. ###',
- 'Suite ###'
- ];
-
- assert.ok(address);
- assert.ok(faker.random.arrayElement.calledWith(expected_array));
- faker.random.arrayElement.restore();
- });
- });
-
- describe("county()", function () {
- it("returns random county", function () {
- sinon.spy(faker.address, 'county');
- var county = faker.address.county();
- assert.ok(county);
- assert.ok(faker.address.county.called);
- faker.address.county.restore();
- });
- });
-
- describe("country()", function () {
- it("returns random country", function () {
- sinon.spy(faker.address, 'country');
- var country = faker.address.country();
- assert.ok(country);
- assert.ok(faker.address.country.called);
- faker.address.country.restore();
- });
- });
-
- describe("countryCode()", function () {
-
- it("returns random countryCode", function () {
- sinon.spy(faker.address, 'countryCode');
- var countryCode = faker.address.countryCode();
- assert.ok(countryCode);
- assert.ok(faker.address.countryCode.called);
- faker.address.countryCode.restore();
- });
-
- it("returns random alpha-3 countryCode", function () {
- sinon.spy(faker.address, 'countryCode');
- var countryCode = faker.address.countryCode("alpha-3");
- assert.ok(countryCode);
- assert.ok(faker.address.countryCode.called);
- assert.strictEqual(countryCode.length, 3, "The countryCode should be had 3 characters");
- faker.address.countryCode.restore();
- });
+ assert.ok(faker.address.secondaryAddress.called);
+ });
+ });
+ });
+
+
+ describe("secondaryAddress()", function () {
+ it("randomly chooses an Apt or Suite number", function () {
+ sinon.spy(faker.random, 'arrayElement');
+
+ var address = faker.address.secondaryAddress();
+
+ var expected_array = [
+ 'Apt. ###',
+ 'Suite ###'
+ ];
+
+ assert.ok(address);
+ assert.ok(faker.random.arrayElement.calledWith(expected_array));
+ faker.random.arrayElement.restore();
+ });
+ });
+
+ describe("county()", function () {
+ it("returns random county", function () {
+ sinon.spy(faker.address, 'county');
+ var county = faker.address.county();
+ assert.ok(county);
+ assert.ok(faker.address.county.called);
+ faker.address.county.restore();
+ });
+ });
+
+ describe("country()", function () {
+ it("returns random country", function () {
+ sinon.spy(faker.address, 'country');
+ var country = faker.address.country();
+ assert.ok(country);
+ assert.ok(faker.address.country.called);
+ faker.address.country.restore();
+ });
+ });
+
+ describe("countryCode()", function () {
+
+ it("returns random countryCode", function () {
+ sinon.spy(faker.address, 'countryCode');
+ var countryCode = faker.address.countryCode();
+ assert.ok(countryCode);
+ assert.ok(faker.address.countryCode.called);
+ faker.address.countryCode.restore();
+ });
+
+ it("returns random alpha-3 countryCode", function () {
+ sinon.spy(faker.address, 'countryCode');
+ var countryCode = faker.address.countryCode("alpha-3");
+ assert.ok(countryCode);
+ assert.ok(faker.address.countryCode.called);
+ assert.strictEqual(countryCode.length, 3, "The countryCode should be had 3 characters");
+ faker.address.countryCode.restore();
+ });
+ });
+
+ describe("state()", function () {
+ it("returns random state", function () {
+ sinon.spy(faker.address, 'state');
+ var state = faker.address.state();
+ assert.ok(state);
+ assert.ok(faker.address.state.called);
+ faker.address.state.restore();
+ });
+ });
+
+ describe("zipCode()", function () {
+ it("returns random zipCode", function () {
+ sinon.spy(faker.address, 'zipCode');
+ var zipCode = faker.address.zipCode();
+ assert.ok(zipCode);
+ assert.ok(faker.address.zipCode.called);
+ faker.address.zipCode.restore();
+ });
+
+ it("returns random zipCode - user specified format", function () {
+ var zipCode = faker.address.zipCode("?#? #?#");
+ assert.ok(zipCode.match(/^[A-Za-z]\d[A-Za-z]\s\d[A-Za-z]\d$/));
+ // try another format
+ zipCode = faker.address.zipCode("###-###");
+ assert.ok(zipCode.match(/^\d{3}-\d{3}$/));
});
- describe("state()", function () {
- it("returns random state", function () {
- sinon.spy(faker.address, 'state');
- var state = faker.address.state();
- assert.ok(state);
- assert.ok(faker.address.state.called);
- faker.address.state.restore();
- });
- });
-
- describe("zipCode()", function () {
- it("returns random zipCode", function () {
- sinon.spy(faker.address, 'zipCode');
- var zipCode = faker.address.zipCode();
- assert.ok(zipCode);
- assert.ok(faker.address.zipCode.called);
- faker.address.zipCode.restore();
- });
-
- it("returns random zipCode - user specified format", function () {
- var zipCode = faker.address.zipCode("?#? #?#");
- assert.ok(zipCode.match(/^[A-Za-z]\d[A-Za-z]\s\d[A-Za-z]\d$/));
- // try another format
- zipCode = faker.address.zipCode("###-###");
- assert.ok(zipCode.match(/^\d{3}-\d{3}$/));
- });
-
- it("returns zipCode with proper locale format", function () {
- // we'll use the en_CA locale..
- faker.locale = "en_CA";
- var zipCode = faker.address.zipCode();
- assert.ok(zipCode.match(/^[A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d$/));
- });
- });
-
- describe("zipCodeByState()", function () {
- it("returns zipCode valid for specified State", function () {
- faker.locale = "en_US";
- var states = ["IL", "GA", "WA"];
-
- var zipCode1 = faker.address.zipCodeByState(states[0]);
- assert.ok(zipCode1 >= 60001);
- assert.ok(zipCode1 <= 62999);
- var zipCode2 = faker.address.zipCodeByState(states[1]);
- assert.ok(zipCode2 >= 30001);
- assert.ok(zipCode2 <= 31999);
- var zipCode3 = faker.address.zipCodeByState(states[2]);
- assert.ok(zipCode3 >= 98001);
- assert.ok(zipCode3 <= 99403);
- });
-
- it("returns undefined if state is invalid", function () {
- var state = "XX";
- sinon.spy(faker.address, 'zipCode');
- faker.address.zipCodeByState(state);
- assert.ok(faker.address.zipCode.called);
- faker.address.zipCode.restore();
- });
-
- it("returns undefined if state is valid but localeis invalid", function () {
- faker.locale = "zh_CN";
- var state = "IL";
- sinon.spy(faker.address, 'zipCode');
- faker.address.zipCodeByState(state);
- assert.ok(faker.address.zipCode.called);
- faker.address.zipCode.restore();
- });
- });
-
- describe("latitude()", function () {
- it("returns random latitude", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var latitude = faker.address.latitude();
- assert.ok(typeof latitude === 'string');
- var latitude_float = parseFloat(latitude);
- assert.ok(latitude_float >= -90.0);
- assert.ok(latitude_float <= 90.0);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
-
- it("returns latitude with min and max and default precision", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var latitude = faker.address.latitude(-5, 5);
- assert.ok(typeof latitude === 'string');
- assert.strictEqual(latitude.split('.')[1].length, 4, "The precision of latitude should be had of 4 digits");
- var latitude_float = parseFloat(latitude);
- assert.ok(latitude_float >= -5);
- assert.ok(latitude_float <= 5);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
-
- it("returns random latitude with custom precision", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var latitude = faker.address.latitude(undefined, undefined, 7);
- assert.ok(typeof latitude === 'string');
- assert.strictEqual(latitude.split('.')[1].length, 7, "The precision of latitude should be had of 7 digits");
- var latitude_float = parseFloat(latitude);
- assert.ok(latitude_float >= -180);
- assert.ok(latitude_float <= 180);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
- });
-
- describe("longitude()", function () {
- it("returns random longitude", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var longitude = faker.address.longitude();
- assert.ok(typeof longitude === 'string');
- var longitude_float = parseFloat(longitude);
- assert.ok(longitude_float >= -180.0);
- assert.ok(longitude_float <= 180.0);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
-
- it("returns random longitude with min and max and default precision", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var longitude = faker.address.longitude(100, -30);
- assert.ok(typeof longitude === 'string');
- assert.strictEqual(longitude.split('.')[1].length, 4, "The precision of longitude should be had of 4 digits");
- var longitude_float = parseFloat(longitude);
- assert.ok(longitude_float >= -30);
- assert.ok(longitude_float <= 100);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
-
- it("returns random longitude with custom precision", function () {
- for (var i = 0; i < 100; i++) {
- sinon.spy(faker.datatype, 'number');
- var longitude = faker.address.longitude(undefined, undefined, 7);
- assert.ok(typeof longitude === 'string');
- assert.strictEqual(longitude.split('.')[1].length, 7, "The precision of longitude should be had of 7 digits");
- var longitude_float = parseFloat(longitude);
- assert.ok(longitude_float >= -180);
- assert.ok(longitude_float <= 180);
- assert.ok(faker.datatype.number.called);
- faker.datatype.number.restore();
- }
- });
- });
-
- describe("direction()", function () {
- it("returns random direction", function () {
- sinon.stub(faker.address, 'direction').returns('North');
- var direction = faker.address.direction();
- var expected = 'North';
-
- assert.strictEqual(direction, expected, "The random direction should be equals " + expected);
- faker.address.direction.restore();
- })
-
- it("returns abbreviation when useAbbr is false", function () {
- sinon.stub(faker.address, 'direction').returns('N');
- var direction = faker.address.direction(false);
- var expected = 'N';
- assert.strictEqual(direction, expected, "The abbreviation of direction when useAbbr is false should be equals " + expected+ ". Current is " + direction);
- faker.address.direction.restore();
- })
-
- it("returns abbreviation when useAbbr is true", function () {
- var direction = faker.address.direction(true);
- var expectedType = 'string';
- var lengthDirection = direction.length
- var prefixErrorMessage = "The abbreviation of direction when useAbbr is true should"
- assert.strictEqual(typeof direction, expectedType, prefixErrorMessage + " be typeof string. Current is" + typeof direction);
- assert.strictEqual(lengthDirection <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + lengthDirection);
- })
-
- it("returns abbreviation when useAbbr is true", function () {
- sinon.stub(faker.address, 'direction').returns('N');
- var direction = faker.address.direction(true);
- var expected = 'N';
- assert.strictEqual(direction, expected, "The abbreviation of direction when useAbbr is true should be equals " + expected + ". Current is " + direction);
- faker.address.direction.restore();
- })
+ it("returns zipCode with proper locale format", function () {
+ // we'll use the en_CA locale..
+ faker.locale = "en_CA";
+ var zipCode = faker.address.zipCode();
+ assert.ok(zipCode.match(/^[A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d$/));
+ });
+ });
+
+ describe("zipCodeByState()", function () {
+ it("returns zipCode valid for specified State", function () {
+ faker.locale = "en_US";
+ var states = ["IL", "GA", "WA"];
+
+ var zipCode1 = faker.address.zipCodeByState(states[0]);
+ assert.ok(zipCode1 >= 60001);
+ assert.ok(zipCode1 <= 62999);
+ var zipCode2 = faker.address.zipCodeByState(states[1]);
+ assert.ok(zipCode2 >= 30001);
+ assert.ok(zipCode2 <= 31999);
+ var zipCode3 = faker.address.zipCodeByState(states[2]);
+ assert.ok(zipCode3 >= 98001);
+ assert.ok(zipCode3 <= 99403);
+ });
+
+ it("returns undefined if state is invalid", function () {
+ var state = "XX";
+ sinon.spy(faker.address, 'zipCode');
+ faker.address.zipCodeByState(state);
+ assert.ok(faker.address.zipCode.called);
+ faker.address.zipCode.restore();
+ });
+
+ it("returns undefined if state is valid but localeis invalid", function () {
+ faker.locale = "zh_CN";
+ var state = "IL";
+ sinon.spy(faker.address, 'zipCode');
+ faker.address.zipCodeByState(state);
+ assert.ok(faker.address.zipCode.called);
+ faker.address.zipCode.restore();
+ });
+ });
+
+ describe("latitude()", function () {
+ it("returns random latitude", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var latitude = faker.address.latitude();
+ assert.ok(typeof latitude === 'string');
+ var latitude_float = parseFloat(latitude);
+ assert.ok(latitude_float >= -90.0);
+ assert.ok(latitude_float <= 90.0);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+
+ it("returns latitude with min and max and default precision", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var latitude = faker.address.latitude(-5, 5);
+ assert.ok(typeof latitude === 'string');
+ assert.strictEqual(latitude.split('.')[1].length, 4, "The precision of latitude should be had of 4 digits");
+ var latitude_float = parseFloat(latitude);
+ assert.ok(latitude_float >= -5);
+ assert.ok(latitude_float <= 5);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+
+ it("returns random latitude with custom precision", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var latitude = faker.address.latitude(undefined, undefined, 7);
+ assert.ok(typeof latitude === 'string');
+ assert.strictEqual(latitude.split('.')[1].length, 7, "The precision of latitude should be had of 7 digits");
+ var latitude_float = parseFloat(latitude);
+ assert.ok(latitude_float >= -180);
+ assert.ok(latitude_float <= 180);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+ });
+
+ describe("longitude()", function () {
+ it("returns random longitude", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var longitude = faker.address.longitude();
+ assert.ok(typeof longitude === 'string');
+ var longitude_float = parseFloat(longitude);
+ assert.ok(longitude_float >= -180.0);
+ assert.ok(longitude_float <= 180.0);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+
+ it("returns random longitude with min and max and default precision", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var longitude = faker.address.longitude(100, -30);
+ assert.ok(typeof longitude === 'string');
+ assert.strictEqual(longitude.split('.')[1].length, 4, "The precision of longitude should be had of 4 digits");
+ var longitude_float = parseFloat(longitude);
+ assert.ok(longitude_float >= -30);
+ assert.ok(longitude_float <= 100);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+
+ it("returns random longitude with custom precision", function () {
+ for (var i = 0; i < 100; i++) {
+ sinon.spy(faker.datatype, 'number');
+ var longitude = faker.address.longitude(undefined, undefined, 7);
+ assert.ok(typeof longitude === 'string');
+ assert.strictEqual(longitude.split('.')[1].length, 7, "The precision of longitude should be had of 7 digits");
+ var longitude_float = parseFloat(longitude);
+ assert.ok(longitude_float >= -180);
+ assert.ok(longitude_float <= 180);
+ assert.ok(faker.datatype.number.called);
+ faker.datatype.number.restore();
+ }
+ });
+ });
+ describe("direction()", function () {
+ it("returns random direction", function () {
+ sinon.stub(faker.address, 'direction').returns('North');
+ var direction = faker.address.direction();
+ var expected = 'North';
+
+ assert.strictEqual(direction, expected, "The random direction should be equals " + expected);
+ faker.address.direction.restore();
+ })
+
+ it("returns abbreviation when useAbbr is false", function () {
+ sinon.stub(faker.address, 'direction').returns('N');
+ var direction = faker.address.direction(false);
+ var expected = 'N';
+ assert.strictEqual(direction, expected, "The abbreviation of direction when useAbbr is false should be equals " + expected+ ". Current is " + direction);
+ faker.address.direction.restore();
+ })
+
+ it("returns abbreviation when useAbbr is true", function () {
+ var direction = faker.address.direction(true);
+ var expectedType = 'string';
+ var lengthDirection = direction.length
+ var prefixErrorMessage = "The abbreviation of direction when useAbbr is true should"
+ assert.strictEqual(typeof direction, expectedType, prefixErrorMessage + " be typeof string. Current is" + typeof direction);
+ assert.strictEqual(lengthDirection <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + lengthDirection);
})
- describe("ordinalDirection()", function () {
- it("returns random ordinal direction", function () {
- sinon.stub(faker.address, 'ordinalDirection').returns('West');
- var ordinalDirection = faker.address.ordinalDirection();
- var expected = 'West';
+ it("returns abbreviation when useAbbr is true", function () {
+ sinon.stub(faker.address, 'direction').returns('N');
+ var direction = faker.address.direction(true);
+ var expected = 'N';
+ assert.strictEqual(direction, expected, "The abbreviation of direction when useAbbr is true should be equals " + expected + ". Current is " + direction);
+ faker.address.direction.restore();
+ })
- assert.strictEqual(ordinalDirection, expected, "The ransom ordinal direction should be equals " + expected + ". Current is " + ordinalDirection);
- faker.address.ordinalDirection.restore();
- })
+ })
- it("returns abbreviation when useAbbr is true", function () {
- sinon.stub(faker.address, 'ordinalDirection').returns('W');
- var ordinalDirection = faker.address.ordinalDirection(true);
- var expected = 'W';
+ describe("ordinalDirection()", function () {
+ it("returns random ordinal direction", function () {
+ sinon.stub(faker.address, 'ordinalDirection').returns('West');
+ var ordinalDirection = faker.address.ordinalDirection();
+ var expected = 'West';
- assert.strictEqual(ordinalDirection, expected, "The ordinal direction when useAbbr is true should be equals " + expected + ". Current is " + ordinalDirection);
- faker.address.ordinalDirection.restore();
- })
+ assert.strictEqual(ordinalDirection, expected, "The ransom ordinal direction should be equals " + expected + ". Current is " + ordinalDirection);
+ faker.address.ordinalDirection.restore();
+ })
- it("returns abbreviation when useAbbr is true", function () {
- var ordinalDirection = faker.address.ordinalDirection(true);
- var expectedType = 'string';
- var ordinalDirectionLength = ordinalDirection.length;
- var prefixErrorMessage = "The ordinal direction when useAbbr is true should"
+ it("returns abbreviation when useAbbr is true", function () {
+ sinon.stub(faker.address, 'ordinalDirection').returns('W');
+ var ordinalDirection = faker.address.ordinalDirection(true);
+ var expected = 'W';
- assert.strictEqual(typeof ordinalDirection, expectedType, prefixErrorMessage + " be had typeof equals " + expectedType + ".Current is " + typeof ordinalDirection);
- assert.strictEqual(ordinalDirectionLength <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + ordinalDirectionLength);
- })
+ assert.strictEqual(ordinalDirection, expected, "The ordinal direction when useAbbr is true should be equals " + expected + ". Current is " + ordinalDirection);
+ faker.address.ordinalDirection.restore();
+ })
+ it("returns abbreviation when useAbbr is true", function () {
+ var ordinalDirection = faker.address.ordinalDirection(true);
+ var expectedType = 'string';
+ var ordinalDirectionLength = ordinalDirection.length;
+ var prefixErrorMessage = "The ordinal direction when useAbbr is true should"
+ assert.strictEqual(typeof ordinalDirection, expectedType, prefixErrorMessage + " be had typeof equals " + expectedType + ".Current is " + typeof ordinalDirection);
+ assert.strictEqual(ordinalDirectionLength <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + ordinalDirectionLength);
})
- describe("cardinalDirection()", function () {
- it("returns random cardinal direction", function () {
- sinon.stub(faker.address, 'cardinalDirection').returns('Northwest');
- var cardinalDirection = faker.address.cardinalDirection();
- var expected = 'Northwest';
- assert.strictEqual(cardinalDirection, expected, "The random cardinal direction should be equals " + expected + ". Current is " + cardinalDirection);
- faker.address.cardinalDirection.restore();
- })
+ })
- it("returns abbreviation when useAbbr is true", function () {
- sinon.stub(faker.address, 'cardinalDirection').returns('NW');
- var cardinalDirection = faker.address.cardinalDirection(true);
- var expected = 'NW';
+ describe("cardinalDirection()", function () {
+ it("returns random cardinal direction", function () {
+ sinon.stub(faker.address, 'cardinalDirection').returns('Northwest');
+ var cardinalDirection = faker.address.cardinalDirection();
+ var expected = 'Northwest';
- assert.strictEqual(cardinalDirection, expected, "The cardinal direction when useAbbr is true should be equals " + expected + ". Current is " + cardinalDirection);
- faker.address.cardinalDirection.restore();
- })
+ assert.strictEqual(cardinalDirection, expected, "The random cardinal direction should be equals " + expected + ". Current is " + cardinalDirection);
+ faker.address.cardinalDirection.restore();
+ })
+
+ it("returns abbreviation when useAbbr is true", function () {
+ sinon.stub(faker.address, 'cardinalDirection').returns('NW');
+ var cardinalDirection = faker.address.cardinalDirection(true);
+ var expected = 'NW';
- it("returns abbreviation when useAbbr is true", function () {
- var cardinalDirection = faker.address.cardinalDirection(true);
- var expectedType = 'string';
- var cardinalDirectionLength = cardinalDirection.length;
- var prefixErrorMessage = "The cardinal direction when useAbbr is true should"
+ assert.strictEqual(cardinalDirection, expected, "The cardinal direction when useAbbr is true should be equals " + expected + ". Current is " + cardinalDirection);
+ faker.address.cardinalDirection.restore();
+ })
- assert.strictEqual(typeof cardinalDirection, expectedType, prefixErrorMessage + " be had typeof equals " + expectedType + ".Current is " + typeof ordinalDirection);
- assert.strictEqual(cardinalDirectionLength <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + cardinalDirectionLength);
- })
+ it("returns abbreviation when useAbbr is true", function () {
+ var cardinalDirection = faker.address.cardinalDirection(true);
+ var expectedType = 'string';
+ var cardinalDirectionLength = cardinalDirection.length;
+ var prefixErrorMessage = "The cardinal direction when useAbbr is true should"
+ assert.strictEqual(typeof cardinalDirection, expectedType, prefixErrorMessage + " be had typeof equals " + expectedType + ".Current is " + typeof ordinalDirection);
+ assert.strictEqual(cardinalDirectionLength <= 2, true, prefixErrorMessage + " have a length less or equals 2. Current is " + cardinalDirectionLength);
})
- describe("nearbyGPSCoordinate()", function () {
- it("returns random gps coordinate within a distance of another one", function () {
- function haversine(lat1, lon1, lat2, lon2, isMetric) {
- function degreesToRadians(degrees) {
- return degrees * (Math.PI/180.0);
- }
- function kilometersToMiles(miles) {
- return miles * 0.621371;
- }
- var R = 6378.137;
- var dLat = degreesToRadians(lat2-lat1);
- var dLon = degreesToRadians(lon2-lon1);
- var a = Math.sin(dLat/2) * Math.sin(dLat/2)
+ })
+
+ describe("nearbyGPSCoordinate()", function () {
+ it("returns random gps coordinate within a distance of another one", function () {
+ function haversine(lat1, lon1, lat2, lon2, isMetric) {
+ function degreesToRadians(degrees) {
+ return degrees * (Math.PI/180.0);
+ }
+ function kilometersToMiles(miles) {
+ return miles * 0.621371;
+ }
+ var R = 6378.137;
+ var dLat = degreesToRadians(lat2-lat1);
+ var dLon = degreesToRadians(lon2-lon1);
+ var a = Math.sin(dLat/2) * Math.sin(dLat/2)
+ Math.cos(degreesToRadians(lat1)) * Math.cos(degreesToRadians(lat2))
* Math.sin(dLon/2) * Math.sin(dLon/2);
- var distance = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
-
- return isMetric ? distance : kilometersToMiles(distance);
- }
- for (var i = 0; i < 10000; i++) {
- var latFloat1 = parseFloat(faker.address.latitude());
- var lonFloat1 = parseFloat(faker.address.longitude());
- var radius = (Math.random() * 99) + 1; // range of [1, 100)
- var isMetric = (Math.round(Math.random()) == 1);
-
- var coordinate = faker.address.nearbyGPSCoordinate([latFloat1, lonFloat1], radius, isMetric);
- assert.ok(coordinate.length === 2);
- assert.ok(typeof coordinate[0] === 'string');
- assert.ok(typeof coordinate[1] === 'string');
-
- var latFloat2 = parseFloat(coordinate[0]);
- assert.ok(latFloat2 >= -90.0);
- assert.ok(latFloat2 <= 90.0);
-
- var lonFloat2 = parseFloat(coordinate[1]);
- assert.ok(lonFloat2 >= -180.0);
- assert.ok(lonFloat2 <= 180.0);
-
- // Due to floating point math, and constants that are not extremely precise,
- // returned points will not be strictly within the given radius of the input
- // coordinate. Using a error of 1.0 to compensate.
- var error = 1.0;
- var actualDistance = haversine(latFloat1, lonFloat1, latFloat2, lonFloat2, isMetric);
- assert.ok(actualDistance <= (radius + error));
- }
-
- // test once with undefined radius
- var coordinate = faker.address.nearbyGPSCoordinate([latFloat1, lonFloat1], undefined, isMetric);
- assert.ok(coordinate.length === 2);
- assert.ok(typeof coordinate[0] === 'string');
- assert.ok(typeof coordinate[1] === 'string');
-
- });
- });
-
- describe("timeZone()", function () {
- it("returns random timeZone", function () {
- sinon.spy(faker.address, 'timeZone');
- var timeZone = faker.address.timeZone();
- assert.ok(timeZone);
- assert.ok(faker.address.timeZone.called);
- faker.address.timeZone.restore();
- });
+ var distance = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+
+ return isMetric ? distance : kilometersToMiles(distance);
+ }
+ for (var i = 0; i < 10000; i++) {
+ var latFloat1 = parseFloat(faker.address.latitude());
+ var lonFloat1 = parseFloat(faker.address.longitude());
+ var radius = (Math.random() * 99) + 1; // range of [1, 100)
+ var isMetric = (Math.round(Math.random()) == 1);
+
+ var coordinate = faker.address.nearbyGPSCoordinate([latFloat1, lonFloat1], radius, isMetric);
+ assert.ok(coordinate.length === 2);
+ assert.ok(typeof coordinate[0] === 'string');
+ assert.ok(typeof coordinate[1] === 'string');
+
+ var latFloat2 = parseFloat(coordinate[0]);
+ assert.ok(latFloat2 >= -90.0);
+ assert.ok(latFloat2 <= 90.0);
+
+ var lonFloat2 = parseFloat(coordinate[1]);
+ assert.ok(lonFloat2 >= -180.0);
+ assert.ok(lonFloat2 <= 180.0);
+
+ // Due to floating point math, and constants that are not extremely precise,
+ // returned points will not be strictly within the given radius of the input
+ // coordinate. Using a error of 1.0 to compensate.
+ var error = 1.0;
+ var actualDistance = haversine(latFloat1, lonFloat1, latFloat2, lonFloat2, isMetric);
+ assert.ok(actualDistance <= (radius + error));
+ }
+
+ // test once with undefined radius
+ var coordinate = faker.address.nearbyGPSCoordinate([latFloat1, lonFloat1], undefined, isMetric);
+ assert.ok(coordinate.length === 2);
+ assert.ok(typeof coordinate[0] === 'string');
+ assert.ok(typeof coordinate[1] === 'string');
+
+ });
+ });
+
+ describe("timeZone()", function () {
+ it("returns random timeZone", function () {
+ sinon.spy(faker.address, 'timeZone');
+ var timeZone = faker.address.timeZone();
+ assert.ok(timeZone);
+ assert.ok(faker.address.timeZone.called);
+ faker.address.timeZone.restore();
});
+ });
});
diff --git a/test/all.functional.js b/test/all.functional.js
index 330a4c85..d2c3785e 100644
--- a/test/all.functional.js
+++ b/test/all.functional.js
@@ -1,7 +1,7 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
var functionalHelpers = require('./support/function-helpers.js');
@@ -12,18 +12,18 @@ 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);
- }
- });
- });
+ 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);
+ }
+ });
});
+ });
});
}
});
@@ -33,23 +33,23 @@ describe("faker.fake functional tests", function () {
faker.locale = locale;
faker.seed(1);
Object.keys(modules).forEach(function (module) {
- describe(module, function () {
- modules[module].forEach(function (meth) {
- it(meth + "()", function () {
- var result = faker.fake('{{' + module + '.' + meth + '}}');
- // just make sure any result is returned
- // an undefined result usually means an error
- assert.ok(typeof result !== 'undefined');
- /*
+ describe(module, function () {
+ modules[module].forEach(function (meth) {
+ it(meth + "()", function () {
+ var result = faker.fake('{{' + module + '.' + meth + '}}');
+ // just make sure any result is returned
+ // an undefined result usually means an error
+ assert.ok(typeof result !== 'undefined');
+ /*
if (meth === 'boolean') {
assert.ok(result === true || result === false);
} else {
assert.ok(result);
}
*/
- });
- });
+ });
});
+ });
});
}
}); \ No newline at end of file
diff --git a/test/animal.unit.js b/test/animal.unit.js
index 5f0e7506..1355be9a 100644
--- a/test/animal.unit.js
+++ b/test/animal.unit.js
@@ -7,9 +7,9 @@ if (typeof module !== 'undefined') {
describe("animal.js", function() {
describe("dog()", function() {
- it("returns random value from dog array", function() {
- var dog = faker.animal.dog();
- assert.ok(faker.definitions.animal.dog.indexOf(dog) !== -1);
- });
+ it("returns random value from dog array", function() {
+ var dog = faker.animal.dog();
+ assert.ok(faker.definitions.animal.dog.indexOf(dog) !== -1);
+ });
});
}); \ No newline at end of file
diff --git a/test/commerce.unit.js b/test/commerce.unit.js
index 61161e07..26b89a68 100644
--- a/test/commerce.unit.js
+++ b/test/commerce.unit.js
@@ -1,23 +1,23 @@
if (typeof module !== 'undefined') {
- var assert = require('assert'),
- sinon = require('sinon'),
- faker = require('../index');
+ var assert = require('assert'),
+ sinon = require('sinon'),
+ faker = require('../index');
}
describe("commerce.js", function() {
describe("color()", function() {
- it("returns random value from commerce.color array", function() {
- var color = faker.commerce.color();
- assert.ok(faker.definitions.commerce.color.indexOf(color) !== -1);
- });
+ it("returns random value from commerce.color array", function() {
+ var color = faker.commerce.color();
+ assert.ok(faker.definitions.commerce.color.indexOf(color) !== -1);
+ });
});
describe("department(max, fixedValue)", function() {
it("should use the default amounts when not passing arguments", function() {
- var department = faker.commerce.department();
- assert.ok(department.split(" ").length === 1);
+ var department = faker.commerce.department();
+ assert.ok(department.split(" ").length === 1);
});
/*
@@ -52,93 +52,93 @@ describe("commerce.js", function() {
});
describe("productName()", function() {
- it("returns name comprising of an adjective, material and product", function() {
- sinon.spy(faker.random, 'arrayElement');
- sinon.spy(faker.commerce, 'productAdjective');
- sinon.spy(faker.commerce, 'productMaterial');
- sinon.spy(faker.commerce, 'product');
- var name = faker.commerce.productName();
-
- assert.ok(name.split(' ').length >= 3);
- assert.ok(faker.random.arrayElement.calledThrice);
- assert.ok(faker.commerce.productAdjective.calledOnce);
- assert.ok(faker.commerce.productMaterial.calledOnce);
- assert.ok(faker.commerce.product.calledOnce);
-
- faker.random.arrayElement.restore();
- faker.commerce.productAdjective.restore();
- faker.commerce.productMaterial.restore();
- faker.commerce.product.restore();
- });
+ it("returns name comprising of an adjective, material and product", function() {
+ sinon.spy(faker.random, 'arrayElement');
+ sinon.spy(faker.commerce, 'productAdjective');
+ sinon.spy(faker.commerce, 'productMaterial');
+ sinon.spy(faker.commerce, 'product');
+ var name = faker.commerce.productName();
+
+ assert.ok(name.split(' ').length >= 3);
+ assert.ok(faker.random.arrayElement.calledThrice);
+ assert.ok(faker.commerce.productAdjective.calledOnce);
+ assert.ok(faker.commerce.productMaterial.calledOnce);
+ assert.ok(faker.commerce.product.calledOnce);
+
+ faker.random.arrayElement.restore();
+ faker.commerce.productAdjective.restore();
+ faker.commerce.productMaterial.restore();
+ faker.commerce.product.restore();
+ });
});
describe("price(min, max, dec, symbol)", function() {
it("should use the default amounts when not passing arguments", function() {
- var price = faker.commerce.price();
+ var price = faker.commerce.price();
- assert.ok(price);
- assert.strictEqual((price > 0), true, "the amount should be greater than 0");
- assert.strictEqual((price < 1001), true, "the amount should be less than 1000");
+ assert.ok(price);
+ assert.strictEqual((price > 0), true, "the amount should be greater than 0");
+ assert.strictEqual((price < 1001), true, "the amount should be less than 1000");
});
it("should use the default decimal location when not passing arguments", function() {
- var price = faker.commerce.price();
+ var price = faker.commerce.price();
- var decimal = ".";
- var expected = price.length - 3;
- var actual = price.indexOf(decimal);
+ var decimal = ".";
+ var expected = price.length - 3;
+ var actual = price.indexOf(decimal);
- assert.strictEqual(actual, expected, "The expected location of the decimal is " + expected + " but it was " + actual + " amount " + price);
+ assert.strictEqual(actual, expected, "The expected location of the decimal is " + expected + " but it was " + actual + " amount " + price);
});
it("should not include a currency symbol by default", function () {
- var amount = faker.commerce.price();
+ var amount = faker.commerce.price();
- var regexp = new RegExp(/[0-9.]/);
+ var regexp = new RegExp(/[0-9.]/);
- var expected = true;
- var actual = regexp.test(amount);
+ var expected = true;
+ var actual = regexp.test(amount);
- assert.strictEqual(actual, expected, 'The expected match should not include a currency symbol');
+ assert.strictEqual(actual, expected, 'The expected match should not include a currency symbol');
});
it("it should handle negative amounts, but return 0", function () {
- var amount = faker.commerce.price(-200, -1);
+ var amount = faker.commerce.price(-200, -1);
- assert.ok(amount);
- assert.strictEqual((amount == 0.00), true, "the amount should equal 0");
+ assert.ok(amount);
+ assert.strictEqual((amount == 0.00), true, "the amount should equal 0");
});
it("it should handle argument dec", function () {
- var price = faker.commerce.price(100, 100, 1);
+ var price = faker.commerce.price(100, 100, 1);
- assert.ok(price);
- assert.strictEqual(price , '100.0', "the price should be equal 100.0");
+ assert.ok(price);
+ assert.strictEqual(price , '100.0', "the price should be equal 100.0");
});
it("it should handle argument dec = 0", function () {
- var price = faker.commerce.price(100, 100, 0);
+ var price = faker.commerce.price(100, 100, 0);
- assert.ok(price);
- assert.strictEqual(price , '100', "the price should be equal 100");
+ assert.ok(price);
+ assert.strictEqual(price , '100', "the price should be equal 100");
});
});
describe("productDescription()", function() {
- it("returns a random product description", function() {
- sinon.spy(faker.commerce, 'productDescription');
- var description = faker.commerce.productDescription();
+ it("returns a random product description", function() {
+ sinon.spy(faker.commerce, 'productDescription');
+ var description = faker.commerce.productDescription();
- assert.ok(typeof description === 'string');
- assert.ok(faker.commerce.productDescription.calledOnce);
+ assert.ok(typeof description === 'string');
+ assert.ok(faker.commerce.productDescription.calledOnce);
- faker.commerce.productDescription.restore();
- });
- });
+ faker.commerce.productDescription.restore();
+ });
+ });
});
diff --git a/test/company.unit.js b/test/company.unit.js
index df8b5a2c..c22d42d8 100644
--- a/test/company.unit.js
+++ b/test/company.unit.js
@@ -1,101 +1,101 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("company.js", function () {
- describe("companyName()", function () {
-
- it("sometimes returns three last names", function () {
- sinon.spy(faker.name, 'lastName');
- sinon.stub(faker.datatype, 'number').returns(2);
- var name = faker.company.companyName();
- var parts = name.split(' ');
-
- assert.strictEqual(parts.length, 4); // account for word 'and'
- assert.ok(faker.name.lastName.calledThrice);
-
- faker.datatype.number.restore();
- faker.name.lastName.restore();
- });
-
- it("sometimes returns two last names separated by a hyphen", function () {
- sinon.spy(faker.name, 'lastName');
- sinon.stub(faker.datatype, 'number').returns(1);
- var name = faker.company.companyName();
- var parts = name.split('-');
-
- assert.ok(parts.length >= 2);
- assert.ok(faker.name.lastName.calledTwice);
-
- faker.datatype.number.restore();
- faker.name.lastName.restore();
- });
-
- it("sometimes returns a last name with a company suffix", function () {
- sinon.spy(faker.company, 'companySuffix');
- sinon.spy(faker.name, 'lastName');
- sinon.stub(faker.datatype, 'number').returns(0);
- var name = faker.company.companyName();
- var parts = name.split(' ');
-
- assert.ok(parts.length >= 2);
- assert.ok(faker.name.lastName.calledOnce);
- assert.ok(faker.company.companySuffix.calledOnce);
-
- faker.datatype.number.restore();
- faker.name.lastName.restore();
- faker.company.companySuffix.restore();
- });
+ describe("companyName()", function () {
+
+ it("sometimes returns three last names", function () {
+ sinon.spy(faker.name, 'lastName');
+ sinon.stub(faker.datatype, 'number').returns(2);
+ var name = faker.company.companyName();
+ var parts = name.split(' ');
+
+ assert.strictEqual(parts.length, 4); // account for word 'and'
+ assert.ok(faker.name.lastName.calledThrice);
+
+ faker.datatype.number.restore();
+ faker.name.lastName.restore();
});
- describe("companySuffix()", function () {
- it("returns random value from company.suffixes array", function () {
- var suffix = faker.company.companySuffix();
- assert.ok(faker.company.suffixes().indexOf(suffix) !== -1);
- });
+ it("sometimes returns two last names separated by a hyphen", function () {
+ sinon.spy(faker.name, 'lastName');
+ sinon.stub(faker.datatype, 'number').returns(1);
+ var name = faker.company.companyName();
+ var parts = name.split('-');
+
+ assert.ok(parts.length >= 2);
+ assert.ok(faker.name.lastName.calledTwice);
+
+ faker.datatype.number.restore();
+ faker.name.lastName.restore();
});
- describe("catchPhrase()", function () {
- it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
- sinon.spy(faker.random, 'arrayElement');
- sinon.spy(faker.company, 'catchPhraseAdjective');
- sinon.spy(faker.company, 'catchPhraseDescriptor');
- sinon.spy(faker.company, 'catchPhraseNoun');
- var phrase = faker.company.catchPhrase();
-
- assert.ok(phrase.split(' ').length >= 3);
- assert.ok(faker.random.arrayElement.calledThrice);
- assert.ok(faker.company.catchPhraseAdjective.calledOnce);
- assert.ok(faker.company.catchPhraseDescriptor.calledOnce);
- assert.ok(faker.company.catchPhraseNoun.calledOnce);
-
- faker.random.arrayElement.restore();
- faker.company.catchPhraseAdjective.restore();
- faker.company.catchPhraseDescriptor.restore();
- faker.company.catchPhraseNoun.restore();
- });
+ it("sometimes returns a last name with a company suffix", function () {
+ sinon.spy(faker.company, 'companySuffix');
+ sinon.spy(faker.name, 'lastName');
+ sinon.stub(faker.datatype, 'number').returns(0);
+ var name = faker.company.companyName();
+ var parts = name.split(' ');
+
+ assert.ok(parts.length >= 2);
+ assert.ok(faker.name.lastName.calledOnce);
+ assert.ok(faker.company.companySuffix.calledOnce);
+
+ faker.datatype.number.restore();
+ faker.name.lastName.restore();
+ faker.company.companySuffix.restore();
});
+ });
- describe("bs()", function () {
- it("returns phrase comprising of a BS buzz, adjective, and noun", function () {
- sinon.spy(faker.random, 'arrayElement');
- sinon.spy(faker.company, 'bsBuzz');
- sinon.spy(faker.company, 'bsAdjective');
- sinon.spy(faker.company, 'bsNoun');
- var bs = faker.company.bs();
-
- assert.ok(typeof bs === 'string');
- assert.ok(faker.random.arrayElement.calledThrice);
- assert.ok(faker.company.bsBuzz.calledOnce);
- assert.ok(faker.company.bsAdjective.calledOnce);
- assert.ok(faker.company.bsNoun.calledOnce);
-
- faker.random.arrayElement.restore();
- faker.company.bsBuzz.restore();
- faker.company.bsAdjective.restore();
- faker.company.bsNoun.restore();
- });
+ describe("companySuffix()", function () {
+ it("returns random value from company.suffixes array", function () {
+ var suffix = faker.company.companySuffix();
+ assert.ok(faker.company.suffixes().indexOf(suffix) !== -1);
+ });
+ });
+
+ describe("catchPhrase()", function () {
+ it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
+ sinon.spy(faker.random, 'arrayElement');
+ sinon.spy(faker.company, 'catchPhraseAdjective');
+ sinon.spy(faker.company, 'catchPhraseDescriptor');
+ sinon.spy(faker.company, 'catchPhraseNoun');
+ var phrase = faker.company.catchPhrase();
+
+ assert.ok(phrase.split(' ').length >= 3);
+ assert.ok(faker.random.arrayElement.calledThrice);
+ assert.ok(faker.company.catchPhraseAdjective.calledOnce);
+ assert.ok(faker.company.catchPhraseDescriptor.calledOnce);
+ assert.ok(faker.company.catchPhraseNoun.calledOnce);
+
+ faker.random.arrayElement.restore();
+ faker.company.catchPhraseAdjective.restore();
+ faker.company.catchPhraseDescriptor.restore();
+ faker.company.catchPhraseNoun.restore();
+ });
+ });
+
+ describe("bs()", function () {
+ it("returns phrase comprising of a BS buzz, adjective, and noun", function () {
+ sinon.spy(faker.random, 'arrayElement');
+ sinon.spy(faker.company, 'bsBuzz');
+ sinon.spy(faker.company, 'bsAdjective');
+ sinon.spy(faker.company, 'bsNoun');
+ var bs = faker.company.bs();
+
+ assert.ok(typeof bs === 'string');
+ assert.ok(faker.random.arrayElement.calledThrice);
+ assert.ok(faker.company.bsBuzz.calledOnce);
+ assert.ok(faker.company.bsAdjective.calledOnce);
+ assert.ok(faker.company.bsNoun.calledOnce);
+
+ faker.random.arrayElement.restore();
+ faker.company.bsBuzz.restore();
+ faker.company.bsAdjective.restore();
+ faker.company.bsNoun.restore();
});
+ });
});
diff --git a/test/database.unit.js b/test/database.unit.js
index b3955fea..9d1dbcb2 100644
--- a/test/database.unit.js
+++ b/test/database.unit.js
@@ -1,51 +1,51 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("database.js", function () {
- describe("column()", function () {
- it("returns a column name", function () {
- sinon.stub(faker.database, 'column').returns('title');
- var column = faker.database.column();
- var expected = 'title';
-
- assert.strictEqual(column, expected, "The column name should be equals " + expected + ". Current is " + column);
- faker.database.column.restore();
- });
+ describe("column()", function () {
+ it("returns a column name", function () {
+ sinon.stub(faker.database, 'column').returns('title');
+ var column = faker.database.column();
+ var expected = 'title';
+
+ assert.strictEqual(column, expected, "The column name should be equals " + expected + ". Current is " + column);
+ faker.database.column.restore();
});
+ });
- describe("collation()", function () {
- it("returns a collation", function () {
- sinon.stub(faker.database, 'collation').returns('utf8_bin');
- var collation = faker.database.collation();
- var expected = 'utf8_bin';
+ describe("collation()", function () {
+ it("returns a collation", function () {
+ sinon.stub(faker.database, 'collation').returns('utf8_bin');
+ var collation = faker.database.collation();
+ var expected = 'utf8_bin';
- assert.strictEqual(collation, expected, "The collation should be equals " + expected + ". Current is " + collation);
- faker.database.collation.restore();
- });
+ assert.strictEqual(collation, expected, "The collation should be equals " + expected + ". Current is " + collation);
+ faker.database.collation.restore();
});
+ });
- describe("engine()", function () {
- it("returns an engine", function () {
- sinon.stub(faker.database, 'engine').returns('InnoDB');
- var engine = faker.database.engine();
- var expected = 'InnoDB';
+ describe("engine()", function () {
+ it("returns an engine", function () {
+ sinon.stub(faker.database, 'engine').returns('InnoDB');
+ var engine = faker.database.engine();
+ var expected = 'InnoDB';
- assert.strictEqual(engine, expected, "The db engine should be equals " + expected + ". Current is " + engine);
- faker.database.engine.restore();
- });
+ assert.strictEqual(engine, expected, "The db engine should be equals " + expected + ". Current is " + engine);
+ faker.database.engine.restore();
});
+ });
- describe("type()", function () {
- it("returns a column type", function () {
- sinon.stub(faker.database, 'type').returns('int');
- var type = faker.database.type();
- var expected = 'int';
+ describe("type()", function () {
+ it("returns a column type", function () {
+ sinon.stub(faker.database, 'type').returns('int');
+ var type = faker.database.type();
+ var expected = 'int';
- assert.strictEqual(type, expected, "The column type should be equals " + expected + ". Current is " + type);
- faker.database.type.restore();
- });
+ assert.strictEqual(type, expected, "The column type should be equals " + expected + ". Current is " + type);
+ faker.database.type.restore();
});
+ });
});
diff --git a/test/datatype.unit.js b/test/datatype.unit.js
index 90c89391..b206ca47 100644
--- a/test/datatype.unit.js
+++ b/test/datatype.unit.js
@@ -1,289 +1,289 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var _ = require('lodash');
- var faker = require('../index');
- var mersenne = require('../vendor/mersenne');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var _ = require('lodash');
+ var faker = require('../index');
+ var mersenne = require('../vendor/mersenne');
}
describe("datatype.js", function () {
- describe("number", function () {
-
- it("returns a random number given a maximum value as Number", function () {
- var max = 10;
- assert.ok(faker.datatype.number(max) <= max);
- });
-
- it("returns a random number given a maximum value as Object", function () {
- var options = {max: 10};
- assert.ok(faker.datatype.number(options) <= options.max);
- });
-
- it("returns a random number given a maximum value of 0", function () {
- var options = {max: 0};
- assert.ok(faker.datatype.number(options) === 0);
- });
-
- it("returns a random number given a negative number minimum and maximum value of 0", function () {
- var options = {min: -100, max: 0};
- assert.ok(faker.datatype.number(options) <= options.max);
- });
-
- it("returns a random number between a range", function () {
- var options = {min: 22, max: 33};
- for (var i = 0; i < 100; i++) {
- var randomNumber = faker.datatype.number(options);
- assert.ok(randomNumber >= options.min);
- assert.ok(randomNumber <= options.max);
- }
- });
-
- it("provides numbers with a given precision", function () {
- var options = {min: 0, max: 1.5, precision: 0.5};
- var results = _.chain(_.range(50))
- .map(function () {
- return faker.datatype.number(options);
- })
- .uniq()
- .value()
- .sort();
-
- assert.ok(_.includes(results, 0.5));
- assert.ok(_.includes(results, 1.0));
-
- assert.strictEqual(results[0], 0);
- assert.strictEqual(_.last(results), 1.5);
-
- });
-
- it("provides numbers with a with exact precision", function () {
- var options = {min: 0.5, max: 0.99, precision: 0.01};
- for (var i = 0; i < 100; i++) {
- var number = faker.datatype.number(options);
- assert.strictEqual(number, Number(number.toFixed(2)));
- }
- });
-
- it("should not modify the input object", function () {
- var min = 1;
- var max = 2;
- var opts = {
- min: min,
- max: max
- };
-
- faker.datatype.number(opts);
-
- assert.strictEqual(opts.min, min);
- assert.strictEqual(opts.max, max);
- });
-
- });
-
- describe("float", function () {
-
- it("returns a random float with a default precision value (0.01)", function () {
- var number = faker.datatype.float();
- assert.strictEqual(number, Number(number.toFixed(2)));
- });
-
- it("returns a random float given a precision value", function () {
- var number = faker.datatype.float(0.001);
- assert.strictEqual(number, Number(number.toFixed(3)));
- });
-
- it("returns a random number given a maximum value as Object", function () {
- var options = {max: 10};
- assert.ok(faker.datatype.float(options) <= options.max);
- });
-
- it("returns a random number given a maximum value of 0", function () {
- var options = {max: 0};
- assert.ok(faker.datatype.float(options) === 0);
- });
-
- it("returns a random number given a negative number minimum and maximum value of 0", function () {
- var options = {min: -100, max: 0};
- assert.ok(faker.datatype.float(options) <= options.max);
- });
-
- it("returns a random number between a range", function () {
- var options = {min: 22, max: 33};
- for (var i = 0; i < 5; i++) {
- var randomNumber = faker.datatype.float(options);
- assert.ok(randomNumber >= options.min);
- assert.ok(randomNumber <= options.max);
- }
- });
-
- it("provides numbers with a given precision", function () {
- var options = {min: 0, max: 1.5, precision: 0.5};
- var results = _.chain(_.range(50))
- .map(function () {
- return faker.datatype.float(options);
- })
- .uniq()
- .value()
- .sort();
-
- assert.ok(_.includes(results, 0.5));
- assert.ok(_.includes(results, 1.0));
-
- assert.strictEqual(results[0], 0);
- assert.strictEqual(_.last(results), 1.5);
-
- });
-
- it("provides numbers with a with exact precision", function () {
- var options = {min: 0.5, max: 0.99, precision: 0.01};
- for (var i = 0; i < 100; i++) {
- var number = faker.datatype.float(options);
- assert.strictEqual(number, Number(number.toFixed(2)));
- }
- });
-
- it("should not modify the input object", function () {
- var min = 1;
- var max = 2;
- var opts = {
- min: min,
- max: max
- };
-
- faker.datatype.float(opts);
-
- assert.strictEqual(opts.min, min);
- assert.strictEqual(opts.max, max);
- });
- });
-
- describe('datetime', function () {
- it('check validity of date and if returned value is created by Date()', function () {
- var date = faker.datatype.datetime();
- assert.strictEqual(typeof date, 'object');
- assert.ok(!isNaN(date.getTime()));
- assert.strictEqual(Object.prototype.toString.call(date), "[object Date]");
- });
- it('basic test with stubed value', function () {
- var today = new Date();
- sinon.stub(faker.datatype, 'number').returns(today);
- var date = faker.datatype.datetime();
- assert.strictEqual(today.valueOf(), date.valueOf());
- faker.datatype.number.restore();
- });
-
- //generating a datetime with seeding is currently not working
- });
-
- describe('string', function () {
- it('should generate a string value', function () {
- var generateString = faker.datatype.string();
- assert.strictEqual(typeof generateString, 'string');
- assert.strictEqual(generateString.length, 10);
- });
-
- it('should generate a string value, checks seeding', function () {
- faker.seed(100);
- var generateString = faker.datatype.string();
- assert.strictEqual(generateString, 'S_:GHQo.!/');
- });
-
- it('returns empty string if negative length is passed', function () {
- var negativeValue = faker.datatype.number({min: -1000, max: -1});
- var generateString = faker.datatype.string(negativeValue);
- assert.strictEqual(generateString, '');
- assert.strictEqual(generateString.length, 0);
- });
-
- it('returns string with length of 2^20 if bigger length value is passed', function () {
- var overMaxValue = Math.pow(2, 28);
- var generateString = faker.datatype.string(overMaxValue);
- assert.strictEqual(generateString.length, (Math.pow(2, 20)));
- });
-
-
- });
-
- describe('boolean', function () {
- it('generates a boolean value', function () {
- var bool = faker.datatype.boolean();
- assert.strictEqual(typeof bool, 'boolean');
- });
- it('generates a boolean value, checks seeding', function (){
- faker.seed(1);
- var bool = faker.datatype.boolean();
- assert.strictEqual(bool, false);
- });
- });
-
- describe('UUID', function () {
- it('generates a valid UUID', function () {
- var UUID = faker.datatype.uuid();
- var RFC4122 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
- assert.ok(RFC4122.test(UUID));
- });
- });
-
- describe('hexaDecimal', function () {
- var hexaDecimal = faker.datatype.hexaDecimal;
-
- it('generates single hex character when no additional argument was provided', function () {
- var hex = hexaDecimal();
- assert.ok(hex.match(/^(0x)[0-9a-f]{1}$/i));
- });
-
- it('generates a random hex string', function () {
- var hex = hexaDecimal(5);
- assert.ok(hex.match(/^(0x)[0-9a-f]+$/i));
- });
- });
-
- describe('json', function () {
- it('generates a valid json object', function () {
- var jsonObject = faker.datatype.json();
- assert.strictEqual(typeof jsonObject, 'string');
- assert.ok(JSON.parse(jsonObject));
- });
-
- it('generates a valid json object, with seeding', function () {
- faker.seed(10);
- var jsonObject = faker.datatype.json();
- var parsedObject = JSON.parse(jsonObject);
- assert.strictEqual(typeof jsonObject, 'string');
- assert.strictEqual(parsedObject.foo, '<\"N[JfnOW5');
- assert.strictEqual(parsedObject.bar, 19806);
- assert.strictEqual(parsedObject.bike, 'g909).``yl');
- assert.strictEqual(parsedObject.a, 33607);
- assert.strictEqual(parsedObject.b, 'sl3Y#dr<dv');
- assert.strictEqual(parsedObject.name, 'c-SG.iCW_1');
- assert.strictEqual(parsedObject.prop, 82608);
- });
- });
-
- describe('array', function () {
- it('generates an array', function () {
- var stubArray = [0, 1, 3, 4, 5, 6, 1, 'a', 'b', 'c'];
- sinon.stub(faker.datatype, 'array').returns(stubArray);
- var generatedArray = faker.datatype.array();
- assert.strictEqual(generatedArray.length, stubArray.length);
- assert.strictEqual(stubArray, generatedArray);
- faker.datatype.array.restore();
-
- });
-
- it('generates an array with passed size', function () {
- var randomSize = faker.datatype.number();
- var generatedArray = faker.datatype.array(randomSize);
- assert.strictEqual(generatedArray.length, randomSize);
- });
-
- it('generates an array with 1 element, with seeding', function () {
- faker.seed(10);
- var generatedArray = faker.datatype.array(1);
- assert.strictEqual(generatedArray[0], '<"N[JfnOW5');
- });
+ describe("number", function () {
+
+ it("returns a random number given a maximum value as Number", function () {
+ var max = 10;
+ assert.ok(faker.datatype.number(max) <= max);
+ });
+
+ it("returns a random number given a maximum value as Object", function () {
+ var options = {max: 10};
+ assert.ok(faker.datatype.number(options) <= options.max);
+ });
+
+ it("returns a random number given a maximum value of 0", function () {
+ var options = {max: 0};
+ assert.ok(faker.datatype.number(options) === 0);
+ });
+
+ it("returns a random number given a negative number minimum and maximum value of 0", function () {
+ var options = {min: -100, max: 0};
+ assert.ok(faker.datatype.number(options) <= options.max);
+ });
+
+ it("returns a random number between a range", function () {
+ var options = {min: 22, max: 33};
+ for (var i = 0; i < 100; i++) {
+ var randomNumber = faker.datatype.number(options);
+ assert.ok(randomNumber >= options.min);
+ assert.ok(randomNumber <= options.max);
+ }
+ });
+
+ it("provides numbers with a given precision", function () {
+ var options = {min: 0, max: 1.5, precision: 0.5};
+ var results = _.chain(_.range(50))
+ .map(function () {
+ return faker.datatype.number(options);
+ })
+ .uniq()
+ .value()
+ .sort();
+
+ assert.ok(_.includes(results, 0.5));
+ assert.ok(_.includes(results, 1.0));
+
+ assert.strictEqual(results[0], 0);
+ assert.strictEqual(_.last(results), 1.5);
+
+ });
+
+ it("provides numbers with a with exact precision", function () {
+ var options = {min: 0.5, max: 0.99, precision: 0.01};
+ for (var i = 0; i < 100; i++) {
+ var number = faker.datatype.number(options);
+ assert.strictEqual(number, Number(number.toFixed(2)));
+ }
+ });
+
+ it("should not modify the input object", function () {
+ var min = 1;
+ var max = 2;
+ var opts = {
+ min: min,
+ max: max
+ };
+
+ faker.datatype.number(opts);
+
+ assert.strictEqual(opts.min, min);
+ assert.strictEqual(opts.max, max);
+ });
+
+ });
+
+ describe("float", function () {
+
+ it("returns a random float with a default precision value (0.01)", function () {
+ var number = faker.datatype.float();
+ assert.strictEqual(number, Number(number.toFixed(2)));
+ });
+
+ it("returns a random float given a precision value", function () {
+ var number = faker.datatype.float(0.001);
+ assert.strictEqual(number, Number(number.toFixed(3)));
+ });
+
+ it("returns a random number given a maximum value as Object", function () {
+ var options = {max: 10};
+ assert.ok(faker.datatype.float(options) <= options.max);
+ });
+
+ it("returns a random number given a maximum value of 0", function () {
+ var options = {max: 0};
+ assert.ok(faker.datatype.float(options) === 0);
+ });
+
+ it("returns a random number given a negative number minimum and maximum value of 0", function () {
+ var options = {min: -100, max: 0};
+ assert.ok(faker.datatype.float(options) <= options.max);
+ });
+
+ it("returns a random number between a range", function () {
+ var options = {min: 22, max: 33};
+ for (var i = 0; i < 5; i++) {
+ var randomNumber = faker.datatype.float(options);
+ assert.ok(randomNumber >= options.min);
+ assert.ok(randomNumber <= options.max);
+ }
+ });
+
+ it("provides numbers with a given precision", function () {
+ var options = {min: 0, max: 1.5, precision: 0.5};
+ var results = _.chain(_.range(50))
+ .map(function () {
+ return faker.datatype.float(options);
+ })
+ .uniq()
+ .value()
+ .sort();
+
+ assert.ok(_.includes(results, 0.5));
+ assert.ok(_.includes(results, 1.0));
+
+ assert.strictEqual(results[0], 0);
+ assert.strictEqual(_.last(results), 1.5);
+
+ });
+
+ it("provides numbers with a with exact precision", function () {
+ var options = {min: 0.5, max: 0.99, precision: 0.01};
+ for (var i = 0; i < 100; i++) {
+ var number = faker.datatype.float(options);
+ assert.strictEqual(number, Number(number.toFixed(2)));
+ }
+ });
+
+ it("should not modify the input object", function () {
+ var min = 1;
+ var max = 2;
+ var opts = {
+ min: min,
+ max: max
+ };
+
+ faker.datatype.float(opts);
+
+ assert.strictEqual(opts.min, min);
+ assert.strictEqual(opts.max, max);
+ });
+ });
+
+ describe('datetime', function () {
+ it('check validity of date and if returned value is created by Date()', function () {
+ var date = faker.datatype.datetime();
+ assert.strictEqual(typeof date, 'object');
+ assert.ok(!isNaN(date.getTime()));
+ assert.strictEqual(Object.prototype.toString.call(date), "[object Date]");
+ });
+ it('basic test with stubed value', function () {
+ var today = new Date();
+ sinon.stub(faker.datatype, 'number').returns(today);
+ var date = faker.datatype.datetime();
+ assert.strictEqual(today.valueOf(), date.valueOf());
+ faker.datatype.number.restore();
+ });
+
+ //generating a datetime with seeding is currently not working
+ });
+
+ describe('string', function () {
+ it('should generate a string value', function () {
+ var generateString = faker.datatype.string();
+ assert.strictEqual(typeof generateString, 'string');
+ assert.strictEqual(generateString.length, 10);
+ });
+
+ it('should generate a string value, checks seeding', function () {
+ faker.seed(100);
+ var generateString = faker.datatype.string();
+ assert.strictEqual(generateString, 'S_:GHQo.!/');
+ });
+
+ it('returns empty string if negative length is passed', function () {
+ var negativeValue = faker.datatype.number({min: -1000, max: -1});
+ var generateString = faker.datatype.string(negativeValue);
+ assert.strictEqual(generateString, '');
+ assert.strictEqual(generateString.length, 0);
+ });
+
+ it('returns string with length of 2^20 if bigger length value is passed', function () {
+ var overMaxValue = Math.pow(2, 28);
+ var generateString = faker.datatype.string(overMaxValue);
+ assert.strictEqual(generateString.length, (Math.pow(2, 20)));
+ });
+
+
+ });
+
+ describe('boolean', function () {
+ it('generates a boolean value', function () {
+ var bool = faker.datatype.boolean();
+ assert.strictEqual(typeof bool, 'boolean');
+ });
+ it('generates a boolean value, checks seeding', function (){
+ faker.seed(1);
+ var bool = faker.datatype.boolean();
+ assert.strictEqual(bool, false);
+ });
+ });
+
+ describe('UUID', function () {
+ it('generates a valid UUID', function () {
+ var UUID = faker.datatype.uuid();
+ var RFC4122 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
+ assert.ok(RFC4122.test(UUID));
+ });
+ });
+
+ describe('hexaDecimal', function () {
+ var hexaDecimal = faker.datatype.hexaDecimal;
+
+ it('generates single hex character when no additional argument was provided', function () {
+ var hex = hexaDecimal();
+ assert.ok(hex.match(/^(0x)[0-9a-f]{1}$/i));
+ });
+
+ it('generates a random hex string', function () {
+ var hex = hexaDecimal(5);
+ assert.ok(hex.match(/^(0x)[0-9a-f]+$/i));
+ });
+ });
+
+ describe('json', function () {
+ it('generates a valid json object', function () {
+ var jsonObject = faker.datatype.json();
+ assert.strictEqual(typeof jsonObject, 'string');
+ assert.ok(JSON.parse(jsonObject));
+ });
+
+ it('generates a valid json object, with seeding', function () {
+ faker.seed(10);
+ var jsonObject = faker.datatype.json();
+ var parsedObject = JSON.parse(jsonObject);
+ assert.strictEqual(typeof jsonObject, 'string');
+ assert.strictEqual(parsedObject.foo, '<\"N[JfnOW5');
+ assert.strictEqual(parsedObject.bar, 19806);
+ assert.strictEqual(parsedObject.bike, 'g909).``yl');
+ assert.strictEqual(parsedObject.a, 33607);
+ assert.strictEqual(parsedObject.b, 'sl3Y#dr<dv');
+ assert.strictEqual(parsedObject.name, 'c-SG.iCW_1');
+ assert.strictEqual(parsedObject.prop, 82608);
+ });
+ });
+
+ describe('array', function () {
+ it('generates an array', function () {
+ var stubArray = [0, 1, 3, 4, 5, 6, 1, 'a', 'b', 'c'];
+ sinon.stub(faker.datatype, 'array').returns(stubArray);
+ var generatedArray = faker.datatype.array();
+ assert.strictEqual(generatedArray.length, stubArray.length);
+ assert.strictEqual(stubArray, generatedArray);
+ faker.datatype.array.restore();
+
+ });
+
+ it('generates an array with passed size', function () {
+ var randomSize = faker.datatype.number();
+ var generatedArray = faker.datatype.array(randomSize);
+ assert.strictEqual(generatedArray.length, randomSize);
+ });
+
+ it('generates an array with 1 element, with seeding', function () {
+ faker.seed(10);
+ var generatedArray = faker.datatype.array(1);
+ assert.strictEqual(generatedArray[0], '<"N[JfnOW5');
});
+ });
}); \ No newline at end of file
diff --git a/test/date.unit.js b/test/date.unit.js
index c4569d54..1404bd4b 100644
--- a/test/date.unit.js
+++ b/test/date.unit.js
@@ -1,215 +1,215 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("date.js", function () {
- describe("past()", function () {
- it("returns a date N years into the past", function () {
+ describe("past()", function () {
+ it("returns a date N years into the past", function () {
- var date = faker.date.past(75);
- assert.ok(date < new Date());
- });
-
- it("returns a past date when N = 0", function () {
+ var date = faker.date.past(75);
+ assert.ok(date < new Date());
+ });
- var refDate = new Date();
- var date = faker.date.past(0, refDate.toJSON());
+ it("returns a past date when N = 0", function () {
- assert.ok(date < refDate); // date should be before the date given
- });
+ var refDate = new Date();
+ var date = faker.date.past(0, refDate.toJSON());
- it("returns a date N years before the date given", function () {
+ assert.ok(date < refDate); // date should be before the date given
+ });
- var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
+ it("returns a date N years before the date given", function () {
- var date = faker.date.past(75, refDate.toJSON());
+ var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
- assert.ok(date < refDate && date > new Date()); // date should be before date given but after the current time
- });
+ var date = faker.date.past(75, refDate.toJSON());
+ assert.ok(date < refDate && date > new Date()); // date should be before date given but after the current time
});
- describe("future()", function () {
- it("returns a date N years into the future", function () {
+ });
- var date = faker.date.future(75);
+ describe("future()", function () {
+ it("returns a date N years into the future", function () {
- assert.ok(date > new Date());
- });
+ var date = faker.date.future(75);
+
+ assert.ok(date > new Date());
+ });
- it("returns a future date when N = 0", function () {
+ it("returns a future date when N = 0", function () {
- var refDate = new Date();
- var date = faker.date.future(0, refDate.toJSON());
+ var refDate = new Date();
+ var date = faker.date.future(0, refDate.toJSON());
- assert.ok(date > refDate); // date should be after the date given
- });
+ assert.ok(date > refDate); // date should be after the date given
+ });
- it("returns a date N years after the date given", function () {
+ it("returns a date N years after the date given", function () {
- var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
+ var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
- var date = faker.date.future(75, refDate.toJSON());
+ var date = faker.date.future(75, refDate.toJSON());
- assert.ok(date > refDate && date < new Date()); // date should be after the date given, but before the current time
- });
+ assert.ok(date > refDate && date < new Date()); // date should be after the date given, but before the current time
});
+ });
- describe("recent()", function () {
- it("returns a date N days from the recent past", function () {
-
- var date = faker.date.recent(30);
+ describe("recent()", function () {
+ it("returns a date N days from the recent past", function () {
- assert.ok(date <= new Date());
- });
+ var date = faker.date.recent(30);
- it("returns a date N days from the recent past, starting from refDate", function () {
+ assert.ok(date <= new Date());
+ });
- var days = 30;
- var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
+ it("returns a date N days from the recent past, starting from refDate", function () {
- var date = faker.date.recent(days, refDate);
+ var days = 30;
+ var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
- var lowerBound = new Date(refDate.getTime() - (days * 24 * 60 * 60 * 1000));
+ var date = faker.date.recent(days, refDate);
- assert.ok(lowerBound <= date, "`recent()` date should not be further back than `n` days ago");
- assert.ok(date <= refDate, "`recent()` date should not be ahead of the starting date reference");
- });
+ var lowerBound = new Date(refDate.getTime() - (days * 24 * 60 * 60 * 1000));
+ assert.ok(lowerBound <= date, "`recent()` date should not be further back than `n` days ago");
+ assert.ok(date <= refDate, "`recent()` date should not be ahead of the starting date reference");
});
- describe("soon()", function () {
- it("returns a date N days into the future", function () {
+ });
- var date = faker.date.soon(30);
+ describe("soon()", function () {
+ it("returns a date N days into the future", function () {
- assert.ok(date >= new Date());
- });
+ var date = faker.date.soon(30);
- it("returns a date N days from the recent future, starting from refDate", function () {
+ assert.ok(date >= new Date());
+ });
- var days = 30;
- var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
+ it("returns a date N days from the recent future, starting from refDate", function () {
- var date = faker.date.soon(days, refDate);
+ var days = 30;
+ var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
- var upperBound = new Date(refDate.getTime() + (days * 24 * 60 * 60 * 1000));
+ var date = faker.date.soon(days, refDate);
- assert.ok(date <= upperBound, "`soon()` date should not be further ahead than `n` days ago");
- assert.ok(refDate <= date, "`soon()` date should not be behind the starting date reference");
- });
+ var upperBound = new Date(refDate.getTime() + (days * 24 * 60 * 60 * 1000));
+ assert.ok(date <= upperBound, "`soon()` date should not be further ahead than `n` days ago");
+ assert.ok(refDate <= date, "`soon()` date should not be behind the starting date reference");
});
- describe("between()", function () {
- it("returns a random date between the dates given", function () {
+ });
+
+ describe("between()", function () {
+ it("returns a random date between the dates given", function () {
- var from = new Date(1990, 5, 7, 9, 11, 0, 0);
- var to = new Date(2000, 6, 8, 10, 12, 0, 0);
+ var from = new Date(1990, 5, 7, 9, 11, 0, 0);
+ var to = new Date(2000, 6, 8, 10, 12, 0, 0);
- var date = faker.date.between(from, to);
+ var date = faker.date.between(from, to);
- assert.ok(date > from && date < to);
- });
+ assert.ok(date > from && date < to);
});
+ });
- describe("betweens()", function () {
- it("returns an array of 3 dates ( by default ) of sorted randoms dates between the dates given", function () {
+ describe("betweens()", function () {
+ it("returns an array of 3 dates ( by default ) of sorted randoms dates between the dates given", function () {
- var from = new Date(1990, 5, 7, 9, 11, 0, 0);
- var to = new Date(2000, 6, 8, 10, 12, 0, 0);
+ var from = new Date(1990, 5, 7, 9, 11, 0, 0);
+ var to = new Date(2000, 6, 8, 10, 12, 0, 0);
- var dates = faker.date.betweens(from, to );
+ var dates = faker.date.betweens(from, to );
- assert.ok(dates[0] > from && dates[0] < to);
- assert.ok(dates[1] > dates[0] && dates[2] > dates[1]);
- });
+ assert.ok(dates[0] > from && dates[0] < to);
+ assert.ok(dates[1] > dates[0] && dates[2] > dates[1]);
});
+ });
- describe("month()", function () {
- it("returns random value from date.month.wide array by default", function () {
- var month = faker.date.month();
- assert.ok(faker.definitions.date.month.wide.indexOf(month) !== -1);
- });
+ describe("month()", function () {
+ it("returns random value from date.month.wide array by default", function () {
+ var month = faker.date.month();
+ assert.ok(faker.definitions.date.month.wide.indexOf(month) !== -1);
+ });
- it("returns random value from date.month.wide_context array for context option", function () {
- var month = faker.date.month({ context: true });
- assert.ok(faker.definitions.date.month.wide_context.indexOf(month) !== -1);
- });
+ it("returns random value from date.month.wide_context array for context option", function () {
+ var month = faker.date.month({ context: true });
+ assert.ok(faker.definitions.date.month.wide_context.indexOf(month) !== -1);
+ });
- it("returns random value from date.month.abbr array for abbr option", function () {
- var month = faker.date.month({ abbr: true });
- assert.ok(faker.definitions.date.month.abbr.indexOf(month) !== -1);
- });
+ it("returns random value from date.month.abbr array for abbr option", function () {
+ var month = faker.date.month({ abbr: true });
+ assert.ok(faker.definitions.date.month.abbr.indexOf(month) !== -1);
+ });
- it("returns random value from date.month.abbr_context array for abbr and context option", function () {
- var month = faker.date.month({ abbr: true, context: true });
- assert.ok(faker.definitions.date.month.abbr_context.indexOf(month) !== -1);
- });
+ it("returns random value from date.month.abbr_context array for abbr and context option", function () {
+ var month = faker.date.month({ abbr: true, context: true });
+ assert.ok(faker.definitions.date.month.abbr_context.indexOf(month) !== -1);
+ });
- it("returns random value from date.month.wide array for context option when date.month.wide_context array is missing", function () {
- var backup_wide_context = faker.definitions.date.month.wide_context;
- faker.definitions.date.month.wide_context = undefined;
+ it("returns random value from date.month.wide array for context option when date.month.wide_context array is missing", function () {
+ var backup_wide_context = faker.definitions.date.month.wide_context;
+ faker.definitions.date.month.wide_context = undefined;
- var month = faker.date.month({ context: true });
- assert.ok(faker.definitions.date.month.wide.indexOf(month) !== -1);
+ var month = faker.date.month({ context: true });
+ assert.ok(faker.definitions.date.month.wide.indexOf(month) !== -1);
- faker.definitions.date.month.wide_context = backup_wide_context;
- });
+ faker.definitions.date.month.wide_context = backup_wide_context;
+ });
- it("returns random value from date.month.abbr array for abbr and context option when date.month.abbr_context array is missing", function () {
- var backup_abbr_context = faker.definitions.date.month.abbr_context;
- faker.definitions.date.month.abbr_context = undefined;
+ it("returns random value from date.month.abbr array for abbr and context option when date.month.abbr_context array is missing", function () {
+ var backup_abbr_context = faker.definitions.date.month.abbr_context;
+ faker.definitions.date.month.abbr_context = undefined;
- var month = faker.date.month({ abbr: true, context: true });
- assert.ok(faker.definitions.date.month.abbr.indexOf(month) !== -1);
+ var month = faker.date.month({ abbr: true, context: true });
+ assert.ok(faker.definitions.date.month.abbr.indexOf(month) !== -1);
- faker.definitions.date.month.abbr_context = backup_abbr_context;
- });
+ faker.definitions.date.month.abbr_context = backup_abbr_context;
});
+ });
- describe("weekday()", function () {
- it("returns random value from date.weekday.wide array by default", function () {
- var weekday = faker.date.weekday();
- assert.ok(faker.definitions.date.weekday.wide.indexOf(weekday) !== -1);
- });
+ describe("weekday()", function () {
+ it("returns random value from date.weekday.wide array by default", function () {
+ var weekday = faker.date.weekday();
+ assert.ok(faker.definitions.date.weekday.wide.indexOf(weekday) !== -1);
+ });
- it("returns random value from date.weekday.wide_context array for context option", function () {
- var weekday = faker.date.weekday({ context: true });
- assert.ok(faker.definitions.date.weekday.wide_context.indexOf(weekday) !== -1);
- });
+ it("returns random value from date.weekday.wide_context array for context option", function () {
+ var weekday = faker.date.weekday({ context: true });
+ assert.ok(faker.definitions.date.weekday.wide_context.indexOf(weekday) !== -1);
+ });
- it("returns random value from date.weekday.abbr array for abbr option", function () {
- var weekday = faker.date.weekday({ abbr: true });
- assert.ok(faker.definitions.date.weekday.abbr.indexOf(weekday) !== -1);
- });
+ it("returns random value from date.weekday.abbr array for abbr option", function () {
+ var weekday = faker.date.weekday({ abbr: true });
+ assert.ok(faker.definitions.date.weekday.abbr.indexOf(weekday) !== -1);
+ });
- it("returns random value from date.weekday.abbr_context array for abbr and context option", function () {
- var weekday = faker.date.weekday({ abbr: true, context: true });
- assert.ok(faker.definitions.date.weekday.abbr_context.indexOf(weekday) !== -1);
- });
+ it("returns random value from date.weekday.abbr_context array for abbr and context option", function () {
+ var weekday = faker.date.weekday({ abbr: true, context: true });
+ assert.ok(faker.definitions.date.weekday.abbr_context.indexOf(weekday) !== -1);
+ });
- it("returns random value from date.weekday.wide array for context option when date.weekday.wide_context array is missing", function () {
- var backup_wide_context = faker.definitions.date.weekday.wide_context;
- faker.definitions.date.weekday.wide_context = undefined;
+ it("returns random value from date.weekday.wide array for context option when date.weekday.wide_context array is missing", function () {
+ var backup_wide_context = faker.definitions.date.weekday.wide_context;
+ faker.definitions.date.weekday.wide_context = undefined;
- var weekday = faker.date.weekday({ context: true });
- assert.ok(faker.definitions.date.weekday.wide.indexOf(weekday) !== -1);
+ var weekday = faker.date.weekday({ context: true });
+ assert.ok(faker.definitions.date.weekday.wide.indexOf(weekday) !== -1);
- faker.definitions.date.weekday.wide_context = backup_wide_context;
- });
+ faker.definitions.date.weekday.wide_context = backup_wide_context;
+ });
- it("returns random value from date.weekday.abbr array for abbr and context option when date.weekday.abbr_context array is missing", function () {
- var backup_abbr_context = faker.definitions.date.weekday.abbr_context;
- faker.definitions.date.weekday.abbr_context = undefined;
+ it("returns random value from date.weekday.abbr array for abbr and context option when date.weekday.abbr_context array is missing", function () {
+ var backup_abbr_context = faker.definitions.date.weekday.abbr_context;
+ faker.definitions.date.weekday.abbr_context = undefined;
- var weekday = faker.date.weekday({ abbr: true, context: true });
- assert.ok(faker.definitions.date.weekday.abbr.indexOf(weekday) !== -1);
+ var weekday = faker.date.weekday({ abbr: true, context: true });
+ assert.ok(faker.definitions.date.weekday.abbr.indexOf(weekday) !== -1);
- faker.definitions.date.weekday.abbr_context = backup_abbr_context;
- });
+ faker.definitions.date.weekday.abbr_context = backup_abbr_context;
});
+ });
});
diff --git a/test/fake.unit.js b/test/fake.unit.js
index 6a802ec4..2ab6b4c0 100644
--- a/test/fake.unit.js
+++ b/test/fake.unit.js
@@ -1,51 +1,51 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("fake.js", function () {
- describe("fake()", function () {
- it("replaces a token with a random value for a method with no parameters", function () {
- var name = faker.fake('{{phone.phoneNumber}}');
- assert.ok(name.match(/\d/));
- });
-
- it("replaces multiple tokens with random values for methods with no parameters", function () {
- var name = faker.fake('{{helpers.randomize}}{{helpers.randomize}}{{helpers.randomize}}');
- assert.ok(name.match(/[abc]{3}/));
- });
-
- it("replaces a token with a random value for a methods with a simple parameter", function () {
- var arr = ["one", "two", "three"];
- var random = faker.fake('{{helpers.slugify("Will This Work")}}');
- assert.ok(random === "Will-This-Work");
- });
-
- it("replaces a token with a random value for a method with an array parameter", function () {
- var arr = ["one", "two", "three"];
- var random = faker.fake('{{helpers.randomize(["one", "two", "three"])}}');
- assert.ok(arr.indexOf(random) > -1);
- });
-
- it("does not allow undefined parameters", function () {
- assert.throws(function () {
- faker.fake()
- }, Error);
- });
-
- it("does not allow invalid module name", function () {
- assert.throws(function () {
- faker.fake('{{foo.bar}}')
- }, Error);
- });
-
- it("does not allow invalid method name", function () {
- assert.throws(function () {
- faker.fake('{{address.foo}}')
- }, Error);
- });
+ describe("fake()", function () {
+ it("replaces a token with a random value for a method with no parameters", function () {
+ var name = faker.fake('{{phone.phoneNumber}}');
+ assert.ok(name.match(/\d/));
+ });
+
+ it("replaces multiple tokens with random values for methods with no parameters", function () {
+ var name = faker.fake('{{helpers.randomize}}{{helpers.randomize}}{{helpers.randomize}}');
+ assert.ok(name.match(/[abc]{3}/));
+ });
+
+ it("replaces a token with a random value for a methods with a simple parameter", function () {
+ var arr = ["one", "two", "three"];
+ var random = faker.fake('{{helpers.slugify("Will This Work")}}');
+ assert.ok(random === "Will-This-Work");
+ });
+
+ it("replaces a token with a random value for a method with an array parameter", function () {
+ var arr = ["one", "two", "three"];
+ var random = faker.fake('{{helpers.randomize(["one", "two", "three"])}}');
+ assert.ok(arr.indexOf(random) > -1);
+ });
+
+ it("does not allow undefined parameters", function () {
+ assert.throws(function () {
+ faker.fake()
+ }, Error);
+ });
+ it("does not allow invalid module name", function () {
+ assert.throws(function () {
+ faker.fake('{{foo.bar}}')
+ }, Error);
+ });
+ it("does not allow invalid method name", function () {
+ assert.throws(function () {
+ faker.fake('{{address.foo}}')
+ }, Error);
});
+
+
+ });
});
diff --git a/test/finance_iban.unit.js b/test/finance_iban.unit.js
index 9ca3c465..c0412afc 100644
--- a/test/finance_iban.unit.js
+++ b/test/finance_iban.unit.js
@@ -1,65 +1,65 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var faker = require('../index');
+ var assert = require('assert');
+ var faker = require('../index');
}
function getAnIbanByCountry(countryCode) {
- var iban = faker.finance.iban();
- var maxTry = 100000;
- var countTry = maxTry;
- while (countTry && iban.substring(0, 2) != countryCode) {
- faker.seed(100000- countTry);
- iban = faker.finance.iban();
- countTry--;
- }
-
- if (countTry === 0) {
- console.log('Not found with 10000 seed, vraiment pas de bol');
- } else if (countTry < maxTry) {
- console.log('you can optimize this helper by add faker.seed(' + (100000 - 1 - countTry) + ') before the call of getAnIbanByCountry()');
- }
- // console.log(iban);
-
- return iban;
+ var iban = faker.finance.iban();
+ var maxTry = 100000;
+ var countTry = maxTry;
+ while (countTry && iban.substring(0, 2) != countryCode) {
+ faker.seed(100000- countTry);
+ iban = faker.finance.iban();
+ countTry--;
+ }
+
+ if (countTry === 0) {
+ console.log('Not found with 10000 seed, vraiment pas de bol');
+ } else if (countTry < maxTry) {
+ console.log('you can optimize this helper by add faker.seed(' + (100000 - 1 - countTry) + ') before the call of getAnIbanByCountry()');
+ }
+ // console.log(iban);
+
+ return iban;
}
describe('finance_iban.js', function () {
- describe("issue_944 IBAN Georgia", function () {
- // Georgia
- // https://transferwise.com/fr/iban/georgia
- // Length 22
- // BBAN 2c,16n
- // GEkk bbcc cccc cccc cccc cc
- // b = National bank code (alpha)
- // c = Account number
+ describe("issue_944 IBAN Georgia", function () {
+ // Georgia
+ // https://transferwise.com/fr/iban/georgia
+ // Length 22
+ // BBAN 2c,16n
+ // GEkk bbcc cccc cccc cccc cc
+ // b = National bank code (alpha)
+ // c = Account number
- // example IBAN GE29 NB00 0000 0101 9049 17
+ // example IBAN GE29 NB00 0000 0101 9049 17
- var ibanLib = require('../lib/iban');
+ var ibanLib = require('../lib/iban');
- it("IBAN for Georgia is correct", function () {
+ it("IBAN for Georgia is correct", function () {
- faker.seed(17);
- var iban = getAnIbanByCountry('GE');
- var ibanFormated = iban.match(/.{1,4}/g).join(" ");
- var bban = iban.substring(4) + iban.substring(0, 4);
+ faker.seed(17);
+ var iban = getAnIbanByCountry('GE');
+ var ibanFormated = iban.match(/.{1,4}/g).join(" ");
+ var bban = iban.substring(4) + iban.substring(0, 4);
- assert.equal(22, iban.length, 'GE IBAN would be 22 chars length, given is ' + iban.length);
+ assert.equal(22, iban.length, 'GE IBAN would be 22 chars length, given is ' + iban.length);
- assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in GE IBAN ' + ibanFormated);
- assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in GE IBAN ' + ibanFormated);
- assert.ok(iban.substring(4, 6).match(/^[A-Z]{2}$/), iban.substring(4, 6) + ' must contains only characters in GE IBAN ' + ibanFormated);
- assert.ok(iban.substring(6, 24).match(/^\d{16}$/), iban.substring(6, 24) + ' must contains only characters in GE IBAN ' + ibanFormated);
+ assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in GE IBAN ' + ibanFormated);
+ assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in GE IBAN ' + ibanFormated);
+ assert.ok(iban.substring(4, 6).match(/^[A-Z]{2}$/), iban.substring(4, 6) + ' must contains only characters in GE IBAN ' + ibanFormated);
+ assert.ok(iban.substring(6, 24).match(/^\d{16}$/), iban.substring(6, 24) + ' must contains only characters in GE IBAN ' + ibanFormated);
- assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
- });
+ assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
});
+ });
- describe("issue_945 IBAN Pakistan", function () {
+ describe("issue_945 IBAN Pakistan", function () {
// https://transferwise.com/fr/iban/pakistan
- // Example IBAN Pakistan
+ // Example IBAN Pakistan
// PK36SCBL0000001123456702
// IBAN en format imprimé
// PK36 SCBL 0000 0011 2345 6702
@@ -70,98 +70,98 @@ describe('finance_iban.js', function () {
// Account Code 16 digits
// Total Length 24 chars
- var ibanLib = require('../lib/iban');
+ var ibanLib = require('../lib/iban');
- it("IBAN for Pakistan is correct", function () {
+ it("IBAN for Pakistan is correct", function () {
- faker.seed(28);
- var iban = getAnIbanByCountry('PK');
- var ibanFormated = iban.match(/.{1,4}/g).join(" ");
- var bban = iban.substring(4) + iban.substring(0, 4);
+ faker.seed(28);
+ var iban = getAnIbanByCountry('PK');
+ var ibanFormated = iban.match(/.{1,4}/g).join(" ");
+ var bban = iban.substring(4) + iban.substring(0, 4);
- assert.equal(24, iban.length, 'PK IBAN would be 24 chars length, given is ' + iban.length);
+ assert.equal(24, iban.length, 'PK IBAN would be 24 chars length, given is ' + iban.length);
- assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(4, 8).match(/^[A-Z]{4}$/), iban.substring(4, 8) + ' must contains only characters in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(8, 24).match(/^\d{16}$/), iban.substring(8, 24) + ' must contains only digits in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(4, 8).match(/^[A-Z]{4}$/), iban.substring(4, 8) + ' must contains only characters in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(8, 24).match(/^\d{16}$/), iban.substring(8, 24) + ' must contains only digits in PK IBAN ' + ibanFormated);
- assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
- });
+ assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
});
+ });
- describe("issue_946 IBAN Turkish", function () {
+ describe("issue_946 IBAN Turkish", function () {
- // https://transferwise.com/fr/iban/turkey
- // Un IBAN en Turquie est constitué de 26 caractères :
- //
- // Code pays à 2 lettres
- // Clé de contrôle à 2 chiffres
- // 5 caractères du SWIFT/BIC de la banque
- // Code à 1 chiffres pour le code national
- // Code à 16 chiffres pour le numéro de compte bancaire
- // Vous avez déjà un code IBAN ?
- //
- // Exemple d'IBAN en Turquie TR330006100519786457841326
- // IBAN en format imprimé TR33 0006 1005 1978 6457 8413 26
- // Code pays TR
- // Clé de contrôle 33
- // Code banque 00061
- // Chiffre d'indicatif national 0
- // Numéro de compte bancaire 0519786457841326
+ // https://transferwise.com/fr/iban/turkey
+ // Un IBAN en Turquie est constitué de 26 caractères :
+ //
+ // Code pays à 2 lettres
+ // Clé de contrôle à 2 chiffres
+ // 5 caractères du SWIFT/BIC de la banque
+ // Code à 1 chiffres pour le code national
+ // Code à 16 chiffres pour le numéro de compte bancaire
+ // Vous avez déjà un code IBAN ?
+ //
+ // Exemple d'IBAN en Turquie TR330006100519786457841326
+ // IBAN en format imprimé TR33 0006 1005 1978 6457 8413 26
+ // Code pays TR
+ // Clé de contrôle 33
+ // Code banque 00061
+ // Chiffre d'indicatif national 0
+ // Numéro de compte bancaire 0519786457841326
- var ibanLib = require('../lib/iban');
+ var ibanLib = require('../lib/iban');
- it("IBAN for Turkish is correct", function () {
+ it("IBAN for Turkish is correct", function () {
- faker.seed(37);
+ faker.seed(37);
- var iban = getAnIbanByCountry('TR');
- var ibanFormated = iban.match(/.{1,4}/g).join(" ");
- var bban = iban.substring(4) + iban.substring(0, 4);
+ var iban = getAnIbanByCountry('TR');
+ var ibanFormated = iban.match(/.{1,4}/g).join(" ");
+ var bban = iban.substring(4) + iban.substring(0, 4);
- assert.equal(26, iban.length, 'PK IBAN would be 26 chars length, given is ' + iban.length);
+ assert.equal(26, iban.length, 'PK IBAN would be 26 chars length, given is ' + iban.length);
- assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), 'Country Code:' + iban.substring(0, 2) + ' must contains only characters in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(2, 4).match(/^\d{2}$/), 'Control key:' + iban.substring(2, 4) + ' must contains only digit in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(4, 9).match(/^\d{5}$/), 'Swift Bank Code:' + iban.substring(4, 9) + ' must contains only digits in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(9, 10).match(/^\d{1}$/), 'National Digit:' + iban.substring(9, 10) + ' must contains only digits in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(10, 26).match(/^\d{16}$/), 'Account Code:' + iban.substring(10, 26) + ' must contains only digits in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), 'Country Code:' + iban.substring(0, 2) + ' must contains only characters in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(2, 4).match(/^\d{2}$/), 'Control key:' + iban.substring(2, 4) + ' must contains only digit in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(4, 9).match(/^\d{5}$/), 'Swift Bank Code:' + iban.substring(4, 9) + ' must contains only digits in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(9, 10).match(/^\d{1}$/), 'National Digit:' + iban.substring(9, 10) + ' must contains only digits in PK IBAN ' + ibanFormated);
+ assert.ok(iban.substring(10, 26).match(/^\d{16}$/), 'Account Code:' + iban.substring(10, 26) + ' must contains only digits in PK IBAN ' + ibanFormated);
- assert.ok(iban.substring(2, 26).match(/^\d{24}$/), 'No character after TR ' + ibanFormated);
+ assert.ok(iban.substring(2, 26).match(/^\d{24}$/), 'No character after TR ' + ibanFormated);
- assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
- });
+ assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
});
+ });
- describe("issue_846 IBAN Azerbaijan", function () {
- // Azerbaijan
- // https://transferwise.com/fr/iban/azerbaijan
- // Length 28
- // BBAN 4c,20n
- // GEkk bbbb cccc cccc cccc cccc cccc
- // b = National bank code (alpha)
- // c = Account number
+ describe("issue_846 IBAN Azerbaijan", function () {
+ // Azerbaijan
+ // https://transferwise.com/fr/iban/azerbaijan
+ // Length 28
+ // BBAN 4c,20n
+ // GEkk bbbb cccc cccc cccc cccc cccc
+ // b = National bank code (alpha)
+ // c = Account number
- // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944
+ // example IBAN AZ21 NABZ 0000 0000 1370 1000 1944
- var ibanLib = require('../lib/iban');
+ var ibanLib = require('../lib/iban');
- it("IBAN for Azerbaijan is correct", function () {
+ it("IBAN for Azerbaijan is correct", function () {
- faker.seed(21);
- var iban = getAnIbanByCountry('AZ');
- var ibanFormated = iban.match(/.{1,4}/g).join(" ");
- var bban = iban.substring(4) + iban.substring(0, 4);
+ faker.seed(21);
+ var iban = getAnIbanByCountry('AZ');
+ var ibanFormated = iban.match(/.{1,4}/g).join(" ");
+ var bban = iban.substring(4) + iban.substring(0, 4);
- assert.equal(28, iban.length, 'AZ IBAN would be 28 chars length, given is ' + iban.length);
+ assert.equal(28, iban.length, 'AZ IBAN would be 28 chars length, given is ' + iban.length);
- assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in AZ IBAN ' + ibanFormated);
- assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in AZ IBAN ' + ibanFormated);
- assert.ok(iban.substring(4, 8).match(/^[A-Z]{4}$/), iban.substring(4, 8) + ' must contains only characters in AZ IBAN ' + ibanFormated);
- assert.ok(iban.substring(8, 28).match(/^\d{20}$/), iban.substring(8, 28) + ' must contains 20 characters in AZ IBAN ' + ibanFormated);
+ assert.ok(iban.substring(0, 2).match(/^[A-Z]{2}$/), iban.substring(0, 2) + ' must contains only characters in AZ IBAN ' + ibanFormated);
+ assert.ok(iban.substring(2, 4).match(/^\d{2}$/), iban.substring(2, 4) + ' must contains only digit in AZ IBAN ' + ibanFormated);
+ assert.ok(iban.substring(4, 8).match(/^[A-Z]{4}$/), iban.substring(4, 8) + ' must contains only characters in AZ IBAN ' + ibanFormated);
+ assert.ok(iban.substring(8, 28).match(/^\d{20}$/), iban.substring(8, 28) + ' must contains 20 characters in AZ IBAN ' + ibanFormated);
- assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
- });
+ assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
});
});
+});
diff --git a/test/helpers.unit.js b/test/helpers.unit.js
index 7436da03..ec32dd02 100644
--- a/test/helpers.unit.js
+++ b/test/helpers.unit.js
@@ -1,89 +1,89 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("helpers.js", function () {
- describe("replaceSymbolWithNumber()", function () {
- context("when no symbol passed in", function () {
- it("uses '#' by default", function () {
- var num = faker.helpers.replaceSymbolWithNumber('#AB');
- assert.ok(num.match(/\dAB/));
- });
- });
+ describe("replaceSymbolWithNumber()", function () {
+ context("when no symbol passed in", function () {
+ it("uses '#' by default", function () {
+ var num = faker.helpers.replaceSymbolWithNumber('#AB');
+ assert.ok(num.match(/\dAB/));
+ });
+ });
- context("when symbol passed in", function () {
- it("replaces that symbol with integers", function () {
- var num = faker.helpers.replaceSymbolWithNumber('#AB', 'A');
- assert.ok(num.match(/#\dB/));
- });
- });
+ context("when symbol passed in", function () {
+ it("replaces that symbol with integers", function () {
+ var num = faker.helpers.replaceSymbolWithNumber('#AB', 'A');
+ assert.ok(num.match(/#\dB/));
+ });
});
+ });
- describe("replaceSymbols()", function () {
- context("when '*' passed", function () {
- it("replaces it with alphanumeric", function(){
- var num = faker.helpers.replaceSymbols('*AB');
- assert.ok(num.match(/\wAB/));
- });
- });
+ describe("replaceSymbols()", function () {
+ context("when '*' passed", function () {
+ it("replaces it with alphanumeric", function(){
+ var num = faker.helpers.replaceSymbols('*AB');
+ assert.ok(num.match(/\wAB/));
+ });
});
+ });
- describe("shuffle()", function () {
- it("the output is the same length as the input", function () {
- sinon.spy(faker.datatype, 'number');
- var shuffled = faker.helpers.shuffle(["a", "b"]);
- assert.ok(shuffled.length === 2);
- assert.ok(faker.datatype.number.calledWith(1));
- faker.datatype.number.restore();
- });
+ describe("shuffle()", function () {
+ it("the output is the same length as the input", function () {
+ sinon.spy(faker.datatype, 'number');
+ var shuffled = faker.helpers.shuffle(["a", "b"]);
+ assert.ok(shuffled.length === 2);
+ assert.ok(faker.datatype.number.calledWith(1));
+ faker.datatype.number.restore();
+ });
- it("empty array returns empty array", function () {
- var shuffled = faker.helpers.shuffle([]);
- assert.ok(shuffled.length === 0);
- });
+ it("empty array returns empty array", function () {
+ var shuffled = faker.helpers.shuffle([]);
+ assert.ok(shuffled.length === 0);
+ });
- it("mutates the input array in place", function () {
- var input = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
- var shuffled = faker.helpers.shuffle(input);
- assert.deepStrictEqual(shuffled, input);
- });
+ it("mutates the input array in place", function () {
+ var input = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
+ var shuffled = faker.helpers.shuffle(input);
+ assert.deepStrictEqual(shuffled, input);
+ });
- it("all items shuffled as expected when seeded", function () {
- var input = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
- faker.seed(100);
- var shuffled = faker.helpers.shuffle(input);
- assert.deepStrictEqual(shuffled, ["b", "e", "a", "d", "j", "i", "h", "c", "g", "f"]);
- });
+ it("all items shuffled as expected when seeded", function () {
+ var input = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
+ faker.seed(100);
+ var shuffled = faker.helpers.shuffle(input);
+ assert.deepStrictEqual(shuffled, ["b", "e", "a", "d", "j", "i", "h", "c", "g", "f"]);
});
+ });
- describe("slugify()", function () {
- it("removes unwanted characters from URI string", function () {
- assert.strictEqual(faker.helpers.slugify("Aiden.Harªann"), "Aiden.Harann");
- assert.strictEqual(faker.helpers.slugify("d'angelo.net"), "dangelo.net");
- });
+ describe("slugify()", function () {
+ it("removes unwanted characters from URI string", function () {
+ assert.strictEqual(faker.helpers.slugify("Aiden.Harªann"), "Aiden.Harann");
+ assert.strictEqual(faker.helpers.slugify("d'angelo.net"), "dangelo.net");
});
+ });
- describe("mustache()", function () {
- it("returns empty string with no arguments", function () {
- assert.strictEqual(faker.helpers.mustache(), "");
- });
+ describe("mustache()", function () {
+ it("returns empty string with no arguments", function () {
+ assert.strictEqual(faker.helpers.mustache(), "");
});
+ });
- describe("repeatString()", function () {
- it("returns empty string with no arguments", function () {
- assert.strictEqual(faker.helpers.repeatString(), "");
- });
+ describe("repeatString()", function () {
+ it("returns empty string with no arguments", function () {
+ assert.strictEqual(faker.helpers.repeatString(), "");
});
+ });
- describe("replaceSymbols()", function () {
- it("returns empty string with no arguments", function () {
- assert.strictEqual(faker.helpers.replaceSymbols(), "");
- });
+ describe("replaceSymbols()", function () {
+ it("returns empty string with no arguments", function () {
+ assert.strictEqual(faker.helpers.replaceSymbols(), "");
});
+ });
- /*
+ /*
describe("replaceCreditCardSymbols()", function () {
it("returns empty string with no arguments", function () {
assert.equal(faker.helpers.replaceCreditCardSymbols(), "");
@@ -91,87 +91,87 @@ describe("helpers.js", function () {
});
*/
- describe("createCard()", function () {
- it("returns an object", function () {
- var card = faker.helpers.createCard();
- assert.ok(typeof card === 'object');
- });
+ describe("createCard()", function () {
+ it("returns an object", function () {
+ var card = faker.helpers.createCard();
+ assert.ok(typeof card === 'object');
});
+ });
- describe("contextualCard()", function () {
- it("returns an object", function () {
- var card = faker.helpers.contextualCard();
- assert.ok(typeof card === 'object');
- });
+ describe("contextualCard()", function () {
+ it("returns an object", function () {
+ var card = faker.helpers.contextualCard();
+ assert.ok(typeof card === 'object');
});
+ });
- describe("userCard()", function () {
- it("returns an object", function () {
- var card = faker.helpers.userCard();
- assert.ok(typeof card === 'object');
- });
+ describe("userCard()", function () {
+ it("returns an object", function () {
+ var card = faker.helpers.userCard();
+ assert.ok(typeof card === 'object');
});
+ });
- // Make sure we keep this function for backward-compatibility.
- describe("randomize()", function () {
- it("returns a random element from an array", function () {
- var arr = ['a', 'b', 'c'];
- var elem = faker.helpers.randomize(arr);
- assert.ok(elem);
- assert.ok(arr.indexOf(elem) !== -1);
- });
+ // Make sure we keep this function for backward-compatibility.
+ describe("randomize()", function () {
+ it("returns a random element from an array", function () {
+ var arr = ['a', 'b', 'c'];
+ var elem = faker.helpers.randomize(arr);
+ assert.ok(elem);
+ assert.ok(arr.indexOf(elem) !== -1);
});
+ });
- describe("replaceCreditCardSymbols()", function () {
- var luhnCheck = require("./support/luhnCheck.js");
- it("returns a credit card number given a schema", function () {
- var number = faker.helpers.replaceCreditCardSymbols("6453-####-####-####-###L");
- assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
- assert.ok(luhnCheck(number));
- });
- it("supports different symbols", function () {
- var number = faker.helpers.replaceCreditCardSymbols("6453-****-****-****-***L","*");
- assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
- assert.ok(luhnCheck(number));
- });
- it("handles regexp style input", function () {
- var number = faker.helpers.replaceCreditCardSymbols("6453-*{4}-*{4}-*{4}-*{3}L","*");
- assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
- assert.ok(luhnCheck(number));
- number = faker.helpers.replaceCreditCardSymbols("645[5-9]-#{4,6}-#{1,2}-#{4,6}-#{3}L");
- assert.ok(number.match(/^645[5-9]\-([0-9]){4,6}\-([0-9]){1,2}\-([0-9]){4,6}\-([0-9]){4}$/));
- assert.ok(luhnCheck(number));
- });
+ describe("replaceCreditCardSymbols()", function () {
+ var luhnCheck = require("./support/luhnCheck.js");
+ it("returns a credit card number given a schema", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-####-####-####-###L");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ });
+ it("supports different symbols", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-****-****-****-***L","*");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ });
+ it("handles regexp style input", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-*{4}-*{4}-*{4}-*{3}L","*");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ number = faker.helpers.replaceCreditCardSymbols("645[5-9]-#{4,6}-#{1,2}-#{4,6}-#{3}L");
+ assert.ok(number.match(/^645[5-9]\-([0-9]){4,6}\-([0-9]){1,2}\-([0-9]){4,6}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
});
+ });
- describe("regexpStyleStringParse()", function () {
- it("returns an empty string when called without param", function () {
- assert.ok(faker.helpers.regexpStyleStringParse() === "");
- });
- it("deals with range repeat", function () {
- var string = faker.helpers.regexpStyleStringParse("#{5,10}");
- assert.ok(string.length <= 10 && string.length >= 5);
- assert.ok(string.match(/^\#{5,10}$/));
- });
- it("flips the range when min > max", function () {
- var string = faker.helpers.regexpStyleStringParse("#{10,5}");
- assert.ok(string.length <= 10 && string.length >= 5);
- assert.ok(string.match(/^\#{5,10}$/));
- });
- it("repeats string {n} number of times", function () {
- assert.ok(faker.helpers.regexpStyleStringParse("%{10}") === faker.helpers.repeatString("%",10));
- assert.ok(faker.helpers.regexpStyleStringParse("%{30}") === faker.helpers.repeatString("%",30));
- assert.ok(faker.helpers.regexpStyleStringParse("%{5}") === faker.helpers.repeatString("%",5));
- });
- it("creates a numerical range", function () {
- var string = faker.helpers.regexpStyleStringParse("Hello[0-9]");
- assert.ok(string.match(/^Hello[0-9]$/));
- });
- it("deals with multiple tokens in one string", function () {
- var string = faker.helpers.regexpStyleStringParse("Test#{5}%{2,5}Testing**[1-5]**{10}END");
- assert.ok(string.match(/^Test\#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/));
- });
+ describe("regexpStyleStringParse()", function () {
+ it("returns an empty string when called without param", function () {
+ assert.ok(faker.helpers.regexpStyleStringParse() === "");
});
+ it("deals with range repeat", function () {
+ var string = faker.helpers.regexpStyleStringParse("#{5,10}");
+ assert.ok(string.length <= 10 && string.length >= 5);
+ assert.ok(string.match(/^\#{5,10}$/));
+ });
+ it("flips the range when min > max", function () {
+ var string = faker.helpers.regexpStyleStringParse("#{10,5}");
+ assert.ok(string.length <= 10 && string.length >= 5);
+ assert.ok(string.match(/^\#{5,10}$/));
+ });
+ it("repeats string {n} number of times", function () {
+ assert.ok(faker.helpers.regexpStyleStringParse("%{10}") === faker.helpers.repeatString("%",10));
+ assert.ok(faker.helpers.regexpStyleStringParse("%{30}") === faker.helpers.repeatString("%",30));
+ assert.ok(faker.helpers.regexpStyleStringParse("%{5}") === faker.helpers.repeatString("%",5));
+ });
+ it("creates a numerical range", function () {
+ var string = faker.helpers.regexpStyleStringParse("Hello[0-9]");
+ assert.ok(string.match(/^Hello[0-9]$/));
+ });
+ it("deals with multiple tokens in one string", function () {
+ var string = faker.helpers.regexpStyleStringParse("Test#{5}%{2,5}Testing**[1-5]**{10}END");
+ assert.ok(string.match(/^Test\#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/));
+ });
+ });
describe("createTransaction()", function() {
it("should create a random transaction", function() {
diff --git a/test/image.unit.js b/test/image.unit.js
index 66664b9e..d482880a 100644
--- a/test/image.unit.js
+++ b/test/image.unit.js
@@ -1,257 +1,257 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("image.js", function () {
- describe("lorempicsum", function() {
- describe("imageUrl()", function () {
- it("returns a random image url from lorempixel", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl();
+ describe("lorempicsum", function() {
+ describe("imageUrl()", function () {
+ it("returns a random image url from lorempixel", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl();
- assert.strictEqual(imageUrl, 'https://picsum.photos/640/480');
- });
- it("returns a random image url from lorem picsum with width and height", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl(100, 100);
+ assert.strictEqual(imageUrl, 'https://picsum.photos/640/480');
+ });
+ it("returns a random image url from lorem picsum with width and height", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100');
- });
- it("returns a random image url grayscaled", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true);
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100');
+ });
+ it("returns a random image url grayscaled", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale');
- });
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale');
+ });
- it("returns a random image url grayscaled and blurred", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true, 2);
+ it("returns a random image url grayscaled and blurred", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true, 2);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale&blur=2');
- });
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale&blur=2');
+ });
- it("returns a random image url blurred", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, undefined, 2);
+ it("returns a random image url blurred", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, undefined, 2);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?blur=2');
- });
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?blur=2');
+ });
- it("returns a random image url with seed", function () {
- var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, undefined, undefined, 'picsum');
+ it("returns a random image url with seed", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, undefined, undefined, 'picsum');
- assert.strictEqual(imageUrl, 'https://picsum.photos/seed/picsum/100/100');
- });
- });
- describe("avatar()", function () {
- it("return a random avatar from FakerCloud", function () {
- assert.notStrictEqual(-1, faker.image.lorempicsum.avatar().indexOf('cdn.fakercloud.com/avatars'));
- })
- });
+ assert.strictEqual(imageUrl, 'https://picsum.photos/seed/picsum/100/100');
+ });
+ });
+ describe("avatar()", function () {
+ it("return a random avatar from FakerCloud", function () {
+ assert.notStrictEqual(-1, faker.image.lorempicsum.avatar().indexOf('cdn.fakercloud.com/avatars'));
+ })
+ });
- describe("imageGrayscale()", function () {
- it("returns a random URL with grayscale image", function () {
- var imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);
+ describe("imageGrayscale()", function () {
+ it("returns a random URL with grayscale image", function () {
+ var imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale');
- });
- });
- describe("imageBlurred()", function () {
- it("returns a random image url blurred", function () {
- var imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2);
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?grayscale');
+ });
+ });
+ describe("imageBlurred()", function () {
+ it("returns a random image url blurred", function () {
+ var imageUrl = faker.image.lorempicsum.imageBlurred(100, 100, 2);
- assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?blur=2');
- });
- });
- describe("imageRandomSeeded()", function () {
- it("returns a random image url blurred", function () {
- var imageUrl = faker.image.lorempicsum.imageRandomSeeded(100, 100, undefined, undefined, 'picsum');
+ assert.strictEqual(imageUrl, 'https://picsum.photos/100/100?blur=2');
+ });
+ });
+ describe("imageRandomSeeded()", function () {
+ it("returns a random image url blurred", function () {
+ var imageUrl = faker.image.lorempicsum.imageRandomSeeded(100, 100, undefined, undefined, 'picsum');
- assert.strictEqual(imageUrl, 'https://picsum.photos/seed/picsum/100/100');
- });
- });
+ assert.strictEqual(imageUrl, 'https://picsum.photos/seed/picsum/100/100');
+ });
});
+ });
- describe("lorempixel", function() {
- describe("imageUrl()", function () {
- it("returns a random image url from lorempixel", function () {
- var imageUrl = faker.image.lorempixel.imageUrl();
+ describe("lorempixel", function() {
+ describe("imageUrl()", function () {
+ it("returns a random image url from lorempixel", function () {
+ var imageUrl = faker.image.lorempixel.imageUrl();
- assert.strictEqual(imageUrl, 'https://lorempixel.com/640/480');
- });
- it("returns a random image url from lorempixel with width and height", function () {
- var imageUrl = faker.image.lorempixel.imageUrl(100, 100);
+ assert.strictEqual(imageUrl, 'https://lorempixel.com/640/480');
+ });
+ it("returns a random image url from lorempixel with width and height", function () {
+ var imageUrl = faker.image.lorempixel.imageUrl(100, 100);
- assert.strictEqual(imageUrl, 'https://lorempixel.com/100/100');
- });
- it("returns a random image url for a specified category", function () {
- var imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract');
+ assert.strictEqual(imageUrl, 'https://lorempixel.com/100/100');
+ });
+ it("returns a random image url for a specified category", function () {
+ var imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract');
- assert.strictEqual(imageUrl, 'https://lorempixel.com/100/100/abstract');
- });
- });
- describe("avatar()", function () {
- it("return a random avatar from FakerCloud", function () {
- assert.notStrictEqual(-1, faker.image.lorempixel.avatar().indexOf('cdn.fakercloud.com/avatars'));
- })
- });
- describe("abstract()", function () {
- it("returns a random abstract image url", function () {
- var abstract = faker.image.lorempixel.abstract();
- assert.strictEqual(abstract, 'https://lorempixel.com/640/480/abstract');
- });
- });
- describe("animals()", function () {
- it("returns a random animals image url", function () {
- var animals = faker.image.lorempixel.animals();
- assert.strictEqual(animals, 'https://lorempixel.com/640/480/animals');
- });
- });
- describe("business()", function () {
- it("returns a random business image url", function () {
- var business = faker.image.lorempixel.business();
- assert.strictEqual(business, 'https://lorempixel.com/640/480/business');
- });
- });
- describe("cats()", function () {
- it("returns a random cats image url", function () {
- var cats = faker.image.lorempixel.cats();
- assert.strictEqual(cats, 'https://lorempixel.com/640/480/cats');
- });
- });
- describe("city()", function () {
- it("returns a random city image url", function () {
- var city = faker.image.lorempixel.city();
- assert.strictEqual(city, 'https://lorempixel.com/640/480/city');
- });
- });
- describe("food()", function () {
- it("returns a random food image url", function () {
- var food = faker.image.lorempixel.food();
- assert.strictEqual(food, 'https://lorempixel.com/640/480/food');
- });
- });
- describe("nightlife()", function () {
- it("returns a random nightlife image url", function () {
- var nightlife = faker.image.lorempixel.nightlife();
- assert.strictEqual(nightlife, 'https://lorempixel.com/640/480/nightlife');
- });
- });
- describe("fashion()", function () {
- it("returns a random fashion image url", function () {
- var fashion = faker.image.lorempixel.fashion();
- assert.strictEqual(fashion, 'https://lorempixel.com/640/480/fashion');
- });
- });
- describe("people()", function () {
- it("returns a random people image url", function () {
- var people = faker.image.lorempixel.people();
- assert.strictEqual(people, 'https://lorempixel.com/640/480/people');
- });
- });
- describe("nature()", function () {
- it("returns a random nature image url", function () {
- var nature = faker.image.lorempixel.nature();
- assert.strictEqual(nature, 'https://lorempixel.com/640/480/nature');
- });
- });
- describe("sports()", function () {
- it("returns a random sports image url", function () {
- var sports = faker.image.lorempixel.sports();
- assert.strictEqual(sports, 'https://lorempixel.com/640/480/sports');
- });
- });
- describe("technics()", function () {
- it("returns a random technics image url", function () {
- var technics = faker.image.lorempixel.technics();
- assert.strictEqual(technics, 'https://lorempixel.com/640/480/technics');
- });
- });
- describe("transport()", function () {
- it("returns a random transport image url", function () {
- var transport = faker.image.lorempixel.transport();
- assert.strictEqual(transport, 'https://lorempixel.com/640/480/transport');
- });
+ assert.strictEqual(imageUrl, 'https://lorempixel.com/100/100/abstract');
+ });
+ });
+ describe("avatar()", function () {
+ it("return a random avatar from FakerCloud", function () {
+ assert.notStrictEqual(-1, faker.image.lorempixel.avatar().indexOf('cdn.fakercloud.com/avatars'));
+ })
+ });
+ describe("abstract()", function () {
+ it("returns a random abstract image url", function () {
+ var abstract = faker.image.lorempixel.abstract();
+ assert.strictEqual(abstract, 'https://lorempixel.com/640/480/abstract');
+ });
+ });
+ describe("animals()", function () {
+ it("returns a random animals image url", function () {
+ var animals = faker.image.lorempixel.animals();
+ assert.strictEqual(animals, 'https://lorempixel.com/640/480/animals');
+ });
+ });
+ describe("business()", function () {
+ it("returns a random business image url", function () {
+ var business = faker.image.lorempixel.business();
+ assert.strictEqual(business, 'https://lorempixel.com/640/480/business');
+ });
+ });
+ describe("cats()", function () {
+ it("returns a random cats image url", function () {
+ var cats = faker.image.lorempixel.cats();
+ assert.strictEqual(cats, 'https://lorempixel.com/640/480/cats');
+ });
+ });
+ describe("city()", function () {
+ it("returns a random city image url", function () {
+ var city = faker.image.lorempixel.city();
+ assert.strictEqual(city, 'https://lorempixel.com/640/480/city');
+ });
+ });
+ describe("food()", function () {
+ it("returns a random food image url", function () {
+ var food = faker.image.lorempixel.food();
+ assert.strictEqual(food, 'https://lorempixel.com/640/480/food');
+ });
+ });
+ describe("nightlife()", function () {
+ it("returns a random nightlife image url", function () {
+ var nightlife = faker.image.lorempixel.nightlife();
+ assert.strictEqual(nightlife, 'https://lorempixel.com/640/480/nightlife');
});
});
+ describe("fashion()", function () {
+ it("returns a random fashion image url", function () {
+ var fashion = faker.image.lorempixel.fashion();
+ assert.strictEqual(fashion, 'https://lorempixel.com/640/480/fashion');
+ });
+ });
+ describe("people()", function () {
+ it("returns a random people image url", function () {
+ var people = faker.image.lorempixel.people();
+ assert.strictEqual(people, 'https://lorempixel.com/640/480/people');
+ });
+ });
+ describe("nature()", function () {
+ it("returns a random nature image url", function () {
+ var nature = faker.image.lorempixel.nature();
+ assert.strictEqual(nature, 'https://lorempixel.com/640/480/nature');
+ });
+ });
+ describe("sports()", function () {
+ it("returns a random sports image url", function () {
+ var sports = faker.image.lorempixel.sports();
+ assert.strictEqual(sports, 'https://lorempixel.com/640/480/sports');
+ });
+ });
+ describe("technics()", function () {
+ it("returns a random technics image url", function () {
+ var technics = faker.image.lorempixel.technics();
+ assert.strictEqual(technics, 'https://lorempixel.com/640/480/technics');
+ });
+ });
+ describe("transport()", function () {
+ it("returns a random transport image url", function () {
+ var transport = faker.image.lorempixel.transport();
+ assert.strictEqual(transport, 'https://lorempixel.com/640/480/transport');
+ });
+ });
+ });
- describe("unsplash", function() {
- describe("imageUrl()", function () {
- it("returns a random image url from unsplash", function () {
- var imageUrl = faker.image.unsplash.imageUrl();
+ describe("unsplash", function() {
+ describe("imageUrl()", function () {
+ it("returns a random image url from unsplash", function () {
+ var imageUrl = faker.image.unsplash.imageUrl();
- assert.strictEqual(imageUrl, 'https://source.unsplash.com/640x480');
- });
- it("returns a random image url from unsplash with width and height", function () {
- var imageUrl = faker.image.unsplash.imageUrl(100, 100);
+ assert.strictEqual(imageUrl, 'https://source.unsplash.com/640x480');
+ });
+ it("returns a random image url from unsplash with width and height", function () {
+ var imageUrl = faker.image.unsplash.imageUrl(100, 100);
- assert.strictEqual(imageUrl, 'https://source.unsplash.com/100x100');
- });
- it("returns a random image url for a specified category", function () {
- var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food');
+ assert.strictEqual(imageUrl, 'https://source.unsplash.com/100x100');
+ });
+ it("returns a random image url for a specified category", function () {
+ var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food');
- assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100');
- });
- it("returns a random image url with correct keywords for a specified category", function () {
- var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,keyword2');
+ assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100');
+ });
+ it("returns a random image url with correct keywords for a specified category", function () {
+ var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,keyword2');
- assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100?keyword1,keyword2');
- });
- it("returns a random image url without keyword which format is wrong for a specified category", function () {
- var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,?ds)0123$*908932409');
+ assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100?keyword1,keyword2');
+ });
+ it("returns a random image url without keyword which format is wrong for a specified category", function () {
+ var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,?ds)0123$*908932409');
- assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100');
- });
- });
- describe("image()", function() {
- it("returns a searching image url with keyword", function () {
- var food = faker.image.unsplash.image(100, 200, 'keyword1,keyword2,keyword3');
- assert.strictEqual(food, 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3');
- });
- })
- describe("food()", function () {
- it("returns a random food image url", function () {
- var food = faker.image.unsplash.food();
- assert.strictEqual(food, 'https://source.unsplash.com/category/food/640x480');
- });
- });
- describe("people()", function () {
- it("returns a random people image url", function () {
- var people = faker.image.unsplash.people();
- assert.strictEqual(people, 'https://source.unsplash.com/category/people/640x480');
- });
- });
- describe("nature()", function () {
- it("returns a random nature image url", function () {
- var nature = faker.image.unsplash.nature();
- assert.strictEqual(nature, 'https://source.unsplash.com/category/nature/640x480');
- });
- });
- describe("technology()", function () {
- it("returns a random technology image url", function () {
- var transport = faker.image.unsplash.technology();
- assert.strictEqual(transport, 'https://source.unsplash.com/category/technology/640x480');
- });
- });
- describe("objects()", function () {
- it("returns a random objects image url", function () {
- var transport = faker.image.unsplash.objects();
- assert.strictEqual(transport, 'https://source.unsplash.com/category/objects/640x480');
- });
- });
- describe("buildings()", function () {
- it("returns a random buildings image url", function () {
- var transport = faker.image.unsplash.buildings();
- assert.strictEqual(transport, 'https://source.unsplash.com/category/buildings/640x480');
- });
+ assert.strictEqual(imageUrl, 'https://source.unsplash.com/category/food/100x100');
+ });
+ });
+ describe("image()", function() {
+ it("returns a searching image url with keyword", function () {
+ var food = faker.image.unsplash.image(100, 200, 'keyword1,keyword2,keyword3');
+ assert.strictEqual(food, 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3');
+ });
+ })
+ describe("food()", function () {
+ it("returns a random food image url", function () {
+ var food = faker.image.unsplash.food();
+ assert.strictEqual(food, 'https://source.unsplash.com/category/food/640x480');
+ });
+ });
+ describe("people()", function () {
+ it("returns a random people image url", function () {
+ var people = faker.image.unsplash.people();
+ assert.strictEqual(people, 'https://source.unsplash.com/category/people/640x480');
+ });
+ });
+ describe("nature()", function () {
+ it("returns a random nature image url", function () {
+ var nature = faker.image.unsplash.nature();
+ assert.strictEqual(nature, 'https://source.unsplash.com/category/nature/640x480');
});
});
- describe("dataUri", function () {
- it("returns a blank data", function () {
- var dataUri = faker.image.dataUri(200,300);
- assert.strictEqual(dataUri, 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E');
- });
- it("returns a customed background color data URI", function () {
- var dataUri = faker.image.dataUri(200, 300, 'red');
- assert.strictEqual(dataUri, 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22red%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E');
- });
+ describe("technology()", function () {
+ it("returns a random technology image url", function () {
+ var transport = faker.image.unsplash.technology();
+ assert.strictEqual(transport, 'https://source.unsplash.com/category/technology/640x480');
+ });
+ });
+ describe("objects()", function () {
+ it("returns a random objects image url", function () {
+ var transport = faker.image.unsplash.objects();
+ assert.strictEqual(transport, 'https://source.unsplash.com/category/objects/640x480');
+ });
+ });
+ describe("buildings()", function () {
+ it("returns a random buildings image url", function () {
+ var transport = faker.image.unsplash.buildings();
+ assert.strictEqual(transport, 'https://source.unsplash.com/category/buildings/640x480');
+ });
+ });
+ });
+ describe("dataUri", function () {
+ it("returns a blank data", function () {
+ var dataUri = faker.image.dataUri(200,300);
+ assert.strictEqual(dataUri, 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E');
+ });
+ it("returns a customed background color data URI", function () {
+ var dataUri = faker.image.dataUri(200, 300, 'red');
+ assert.strictEqual(dataUri, 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22200%22%20height%3D%22300%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22red%22%2F%3E%3Ctext%20x%3D%22100%22%20y%3D%22150%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3E200x300%3C%2Ftext%3E%3C%2Fsvg%3E');
});
+ });
});
diff --git a/test/internet.unit.js b/test/internet.unit.js
index 48006472..f615656c 100644
--- a/test/internet.unit.js
+++ b/test/internet.unit.js
@@ -1,228 +1,228 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("internet.js", function () {
- describe("email()", function () {
- it("returns an email", function () {
- sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
- var email = faker.internet.email("Aiden.Harann55");
- var res = email.split("@");
- res = res[0];
- assert.strictEqual(res, 'Aiden.Harann55');
- faker.internet.userName.restore();
- });
-
- it("returns an email with japanese characters", function () {
- sinon.stub(faker.internet, 'userName').returns('思源_唐3');
- var email = faker.internet.email("思源_唐3");
- var res = email.split("@");
- res = res[0];
- assert.equal(res, '思源_唐3');
- faker.internet.userName.restore();
- });
- });
-
- describe("exampleEmail", function () {
- it("returns an email with the correct name", function () {
- sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
- var email = faker.internet.email("Aiden.Harann55");
- var res = email.split("@");
- res = res[0];
- assert.strictEqual(res, 'Aiden.Harann55');
- faker.internet.userName.restore();
- });
-
- it("uses the example.[org|com|net] host", function () {
- var email = faker.internet.exampleEmail();
- assert.ok(email.match(/@example\.(org|com|net)$/));
- });
+ describe("email()", function () {
+ it("returns an email", function () {
+ sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
+ var email = faker.internet.email("Aiden.Harann55");
+ var res = email.split("@");
+ res = res[0];
+ assert.strictEqual(res, 'Aiden.Harann55');
+ faker.internet.userName.restore();
});
- describe("userName()", function () {
- it("occasionally returns a single firstName", function () {
- sinon.stub(faker.datatype, 'number').returns(0);
- sinon.spy(faker.name, 'firstName');
- var username = faker.internet.userName();
+ it("returns an email with japanese characters", function () {
+ sinon.stub(faker.internet, 'userName').returns('思源_唐3');
+ var email = faker.internet.email("思源_唐3");
+ var res = email.split("@");
+ res = res[0];
+ assert.equal(res, '思源_唐3');
+ faker.internet.userName.restore();
+ });
+ });
+
+ describe("exampleEmail", function () {
+ it("returns an email with the correct name", function () {
+ sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
+ var email = faker.internet.email("Aiden.Harann55");
+ var res = email.split("@");
+ res = res[0];
+ assert.strictEqual(res, 'Aiden.Harann55');
+ faker.internet.userName.restore();
+ });
- assert.ok(username);
- assert.ok(faker.name.firstName.called);
+ it("uses the example.[org|com|net] host", function () {
+ var email = faker.internet.exampleEmail();
+ assert.ok(email.match(/@example\.(org|com|net)$/));
+ });
+ });
- faker.datatype.number.restore();
- faker.name.firstName.restore();
- });
+ describe("userName()", function () {
+ it("occasionally returns a single firstName", function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
+ sinon.spy(faker.name, 'firstName');
+ var username = faker.internet.userName();
- it("occasionally returns a firstName with a period or hyphen and a lastName", function () {
- sinon.stub(faker.datatype, 'number').returns(1);
- sinon.spy(faker.name, 'firstName');
- sinon.spy(faker.name, 'lastName');
- sinon.spy(faker.random, 'arrayElement');
- var username = faker.internet.userName();
+ assert.ok(username);
+ assert.ok(faker.name.firstName.called);
- assert.ok(username);
- assert.ok(faker.name.firstName.called);
- assert.ok(faker.name.lastName.called);
- assert.ok(faker.random.arrayElement.calledWith(['.', '_']));
+ faker.datatype.number.restore();
+ faker.name.firstName.restore();
+ });
- faker.datatype.number.restore();
- faker.name.firstName.restore();
- faker.name.lastName.restore();
- faker.random.arrayElement.restore();
- });
+ it("occasionally returns a firstName with a period or hyphen and a lastName", function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
+ sinon.spy(faker.name, 'firstName');
+ sinon.spy(faker.name, 'lastName');
+ sinon.spy(faker.random, 'arrayElement');
+ var username = faker.internet.userName();
+
+ assert.ok(username);
+ assert.ok(faker.name.firstName.called);
+ assert.ok(faker.name.lastName.called);
+ assert.ok(faker.random.arrayElement.calledWith(['.', '_']));
+
+ faker.datatype.number.restore();
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ faker.random.arrayElement.restore();
});
+ });
- describe("domainName()", function () {
- it("returns a domainWord plus a random suffix", function () {
- sinon.stub(faker.internet, 'domainWord').returns('bar');
- sinon.stub(faker.internet, 'domainSuffix').returns('net');
+ describe("domainName()", function () {
+ it("returns a domainWord plus a random suffix", function () {
+ sinon.stub(faker.internet, 'domainWord').returns('bar');
+ sinon.stub(faker.internet, 'domainSuffix').returns('net');
- var domain_name = faker.internet.domainName();
+ var domain_name = faker.internet.domainName();
- assert.strictEqual(domain_name, 'bar.net');
+ assert.strictEqual(domain_name, 'bar.net');
- faker.internet.domainWord.restore();
- faker.internet.domainSuffix.restore();
- });
+ faker.internet.domainWord.restore();
+ faker.internet.domainSuffix.restore();
});
+ });
- describe("domainWord()", function () {
- it("returns a lower-case firstName", function () {
- sinon.stub(faker.name, 'firstName').returns('FOO');
- var domain_word = faker.internet.domainWord();
+ describe("domainWord()", function () {
+ it("returns a lower-case firstName", function () {
+ sinon.stub(faker.name, 'firstName').returns('FOO');
+ var domain_word = faker.internet.domainWord();
- assert.ok(domain_word);
- assert.strictEqual(domain_word, 'foo');
+ assert.ok(domain_word);
+ assert.strictEqual(domain_word, 'foo');
- faker.name.firstName.restore();
- });
- describe("when the firstName used contains a apostrophe", function () {
- sinon.stub(faker.name, 'firstName').returns('d\'angelo');
- var domain_word = faker.internet.domainWord();
+ faker.name.firstName.restore();
+ });
+ describe("when the firstName used contains a apostrophe", function () {
+ sinon.stub(faker.name, 'firstName').returns('d\'angelo');
+ var domain_word = faker.internet.domainWord();
- it("should remove the apostrophe", function () {
- assert.strictEqual(domain_word, 'dangelo');
- });
+ it("should remove the apostrophe", function () {
+ assert.strictEqual(domain_word, 'dangelo');
+ });
- faker.name.firstName.restore();
- });
+ faker.name.firstName.restore();
});
+ });
- describe('protocol()', function () {
- it('returns a valid protocol', function () {
- var protocol = faker.internet.protocol();
- assert.ok(protocol);
- });
+ describe('protocol()', function () {
+ it('returns a valid protocol', function () {
+ var protocol = faker.internet.protocol();
+ assert.ok(protocol);
+ });
- it('should occasionally return http', function () {
- sinon.stub(faker.datatype, 'number').returns(0);
- var protocol = faker.internet.protocol();
- assert.ok(protocol);
- assert.strictEqual(protocol, 'http');
+ it('should occasionally return http', function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
+ var protocol = faker.internet.protocol();
+ assert.ok(protocol);
+ assert.strictEqual(protocol, 'http');
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it('should occasionally return https', function () {
- sinon.stub(faker.datatype, 'number').returns(1);
- var protocol = faker.internet.protocol();
- assert.ok(protocol);
- assert.strictEqual(protocol, 'https');
+ it('should occasionally return https', function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
+ var protocol = faker.internet.protocol();
+ assert.ok(protocol);
+ assert.strictEqual(protocol, 'https');
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
});
+ });
- describe('httpMethod()', function () {
- it('returns a valid http method', function () {
- var httpMethods = ['GET','POST', 'PUT', 'DELETE', 'PATCH'];
- var method = faker.internet.httpMethod();
- assert.ok(httpMethods.includes(method));
- });
+ describe('httpMethod()', function () {
+ it('returns a valid http method', function () {
+ var httpMethods = ['GET','POST', 'PUT', 'DELETE', 'PATCH'];
+ var method = faker.internet.httpMethod();
+ assert.ok(httpMethods.includes(method));
});
+ });
- describe('url()', function () {
- it('returns a valid url', function () {
- sinon.stub(faker.internet,'protocol').returns('http');
- sinon.stub(faker.internet, 'domainWord').returns('bar');
- sinon.stub(faker.internet, 'domainSuffix').returns('net');
+ describe('url()', function () {
+ it('returns a valid url', function () {
+ sinon.stub(faker.internet,'protocol').returns('http');
+ sinon.stub(faker.internet, 'domainWord').returns('bar');
+ sinon.stub(faker.internet, 'domainSuffix').returns('net');
- var url = faker.internet.url();
+ var url = faker.internet.url();
- assert.ok(url);
- assert.strictEqual(url,'http://bar.net');
- });
+ assert.ok(url);
+ assert.strictEqual(url,'http://bar.net');
});
+ });
- describe("ip()", function () {
- it("returns a random IP address with four parts", function () {
- var ip = faker.internet.ip();
- var parts = ip.split('.');
- assert.strictEqual(parts.length, 4);
- });
+ describe("ip()", function () {
+ it("returns a random IP address with four parts", function () {
+ var ip = faker.internet.ip();
+ var parts = ip.split('.');
+ assert.strictEqual(parts.length, 4);
});
+ });
- describe("ipv6()", function () {
- it("returns a random IPv6 address with eight parts", function () {
- var ip = faker.internet.ipv6();
- var parts = ip.split(':');
- assert.strictEqual(parts.length, 8);
- });
+ describe("ipv6()", function () {
+ it("returns a random IPv6 address with eight parts", function () {
+ var ip = faker.internet.ipv6();
+ var parts = ip.split(':');
+ assert.strictEqual(parts.length, 8);
});
+ });
- describe("port()", function () {
- it("returns a random port number", function () {
- var port = faker.internet.port();
- assert.ok(Number.isInteger(port));
- assert.ok(0 <= port && port <= 65535);
- });
+ describe("port()", function () {
+ it("returns a random port number", function () {
+ var port = faker.internet.port();
+ assert.ok(Number.isInteger(port));
+ assert.ok(0 <= port && port <= 65535);
});
+ });
- describe("userAgent()", function () {
- it("returns a valid user-agent", function () {
- var ua = faker.internet.userAgent();
- assert.ok(ua);
- });
+ describe("userAgent()", function () {
+ it("returns a valid user-agent", function () {
+ var ua = faker.internet.userAgent();
+ assert.ok(ua);
+ });
- it('is deterministic', function () {
- faker.seed(1);
- var ua1 = faker.internet.userAgent();
- faker.seed(1);
- var ua2 = faker.internet.userAgent();
- assert.strictEqual(ua1, ua2);
- });
+ it('is deterministic', function () {
+ faker.seed(1);
+ var ua1 = faker.internet.userAgent();
+ faker.seed(1);
+ var ua2 = faker.internet.userAgent();
+ assert.strictEqual(ua1, ua2);
});
+ });
- describe("color()", function () {
- it("returns a valid hex value (like #ffffff)", function () {
- var color = faker.internet.color(100, 100, 100);
- assert.ok(color.match(/^#[a-f0-9]{6}$/));
- });
+ describe("color()", function () {
+ it("returns a valid hex value (like #ffffff)", function () {
+ var color = faker.internet.color(100, 100, 100);
+ assert.ok(color.match(/^#[a-f0-9]{6}$/));
});
+ });
- describe("mac()", function () {
- it("returns a random MAC address with 6 hexadecimal digits", function () {
- var mac = faker.internet.mac();
- assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
- });
+ describe("mac()", function () {
+ it("returns a random MAC address with 6 hexadecimal digits", function () {
+ var mac = faker.internet.mac();
+ assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
+ });
- it("uses the dash separator if we pass it in as our separator", function () {
- var mac = faker.internet.mac('-');
- assert.ok(mac.match(/^([a-f0-9]{2}-){5}[a-f0-9]{2}$/));
- });
+ it("uses the dash separator if we pass it in as our separator", function () {
+ var mac = faker.internet.mac('-');
+ assert.ok(mac.match(/^([a-f0-9]{2}-){5}[a-f0-9]{2}$/));
+ });
- it("uses no separator if we pass in an empty string", function() {
- var mac = faker.internet.mac('');
- assert.ok(mac.match(/^[a-f0-9]{12}$/));
- });
+ it("uses no separator if we pass in an empty string", function() {
+ var mac = faker.internet.mac('');
+ assert.ok(mac.match(/^[a-f0-9]{12}$/));
+ });
- it("uses the default colon (:) if we provide an unacceptable separator", function() {
- var mac = faker.internet.mac('!');
- assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
+ it("uses the default colon (:) if we provide an unacceptable separator", function() {
+ var mac = faker.internet.mac('!');
+ assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
- mac = faker.internet.mac('&');
- assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
- });
+ mac = faker.internet.mac('&');
+ assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
});
+ });
});
diff --git a/test/locales.unit.js b/test/locales.unit.js
index 8f8be2d7..f1e1e4fb 100644
--- a/test/locales.unit.js
+++ b/test/locales.unit.js
@@ -1,7 +1,7 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
// TODO: make some tests for getting / setting locales
@@ -9,12 +9,12 @@ if (typeof module !== 'undefined') {
// Remark: actual use of locales functionality is currently tested in all.functional.js test
describe("locale", function () {
- describe("setLocale()", function () {
- it("setLocale() changes faker.locale", function () {
- for(var locale in faker.locales) {
- faker.setLocale(locale)
- assert.strictEqual(faker.locale, locale);
- }
- });
+ describe("setLocale()", function () {
+ it("setLocale() changes faker.locale", function () {
+ for(var locale in faker.locales) {
+ faker.setLocale(locale)
+ assert.strictEqual(faker.locale, locale);
+ }
});
+ });
});
diff --git a/test/lorem.unit.js b/test/lorem.unit.js
index d7853a4b..7902077e 100644
--- a/test/lorem.unit.js
+++ b/test/lorem.unit.js
@@ -1,88 +1,88 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("lorem.js", function () {
- describe("word()", function () {
+ describe("word()", function () {
- context("when no 'length' param passed in", function () {
- it("returns a word with a random length", function () {
- var str = faker.lorem.word();
- assert.ok(typeof str === 'string');
- });
- });
+ context("when no 'length' param passed in", function () {
+ it("returns a word with a random length", function () {
+ var str = faker.lorem.word();
+ assert.ok(typeof str === 'string');
+ });
+ });
- context("when 'length' param passed in", function () {
- it("returns a word with the requested length", function () {
- var str = faker.lorem.word(5);
- assert.ok(typeof str === 'string');
- assert.strictEqual(str.length, 5);
- });
- });
+ context("when 'length' param passed in", function () {
+ it("returns a word with the requested length", function () {
+ var str = faker.lorem.word(5);
+ assert.ok(typeof str === 'string');
+ assert.strictEqual(str.length, 5);
+ });
});
+ });
- describe("words()", function () {
- beforeEach(function () {
- sinon.spy(faker.helpers, 'shuffle');
- });
-
- afterEach(function () {
- faker.helpers.shuffle.restore();
- });
+ describe("words()", function () {
+ beforeEach(function () {
+ sinon.spy(faker.helpers, 'shuffle');
+ });
- context("when no 'num' param passed in", function () {
- it("returns three words", function () {
- var str = faker.lorem.words();
- var words = str.split(' ');
- assert.ok(Array.isArray(words));
- assert.strictEqual(true, words.length >= 3);
- // assert.ok(faker.helpers.shuffle.called);
- });
- });
+ afterEach(function () {
+ faker.helpers.shuffle.restore();
+ });
- context("when 'num' param passed in", function () {
- it("returns requested number of words", function () {
- var str = faker.lorem.words(7);
- var words = str.split(' ');
- assert.ok(Array.isArray(words));
- assert.strictEqual(words.length, 7);
- });
- });
+ context("when no 'num' param passed in", function () {
+ it("returns three words", function () {
+ var str = faker.lorem.words();
+ var words = str.split(' ');
+ assert.ok(Array.isArray(words));
+ assert.strictEqual(true, words.length >= 3);
+ // assert.ok(faker.helpers.shuffle.called);
+ });
});
- describe("slug()", function () {
- beforeEach(function () {
- sinon.spy(faker.helpers, 'shuffle');
- });
+ context("when 'num' param passed in", function () {
+ it("returns requested number of words", function () {
+ var str = faker.lorem.words(7);
+ var words = str.split(' ');
+ assert.ok(Array.isArray(words));
+ assert.strictEqual(words.length, 7);
+ });
+ });
+ });
- afterEach(function () {
- faker.helpers.shuffle.restore();
- });
+ describe("slug()", function () {
+ beforeEach(function () {
+ sinon.spy(faker.helpers, 'shuffle');
+ });
- var validateSlug = function (wordCount, str) {
- assert.strictEqual(1, str.match(/^[a-z][a-z-]*[a-z]$/).length);
- assert.strictEqual(wordCount - 1, str.match(/-/g).length);
- };
+ afterEach(function () {
+ faker.helpers.shuffle.restore();
+ });
- context("when no 'wordCount' param passed in", function () {
- it("returns a slug with three words", function () {
- var str = faker.lorem.slug();
- validateSlug(3, str);
- });
- });
+ var validateSlug = function (wordCount, str) {
+ assert.strictEqual(1, str.match(/^[a-z][a-z-]*[a-z]$/).length);
+ assert.strictEqual(wordCount - 1, str.match(/-/g).length);
+ };
- context("when 'wordCount' param passed in", function () {
- it("returns a slug with requested number of words", function () {
- var str = faker.lorem.slug(7);
- validateSlug(7, str);
- });
- });
+ context("when no 'wordCount' param passed in", function () {
+ it("returns a slug with three words", function () {
+ var str = faker.lorem.slug();
+ validateSlug(3, str);
+ });
+ });
+ context("when 'wordCount' param passed in", function () {
+ it("returns a slug with requested number of words", function () {
+ var str = faker.lorem.slug(7);
+ validateSlug(7, str);
+ });
});
- /*
+ });
+
+ /*
describe("sentence()", function () {
context("when no 'wordCount' or 'range' param passed in", function () {
it("returns a string of at least three words", function () {
@@ -136,7 +136,7 @@ describe("lorem.js", function () {
});
});
*/
- /*
+ /*
describe("sentences()", function () {
context("when no 'sentenceCount' param passed in", function () {
it("returns newline-separated string of three sentences", function () {
@@ -166,7 +166,7 @@ describe("lorem.js", function () {
});
});
*/
- /*
+ /*
describe("paragraph()", function () {
context("when no 'wordCount' param passed in", function () {
it("returns a string of at least three sentences", function () {
@@ -202,7 +202,7 @@ describe("lorem.js", function () {
});
*/
- /*
+ /*
describe("paragraphs()", function () {
context("when no 'paragraphCount' param passed in", function () {
diff --git a/test/music.unit.js b/test/music.unit.js
index 3abc0787..d6d3a151 100644
--- a/test/music.unit.js
+++ b/test/music.unit.js
@@ -1,17 +1,17 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("music.js", function () {
- describe("genre()", function () {
- it("returns a genre", function () {
- sinon.stub(faker.music, 'genre').returns('Rock');
- var genre = faker.music.genre();
+ describe("genre()", function () {
+ it("returns a genre", function () {
+ sinon.stub(faker.music, 'genre').returns('Rock');
+ var genre = faker.music.genre();
- assert.strictEqual(genre, 'Rock');
- faker.music.genre.restore();
- });
+ assert.strictEqual(genre, 'Rock');
+ faker.music.genre.restore();
});
+ });
});
diff --git a/test/name.unit.js b/test/name.unit.js
index 89d7effa..4820983d 100644
--- a/test/name.unit.js
+++ b/test/name.unit.js
@@ -1,274 +1,274 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
function assertInArray(value, array) {
- var idx = array.indexOf(value);
- assert.notEqual(idx, -1);
+ var idx = array.indexOf(value);
+ assert.notEqual(idx, -1);
}
describe("name.js", function () {
- describe("firstName()", function () {
- it("returns a random name", function () {
- sinon.stub(faker.name, 'firstName').returns('foo');
- var first_name = faker.name.firstName();
+ describe("firstName()", function () {
+ it("returns a random name", function () {
+ sinon.stub(faker.name, 'firstName').returns('foo');
+ var first_name = faker.name.firstName();
- assert.strictEqual(first_name, 'foo');
+ assert.strictEqual(first_name, 'foo');
- faker.name.firstName.restore();
- });
+ faker.name.firstName.restore();
+ });
- it("returns a gender-specific name when passed a number", function () {
- for (var q = 0; q < 30; q++) {
- var gender = Math.floor(Math.random() * 2);
- var name = faker.name.firstName(gender);
- if (gender === 0) assertInArray(name, faker.definitions.name.male_first_name);
- else assertInArray(name, faker.definitions.name.female_first_name);
- }
- });
+ it("returns a gender-specific name when passed a number", function () {
+ for (var q = 0; q < 30; q++) {
+ var gender = Math.floor(Math.random() * 2);
+ var name = faker.name.firstName(gender);
+ if (gender === 0) {assertInArray(name, faker.definitions.name.male_first_name);}
+ else {assertInArray(name, faker.definitions.name.female_first_name);}
+ }
+ });
- it("returns a gender-specific name when passed a string", function () {
- for (var q = 0; q < 30; q++) {
- var gender = Math.floor(Math.random() * 2);
- var genderString = (gender === 0 ? 'male' : 'female');
- var name = faker.name.firstName(genderString);
- assertInArray(name, faker.definitions.name[genderString + '_first_name']);
- }
- });
+ it("returns a gender-specific name when passed a string", function () {
+ for (var q = 0; q < 30; q++) {
+ var gender = Math.floor(Math.random() * 2);
+ var genderString = (gender === 0 ? 'male' : 'female');
+ var name = faker.name.firstName(genderString);
+ assertInArray(name, faker.definitions.name[genderString + '_first_name']);
+ }
});
+ });
- describe("lastName()", function () {
- it("returns a random name", function () {
- sinon.stub(faker.name, 'lastName').returns('foo');
+ describe("lastName()", function () {
+ it("returns a random name", function () {
+ sinon.stub(faker.name, 'lastName').returns('foo');
- var last_name = faker.name.lastName();
+ var last_name = faker.name.lastName();
- assert.strictEqual(last_name, 'foo');
+ assert.strictEqual(last_name, 'foo');
- faker.name.lastName.restore();
- });
+ faker.name.lastName.restore();
});
+ });
- describe("middleName()", function () {
+ describe("middleName()", function () {
- it("returns a random middle name", function () {
- sinon.stub(faker.name, 'middleName').returns('foo');
+ it("returns a random middle name", function () {
+ sinon.stub(faker.name, 'middleName').returns('foo');
- var middle_name = faker.name.middleName();
+ var middle_name = faker.name.middleName();
- assert.strictEqual(middle_name, 'foo');
+ assert.strictEqual(middle_name, 'foo');
- faker.name.middleName.restore();
- });
+ faker.name.middleName.restore();
+ });
- describe('when using a locale with gender specific middle names', function () {
- beforeEach(function(){
- this.oldLocale = faker.locale;
- faker.locale = 'TEST';
+ describe('when using a locale with gender specific middle names', function () {
+ beforeEach(function(){
+ this.oldLocale = faker.locale;
+ faker.locale = 'TEST';
- faker.locales['TEST'] = {
- name: {
- male_middle_name: ['Genaddiesvich'],
- female_middle_name: ['Genaddievna']
- }
- };
- });
+ faker.locales['TEST'] = {
+ name: {
+ male_middle_name: ['Genaddiesvich'],
+ female_middle_name: ['Genaddievna']
+ }
+ };
+ });
- afterEach(function () {
- faker.locale = this.oldLocale;
- delete faker.locale['TEST'];
- })
+ afterEach(function () {
+ faker.locale = this.oldLocale;
+ delete faker.locale['TEST'];
+ })
- it("returns male prefix", function () {
- var middle_name = faker.name.middleName(0);
+ it("returns male prefix", function () {
+ var middle_name = faker.name.middleName(0);
- assert.strictEqual(middle_name, 'Genaddiesvich')
- });
+ assert.strictEqual(middle_name, 'Genaddiesvich')
+ });
- it("returns female prefix", function () {
- var middle_name = faker.name.middleName(1);
+ it("returns female prefix", function () {
+ var middle_name = faker.name.middleName(1);
- assert.strictEqual(middle_name, 'Genaddievna');
- });
- });
+ assert.strictEqual(middle_name, 'Genaddievna');
+ });
});
+ });
- describe("findName()", function () {
- it("usually returns a first name and last name", function () {
- sinon.stub(faker.datatype, 'number').returns(5);
- var name = faker.name.findName();
- assert.ok(name);
- var parts = name.split(' ');
+ describe("findName()", function () {
+ it("usually returns a first name and last name", function () {
+ sinon.stub(faker.datatype, 'number').returns(5);
+ var name = faker.name.findName();
+ assert.ok(name);
+ var parts = name.split(' ');
- assert.strictEqual(parts.length, 2);
+ assert.strictEqual(parts.length, 2);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("occasionally returns a first name and last name with a prefix", function () {
- sinon.stub(faker.datatype, 'number').returns(0);
- var name = faker.name.findName();
- var parts = name.split(' ');
+ it("occasionally returns a first name and last name with a prefix", function () {
+ sinon.stub(faker.datatype, 'number').returns(0);
+ var name = faker.name.findName();
+ var parts = name.split(' ');
- assert.ok(parts.length >= 3);
+ assert.ok(parts.length >= 3);
- faker.datatype.number.restore();
- });
+ faker.datatype.number.restore();
+ });
- it("occasionally returns a male full name with a prefix", function () {
- sinon.stub(faker.datatype, 'number')
- .withArgs(8).returns(0) // with prefix
- .withArgs(1).returns(0); // gender male
+ it("occasionally returns a male full name with a prefix", function () {
+ sinon.stub(faker.datatype, 'number')
+ .withArgs(8).returns(0) // with prefix
+ .withArgs(1).returns(0); // gender male
- sinon.stub(faker.name, 'prefix').withArgs(0).returns('X');
- sinon.stub(faker.name, 'firstName').withArgs(0).returns('Y');
- sinon.stub(faker.name, 'lastName').withArgs(0).returns('Z');
+ sinon.stub(faker.name, 'prefix').withArgs(0).returns('X');
+ sinon.stub(faker.name, 'firstName').withArgs(0).returns('Y');
+ sinon.stub(faker.name, 'lastName').withArgs(0).returns('Z');
- var name = faker.name.findName();
+ var name = faker.name.findName();
- assert.strictEqual(name, 'X Y Z');
+ assert.strictEqual(name, 'X Y Z');
- faker.datatype.number.restore();
- faker.name.prefix.restore();
- faker.name.firstName.restore();
- faker.name.lastName.restore();
- });
+ faker.datatype.number.restore();
+ faker.name.prefix.restore();
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ });
- it("occasionally returns a female full name with a prefix", function () {
- sinon.stub(faker.datatype, 'number')
- .withArgs(8).returns(0) // with prefix
- .withArgs(1).returns(1); // gender female
+ it("occasionally returns a female full name with a prefix", function () {
+ sinon.stub(faker.datatype, 'number')
+ .withArgs(8).returns(0) // with prefix
+ .withArgs(1).returns(1); // gender female
- sinon.stub(faker.name, 'prefix').withArgs(1).returns('J');
- sinon.stub(faker.name, 'firstName').withArgs(1).returns('K');
- sinon.stub(faker.name, 'lastName').withArgs(1).returns('L');
+ sinon.stub(faker.name, 'prefix').withArgs(1).returns('J');
+ sinon.stub(faker.name, 'firstName').withArgs(1).returns('K');
+ sinon.stub(faker.name, 'lastName').withArgs(1).returns('L');
- var name = faker.name.findName();
+ var name = faker.name.findName();
- assert.strictEqual(name, 'J K L');
+ assert.strictEqual(name, 'J K L');
- faker.datatype.number.restore();
- faker.name.prefix.restore();
- faker.name.firstName.restore();
- faker.name.lastName.restore();
- });
+ faker.datatype.number.restore();
+ faker.name.prefix.restore();
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ });
- it("occasionally returns a first name and last name with a suffix", function () {
- sinon.stub(faker.datatype, 'number').returns(1);
- sinon.stub(faker.name, 'suffix').returns('Jr.');
- var name = faker.name.findName();
- var parts = name.split(' ');
+ it("occasionally returns a first name and last name with a suffix", function () {
+ sinon.stub(faker.datatype, 'number').returns(1);
+ sinon.stub(faker.name, 'suffix').returns('Jr.');
+ var name = faker.name.findName();
+ var parts = name.split(' ');
- assert.ok(parts.length >= 3);
- assert.strictEqual(parts[parts.length-1], 'Jr.');
+ assert.ok(parts.length >= 3);
+ assert.strictEqual(parts[parts.length-1], 'Jr.');
- faker.name.suffix.restore();
- faker.datatype.number.restore();
- });
+ faker.name.suffix.restore();
+ faker.datatype.number.restore();
+ });
- it("needs to work with specific locales and respect the fallbacks", function () {
- faker.locale = 'en_US';
- // this will throw if this is broken
- var name = faker.name.findName();
- });
+ it("needs to work with specific locales and respect the fallbacks", function () {
+ faker.locale = 'en_US';
+ // this will throw if this is broken
+ var name = faker.name.findName();
});
+ });
- describe("title()", function () {
- it("returns a random title", function () {
- sinon.stub(faker.name, 'title').returns('Lead Solutions Supervisor');
+ describe("title()", function () {
+ it("returns a random title", function () {
+ sinon.stub(faker.name, 'title').returns('Lead Solutions Supervisor');
- var title = faker.name.title();
+ var title = faker.name.title();
- assert.strictEqual(title, 'Lead Solutions Supervisor');
+ assert.strictEqual(title, 'Lead Solutions Supervisor');
- faker.name.title.restore();
- });
+ faker.name.title.restore();
+ });
+ });
+
+ describe("jobTitle()", function () {
+ it("returns a job title consisting of a descriptor, area, and type", function () {
+ sinon.spy(faker.random, 'arrayElement');
+ sinon.spy(faker.name, 'jobDescriptor');
+ sinon.spy(faker.name, 'jobArea');
+ sinon.spy(faker.name, 'jobType');
+ var jobTitle = faker.name.jobTitle();
+
+ assert.ok(typeof jobTitle === 'string');
+ assert.ok(faker.random.arrayElement.calledThrice);
+ assert.ok(faker.name.jobDescriptor.calledOnce);
+ assert.ok(faker.name.jobArea.calledOnce);
+ assert.ok(faker.name.jobType.calledOnce);
+
+ faker.random.arrayElement.restore();
+ faker.name.jobDescriptor.restore();
+ faker.name.jobArea.restore();
+ faker.name.jobType.restore();
});
+ });
+
+ describe("prefix()", function () {
+ describe('when using a locale with gender specific name prefixes', function () {
+ beforeEach(function(){
+ this.oldLocale = faker.locale;
+ faker.locale = 'TEST';
+
+ faker.locales['TEST'] = {
+ name: {
+ male_prefix: ['Mp'],
+ female_prefix: ['Fp']
+ }
+ };
+ });
+
+ afterEach(function () {
+ faker.locale = this.oldLocale;
+ delete faker.locale['TEST'];
+ })
+
+ it("returns male prefix", function () {
+ var prefix = faker.name.prefix(0);
+ assert.strictEqual(prefix, 'Mp')
+ });
+
+ it("returns female prefix", function () {
+ var prefix = faker.name.prefix(1);
+
+ assert.strictEqual(prefix, 'Fp');
+ });
+
+ it("returns either prefix", function () {
+ var prefix = faker.name.prefix();
+ assert(['Mp', 'Fp'].indexOf(prefix) >= 0)
+ });
- describe("jobTitle()", function () {
- it("returns a job title consisting of a descriptor, area, and type", function () {
- sinon.spy(faker.random, 'arrayElement');
- sinon.spy(faker.name, 'jobDescriptor');
- sinon.spy(faker.name, 'jobArea');
- sinon.spy(faker.name, 'jobType');
- var jobTitle = faker.name.jobTitle();
-
- assert.ok(typeof jobTitle === 'string');
- assert.ok(faker.random.arrayElement.calledThrice);
- assert.ok(faker.name.jobDescriptor.calledOnce);
- assert.ok(faker.name.jobArea.calledOnce);
- assert.ok(faker.name.jobType.calledOnce);
-
- faker.random.arrayElement.restore();
- faker.name.jobDescriptor.restore();
- faker.name.jobArea.restore();
- faker.name.jobType.restore();
- });
});
- describe("prefix()", function () {
- describe('when using a locale with gender specific name prefixes', function () {
- beforeEach(function(){
- this.oldLocale = faker.locale;
- faker.locale = 'TEST';
-
- faker.locales['TEST'] = {
- name: {
- male_prefix: ['Mp'],
- female_prefix: ['Fp']
- }
- };
- });
-
- afterEach(function () {
- faker.locale = this.oldLocale;
- delete faker.locale['TEST'];
- })
-
- it("returns male prefix", function () {
- var prefix = faker.name.prefix(0);
- assert.strictEqual(prefix, 'Mp')
- });
-
- it("returns female prefix", function () {
- var prefix = faker.name.prefix(1);
-
- assert.strictEqual(prefix, 'Fp');
- });
-
- it("returns either prefix", function () {
- var prefix = faker.name.prefix();
- assert(['Mp', 'Fp'].indexOf(prefix) >= 0)
- });
-
- });
-
- describe('when using a locale without gender specific name prefixes', function () {
- beforeEach(function(){
- this.oldLocale = faker.locale;
- faker.locale = 'TEST';
-
- faker.locales['TEST'] = {
- name: {
- prefix: ['P']
- }
- };
- });
-
- afterEach(function () {
- faker.locale = this.oldLocale;
- delete faker.locale['TEST'];
- })
-
- it("returns a prefix", function () {
- var prefix = faker.name.prefix();
-
- assert.strictEqual(prefix, 'P');
- });
- });
+ describe('when using a locale without gender specific name prefixes', function () {
+ beforeEach(function(){
+ this.oldLocale = faker.locale;
+ faker.locale = 'TEST';
+
+ faker.locales['TEST'] = {
+ name: {
+ prefix: ['P']
+ }
+ };
+ });
+
+ afterEach(function () {
+ faker.locale = this.oldLocale;
+ delete faker.locale['TEST'];
+ })
+
+ it("returns a prefix", function () {
+ var prefix = faker.name.prefix();
+
+ assert.strictEqual(prefix, 'P');
+ });
});
+ });
});
diff --git a/test/phone_number.unit.js b/test/phone_number.unit.js
index 442a602a..40dbe72f 100644
--- a/test/phone_number.unit.js
+++ b/test/phone_number.unit.js
@@ -1,48 +1,48 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("phone_number.js", function () {
- describe("phoneNumber()", function () {
- it("returns a random phoneNumber with a random format", function () {
- sinon.spy(faker.helpers, 'replaceSymbolWithNumber');
- var phone_number = faker.phone.phoneNumber();
+ describe("phoneNumber()", function () {
+ it("returns a random phoneNumber with a random format", function () {
+ sinon.spy(faker.helpers, 'replaceSymbolWithNumber');
+ var phone_number = faker.phone.phoneNumber();
- assert.ok(phone_number.match(/\d/));
- assert.ok(faker.helpers.replaceSymbolWithNumber.called);
+ assert.ok(phone_number.match(/\d/));
+ assert.ok(faker.helpers.replaceSymbolWithNumber.called);
- faker.helpers.replaceSymbolWithNumber.restore();
- });
+ faker.helpers.replaceSymbolWithNumber.restore();
+ });
+ });
+
+ describe("phoneNumberFormat()", function () {
+ it("returns phone number with requested format (Array index)", function () {
+ faker.locale = "en";
+ for (var i = 0; i < 10; i++) {
+ var phone_number = faker.phone.phoneNumberFormat(1);
+ assert.ok(phone_number.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/));
+ }
});
- describe("phoneNumberFormat()", function () {
- it("returns phone number with requested format (Array index)", function () {
- faker.locale = "en";
- for (var i = 0; i < 10; i++) {
- var phone_number = faker.phone.phoneNumberFormat(1);
- assert.ok(phone_number.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/));
- }
- });
-
- it("returns phone number with proper format US (Array index)", function () {
- faker.locale = "en";
- for (var i = 0; i < 25; i++) {
- var phone_number = faker.phone.phoneNumberFormat(1);
- console.log(phone_number)
- assert.ok(phone_number.match(/\([2-9]\d\d\) [2-9]\d\d-\d\d\d\d/));
- }
- });
-
- it("returns phone number with proper format CA (Array index)", function () {
- faker.locale = "en_CA";
- for (var i = 0; i < 25; i++) {
- var phone_number = faker.phone.phoneNumberFormat(1);
- assert.ok(phone_number.match(/\([2-9]\d\d\)[2-9]\d\d-\d\d\d\d/));
- }
- });
+ it("returns phone number with proper format US (Array index)", function () {
+ faker.locale = "en";
+ for (var i = 0; i < 25; i++) {
+ var phone_number = faker.phone.phoneNumberFormat(1);
+ console.log(phone_number)
+ assert.ok(phone_number.match(/\([2-9]\d\d\) [2-9]\d\d-\d\d\d\d/));
+ }
+ });
+ it("returns phone number with proper format CA (Array index)", function () {
+ faker.locale = "en_CA";
+ for (var i = 0; i < 25; i++) {
+ var phone_number = faker.phone.phoneNumberFormat(1);
+ assert.ok(phone_number.match(/\([2-9]\d\d\)[2-9]\d\d-\d\d\d\d/));
+ }
});
+ });
+
});
diff --git a/test/random.unit.js b/test/random.unit.js
index a596d75b..147d7dbb 100644
--- a/test/random.unit.js
+++ b/test/random.unit.js
@@ -1,9 +1,9 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var _ = require('lodash');
- var faker = require('../index');
- var mersenne = require('../vendor/mersenne');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var _ = require('lodash');
+ var faker = require('../index');
+ var mersenne = require('../vendor/mersenne');
}
diff --git a/test/run.js b/test/run.js
index d577de9a..77a89bb7 100755
--- a/test/run.js
+++ b/test/run.js
@@ -7,17 +7,17 @@ var optimist = require('optimist');
var walk_dir = require('./support/walk_dir');
var argv = optimist
- .usage("Usage: $0 -t [types] --reporter [reporter] --timeout [timeout]")
- .default({types: 'unit,functional', reporter: 'spec', timeout: 6000})
- .describe('types', 'The types of tests to run, separated by commas. E.g., unit,functional,acceptance')
- .describe('reporter', 'The mocha test reporter to use.')
- .describe('timeout', 'The mocha timeout to use per test (ms).')
- .boolean('help')
- .alias('types', 'T')
- .alias('timeout', 't')
- .alias('reporter', 'R')
- .alias('help', 'h')
- .argv;
+ .usage("Usage: $0 -t [types] --reporter [reporter] --timeout [timeout]")
+ .default({types: 'unit,functional', reporter: 'spec', timeout: 6000})
+ .describe('types', 'The types of tests to run, separated by commas. E.g., unit,functional,acceptance')
+ .describe('reporter', 'The mocha test reporter to use.')
+ .describe('timeout', 'The mocha timeout to use per test (ms).')
+ .boolean('help')
+ .alias('types', 'T')
+ .alias('timeout', 't')
+ .alias('reporter', 'R')
+ .alias('help', 'h')
+ .argv;
var mocha = new Mocha({timeout: argv.timeout, reporter: argv.reporter, ui: 'bdd'});
@@ -26,43 +26,43 @@ var requested_types = argv.types.split(',');
var types_to_use = [];
valid_test_types.forEach(function (valid_test_type) {
- if (requested_types.indexOf(valid_test_type) !== -1) {
- types_to_use.push(valid_test_type);
- }
+ if (requested_types.indexOf(valid_test_type) !== -1) {
+ types_to_use.push(valid_test_type);
+ }
});
if (argv.help || types_to_use.length === 0) {
- console.log('\n' + optimist.help());
- process.exit();
+ console.log('\n' + optimist.help());
+ process.exit();
}
var is_valid_file = function (file) {
- for (var i = 0; i < types_to_use.length; i++) {
- var test_type = types_to_use[i];
- var ext = test_type + ".js";
+ for (var i = 0; i < types_to_use.length; i++) {
+ var test_type = types_to_use[i];
+ var ext = test_type + ".js";
- if (file.indexOf(ext) !== -1) {
- return true;
- }
+ if (file.indexOf(ext) !== -1) {
+ return true;
}
+ }
- return false;
+ return false;
};
function run(cb) {
- walk_dir.walk('test', is_valid_file, function (err, files) {
- if (err) { return cb(err); }
-
- files.forEach(function (file) {
- mocha.addFile(file);
- });
+ walk_dir.walk('test', is_valid_file, function (err, files) {
+ if (err) { return cb(err); }
- cb();
+ files.forEach(function (file) {
+ mocha.addFile(file);
});
+
+ cb();
+ });
}
run(function (err) {
- mocha.run(function (failures) {
- process.exit(failures);
- });
+ mocha.run(function (failures) {
+ process.exit(failures);
+ });
});
diff --git a/test/system.unit.js b/test/system.unit.js
index 0198af62..004460d2 100644
--- a/test/system.unit.js
+++ b/test/system.unit.js
@@ -1,47 +1,47 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
describe("system.js", function () {
- describe("directoryPath()", function () {
- it("returns unix fs directory full path", function () {
- sinon.stub(faker.random, 'words').returns('24/7');
- var directoryPath = faker.system.directoryPath();
- assert.strictEqual(directoryPath.indexOf('/'), 0, 'generated directoryPath should start with /');
+ describe("directoryPath()", function () {
+ it("returns unix fs directory full path", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var directoryPath = faker.system.directoryPath();
+ assert.strictEqual(directoryPath.indexOf('/'), 0, 'generated directoryPath should start with /');
- faker.random.words.restore();
- });
+ faker.random.words.restore();
});
+ });
- describe("filePath()", function () {
- it("returns unix fs file full path", function () {
- sinon.stub(faker.random, 'words').returns('24/7');
- var filePath = faker.system.filePath();
- assert.strictEqual(filePath.indexOf('/'), 0, 'generated filePath should start with /');
+ describe("filePath()", function () {
+ it("returns unix fs file full path", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var filePath = faker.system.filePath();
+ assert.strictEqual(filePath.indexOf('/'), 0, 'generated filePath should start with /');
- faker.random.words.restore();
- });
+ faker.random.words.restore();
});
+ });
- describe("fileName()", function () {
- it("returns filenames without system path seperators", function () {
- sinon.stub(faker.random, 'words').returns('24/7');
- var fileName = faker.system.fileName();
- assert.strictEqual(fileName.indexOf('/'), -1, 'generated fileNames should not have path seperators');
+ describe("fileName()", function () {
+ it("returns filenames without system path seperators", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var fileName = faker.system.fileName();
+ assert.strictEqual(fileName.indexOf('/'), -1, 'generated fileNames should not have path seperators');
- faker.random.words.restore();
- });
+ faker.random.words.restore();
});
+ });
- describe("commonFileName()", function () {
- it("returns filenames without system path seperators", function () {
- sinon.stub(faker.random, 'words').returns('24/7');
- var fileName = faker.system.commonFileName();
- assert.strictEqual(fileName.indexOf('/'), -1, 'generated commonFileNames should not have path seperators');
+ describe("commonFileName()", function () {
+ it("returns filenames without system path seperators", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var fileName = faker.system.commonFileName();
+ assert.strictEqual(fileName.indexOf('/'), -1, 'generated commonFileNames should not have path seperators');
- faker.random.words.restore();
- });
+ faker.random.words.restore();
});
+ });
});
diff --git a/test/time.unit.js b/test/time.unit.js
index 7b2c7bae..4a278129 100644
--- a/test/time.unit.js
+++ b/test/time.unit.js
@@ -1,30 +1,30 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
}
faker.seed(1234);
describe("time.js", function () {
- describe("recent()", function () {
- it("returns the recent timestamp in Unix time format", function () {
- var date = faker.time.recent();
- assert.ok(typeof date === 'number');
- // assert.ok(date == new Date().getTime());
- });
+ describe("recent()", function () {
+ it("returns the recent timestamp in Unix time format", function () {
+ var date = faker.time.recent();
+ assert.ok(typeof date === 'number');
+ // assert.ok(date == new Date().getTime());
+ });
- it("returns the recent timestamp in full time string format", function () {
- var date = faker.time.recent('wide');
- assert.ok(typeof date === 'string');
- // assert.ok(date == new Date().toTimeString());
- });
+ it("returns the recent timestamp in full time string format", function () {
+ var date = faker.time.recent('wide');
+ assert.ok(typeof date === 'string');
+ // assert.ok(date == new Date().toTimeString());
+ });
- it("returns the recent timestamp in abbreviated string format", function () {
- var date = faker.time.recent('abbr');
- assert.ok(typeof date === 'string');
- // assert.ok(date == new Date().toLocaleTimeString());
- });
+ it("returns the recent timestamp in abbreviated string format", function () {
+ var date = faker.time.recent('abbr');
+ assert.ok(typeof date === 'string');
+ // assert.ok(date == new Date().toLocaleTimeString());
});
+ });
});
diff --git a/test/unique.unit.js b/test/unique.unit.js
index 3681e0b3..b312fb7f 100644
--- a/test/unique.unit.js
+++ b/test/unique.unit.js
@@ -1,54 +1,54 @@
if (typeof module !== 'undefined') {
- var assert = require('assert');
- var sinon = require('sinon');
- var faker = require('../index');
+ 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.strictEqual(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 same 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.strictEqual(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.strictEqual(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.strictEqual(err.message.substr(0, 19), 'Exceeded maxRetries');
- }
- });
-
- it("is able to call last 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/));
- });
+ 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.strictEqual(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 same 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.strictEqual(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.strictEqual(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.strictEqual(err.message.substr(0, 19), 'Exceeded maxRetries');
+ }
+ });
+
+ it("is able to call last 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/));
+ });
+
+ });
});
diff --git a/test/vehicle.unit.js b/test/vehicle.unit.js
index 80504581..eca19bf6 100644
--- a/test/vehicle.unit.js
+++ b/test/vehicle.unit.js
@@ -6,71 +6,71 @@ if (typeof module !== 'undefined') {
describe("vehicle.js", function () {
describe("vehicle()", function () {
- it("returns a random vehicle", function () {
- sinon.stub(faker.vehicle, 'vehicle').returns('Ford Explorer');
- var vehicle = faker.vehicle.vehicle();
+ it("returns a random vehicle", function () {
+ sinon.stub(faker.vehicle, 'vehicle').returns('Ford Explorer');
+ var vehicle = faker.vehicle.vehicle();
- assert.strictEqual(vehicle, 'Ford Explorer');
- faker.vehicle.vehicle.restore();
- });
+ assert.strictEqual(vehicle, 'Ford Explorer');
+ faker.vehicle.vehicle.restore();
+ });
});
describe("manufacturer()", function () {
- it("returns random manufacturer", function () {
- sinon.stub(faker.vehicle, 'manufacturer').returns('Porsche');
- var manufacturer = faker.vehicle.manufacturer();
+ it("returns random manufacturer", function () {
+ sinon.stub(faker.vehicle, 'manufacturer').returns('Porsche');
+ var manufacturer = faker.vehicle.manufacturer();
- assert.strictEqual(manufacturer, 'Porsche');
- faker.vehicle.manufacturer.restore();
- });
+ assert.strictEqual(manufacturer, 'Porsche');
+ faker.vehicle.manufacturer.restore();
+ });
});
describe("type()", function () {
it("returns random vehicle type", function () {
sinon.stub(faker.vehicle, 'type').returns('Minivan');
- var type = faker.vehicle.type();
+ var type = faker.vehicle.type();
- assert.strictEqual(type, 'Minivan');
- faker.vehicle.type.restore();
- });
+ assert.strictEqual(type, 'Minivan');
+ faker.vehicle.type.restore();
+ });
});
describe("fuel()", function () {
- it("returns a fuel type", function () {
- sinon.stub(faker.vehicle, 'fuel').returns('Hybrid');
- var fuel = faker.vehicle.fuel();
+ it("returns a fuel type", function () {
+ sinon.stub(faker.vehicle, 'fuel').returns('Hybrid');
+ var fuel = faker.vehicle.fuel();
- assert.strictEqual(fuel, 'Hybrid');
- faker.vehicle.fuel.restore();
- });
+ assert.strictEqual(fuel, 'Hybrid');
+ faker.vehicle.fuel.restore();
+ });
});
describe("vin()", function () {
- it("returns valid vin number", function () {
- var vin = faker.vehicle.vin();
- assert.ok(vin.match(/^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/));
- });
+ it("returns valid vin number", function () {
+ var vin = faker.vehicle.vin();
+ assert.ok(vin.match(/^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/));
+ });
});
describe("color()", function () {
- it("returns a random color", function () {
- sinon.stub(faker.vehicle, 'color').returns('black');
- var color = faker.vehicle.color();
+ it("returns a random color", function () {
+ sinon.stub(faker.vehicle, 'color').returns('black');
+ var color = faker.vehicle.color();
- assert.strictEqual(color, 'black');
- faker.vehicle.color.restore();
- });
+ assert.strictEqual(color, 'black');
+ faker.vehicle.color.restore();
+ });
});
- describe("vrm()", function () {
- it("returns a random vrm", function () {
- sinon.stub(faker.vehicle, 'vrm').returns('MF59EEW');
- var vrm = faker.vehicle.vrm();
+ describe("vrm()", function () {
+ it("returns a random vrm", function () {
+ sinon.stub(faker.vehicle, 'vrm').returns('MF59EEW');
+ var vrm = faker.vehicle.vrm();
- assert.equal(vrm, 'MF59EEW');
- faker.vehicle.vrm.restore();
- });
+ assert.equal(vrm, 'MF59EEW');
+ faker.vehicle.vrm.restore();
});
+ });
describe("bicycle()", function () {
it("returns a random type of bicycle", function () {