aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarak <[email protected]>2020-08-25 18:45:05 -0500
committerGitHub <[email protected]>2020-08-25 18:45:05 -0500
commit9a914b148190e3276786d2b2ae8a8992f61a42d2 (patch)
treebff39c1067b4bffc4968bb7709dcbb6c009b475a /test
parentaec3829d0021cb34cd83f68603be7273543877ae (diff)
parent6a979f2652cfcd0f7dc6643eed4c35551f36ccf4 (diff)
downloadfaker-9a914b148190e3276786d2b2ae8a8992f61a42d2.tar.xz
faker-9a914b148190e3276786d2b2ae8a8992f61a42d2.zip
Merge branch 'master' into country-code-alpha-3
Diffstat (limited to 'test')
-rw-r--r--test/address.unit.js10
-rw-r--r--test/commerce.unit.js12
-rw-r--r--test/finance.unit.js37
-rw-r--r--test/helpers.unit.js13
-rw-r--r--test/image.unit.js97
-rw-r--r--test/internet.unit.js8
-rw-r--r--test/lorem.unit.js18
-rw-r--r--test/name.unit.js23
-rw-r--r--test/time.unit.js30
9 files changed, 227 insertions, 21 deletions
diff --git a/test/address.unit.js b/test/address.unit.js
index b08ef0bb..dbd6cca6 100644
--- a/test/address.unit.js
+++ b/test/address.unit.js
@@ -520,4 +520,14 @@ describe("address.js", function () {
});
});
+ 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/commerce.unit.js b/test/commerce.unit.js
index a0336c47..04d4277e 100644
--- a/test/commerce.unit.js
+++ b/test/commerce.unit.js
@@ -129,4 +129,16 @@ describe("commerce.js", function() {
});
+ describe("productDescription()", function() {
+ 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);
+
+ faker.commerce.productDescription.restore();
+ });
+ });
+
});
diff --git a/test/finance.unit.js b/test/finance.unit.js
index bad85884..a5a2c354 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -4,6 +4,7 @@ if (typeof module !== 'undefined') {
var faker = require('../index');
}
+faker.seed(1234);
describe('finance.js', function () {
describe('account( length )', function () {
@@ -160,9 +161,9 @@ describe('finance.js', function () {
});
- it("should use the defaul decimal location when not passing arguments", function () {
+ it("should use the default decimal location when not passing arguments", function () {
- var amount = faker.finance.amount();
+ var amount = faker.finance.amount().toString();
var decimal = '.';
var expected = amount.length - 3;
@@ -200,7 +201,7 @@ describe('finance.js', function () {
var amount = faker.finance.amount(100, 100, 1);
assert.ok(amount);
- assert.strictEqual(amount , '100.0', "the amount should be equal 100.0");
+ assert.strictEqual(amount , 100.0, "the amount should be equal 100.0");
});
it("it should handle argument dec = 0", function () {
@@ -208,7 +209,17 @@ describe('finance.js', function () {
var amount = faker.finance.amount(100, 100, 0);
assert.ok(amount);
- assert.strictEqual(amount , '100', "the amount should be equal 100");
+ assert.strictEqual(amount , 100, "the amount should be equal 100");
+ });
+
+ it("it should return a number", function() {
+
+ var amount = faker.finance.amount(100, 100, 0);
+
+ var typeOfAmount = typeof amount;
+
+ assert.ok(amount);
+ assert.strictEqual(typeOfAmount , 'number', "the amount type should be number");
});
});
@@ -226,7 +237,7 @@ describe('finance.js', function () {
it("returns a random currency code with a format", function () {
var currencyCode = faker.finance.currencyCode();
- assert.ok(currencyCode.match(/[A-Z]{3}/));
+ assert.ok(currencyCode.match(/^[A-Z]{3}$/));
});
});
@@ -243,6 +254,14 @@ describe('finance.js', function () {
});
});
+ describe("litecoinAddress()", function(){
+ it("returns a random litecoin address", function(){
+ var litecoinAddress = faker.finance.litecoinAddress();
+
+ assert.ok(litecoinAddress.match(/^[LM3][a-km-zA-HJ-NP-Z1-9]{26,33}$/));
+ });
+ });
+
describe("ethereumAddress()", function(){
it("returns a random ethereum address", function(){
var ethereumAddress = faker.finance.ethereumAddress();
@@ -342,4 +361,12 @@ describe('finance.js', function () {
assert.ok(bic.match(expr));
});
});
+
+ describe("transactionDescription()", function() {
+ it("returns a random transaction description", function() {
+ var transactionDescription = faker.finance.transactionDescription();
+
+ assert.ok(transactionDescription);
+ })
+ })
});
diff --git a/test/helpers.unit.js b/test/helpers.unit.js
index 5c8b31d5..f08be413 100644
--- a/test/helpers.unit.js
+++ b/test/helpers.unit.js
@@ -43,6 +43,19 @@ describe("helpers.js", 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.deepEqual(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.deepEqual(shuffled, ["b", "e", "a", "d", "j", "i", "h", "c", "g", "f"]);
+ });
});
describe("slugify()", function () {
diff --git a/test/image.unit.js b/test/image.unit.js
index 5f5e7b48..ca4c6c29 100644
--- a/test/image.unit.js
+++ b/test/image.unit.js
@@ -5,22 +5,87 @@ if (typeof module !== 'undefined') {
}
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();
+
+ assert.equal(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.equal(imageUrl, 'https://picsum.photos/100/100');
+ });
+ it("returns a random image url grayscaled", function () {
+ var imageUrl = faker.image.lorempicsum.imageUrl(100, 100, true);
+
+ assert.equal(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);
+
+ assert.equal(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);
+
+ assert.equal(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');
+
+ assert.equal(imageUrl, 'https://picsum.photos/seed/picsum/100/100');
+ });
+ });
+ describe("avatar()", function () {
+ it("return a random avatar from UIFaces", function () {
+ assert.notEqual(-1, faker.image.lorempicsum.avatar().indexOf('s3.amazonaws.com/uifaces/faces'));
+ })
+ });
+
+ describe("imageGrayscale()", function () {
+ it("returns a random URL with grayscale image", function () {
+ var imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true);
+
+ assert.equal(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.equal(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.equal(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();
- assert.equal(imageUrl, 'http://lorempixel.com/640/480');
+ assert.equal(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.equal(imageUrl, 'http://lorempixel.com/100/100');
+ assert.equal(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.equal(imageUrl, 'http://lorempixel.com/100/100/abstract');
+ assert.equal(imageUrl, 'https://lorempixel.com/100/100/abstract');
});
});
describe("avatar()", function () {
@@ -31,79 +96,79 @@ describe("image.js", function () {
describe("abstract()", function () {
it("returns a random abstract image url", function () {
var abstract = faker.image.lorempixel.abstract();
- assert.equal(abstract, 'http://lorempixel.com/640/480/abstract');
+ assert.equal(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.equal(animals, 'http://lorempixel.com/640/480/animals');
+ assert.equal(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.equal(business, 'http://lorempixel.com/640/480/business');
+ assert.equal(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.equal(cats, 'http://lorempixel.com/640/480/cats');
+ assert.equal(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.equal(city, 'http://lorempixel.com/640/480/city');
+ assert.equal(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.equal(food, 'http://lorempixel.com/640/480/food');
+ assert.equal(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.equal(nightlife, 'http://lorempixel.com/640/480/nightlife');
+ assert.equal(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.equal(fashion, 'http://lorempixel.com/640/480/fashion');
+ assert.equal(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.equal(people, 'http://lorempixel.com/640/480/people');
+ assert.equal(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.equal(nature, 'http://lorempixel.com/640/480/nature');
+ assert.equal(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.equal(sports, 'http://lorempixel.com/640/480/sports');
+ assert.equal(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.equal(technics, 'http://lorempixel.com/640/480/technics');
+ assert.equal(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.equal(transport, 'http://lorempixel.com/640/480/transport');
+ assert.equal(transport, 'https://lorempixel.com/640/480/transport');
});
});
});
diff --git a/test/internet.unit.js b/test/internet.unit.js
index 0c9bbd30..a554cea0 100644
--- a/test/internet.unit.js
+++ b/test/internet.unit.js
@@ -159,6 +159,14 @@ describe("internet.js", 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.equal(ua1, ua2);
+ });
});
describe("color()", function () {
diff --git a/test/lorem.unit.js b/test/lorem.unit.js
index 300786b8..04c03a55 100644
--- a/test/lorem.unit.js
+++ b/test/lorem.unit.js
@@ -5,6 +5,24 @@ if (typeof module !== 'undefined') {
}
describe("lorem.js", 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 '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.equal(str.length, 5);
+ });
+ });
+ });
+
describe("words()", function () {
beforeEach(function () {
sinon.spy(faker.helpers, 'shuffle');
diff --git a/test/name.unit.js b/test/name.unit.js
index d6b311a3..8cf25bab 100644
--- a/test/name.unit.js
+++ b/test/name.unit.js
@@ -5,6 +5,11 @@ if (typeof module !== 'undefined') {
}
+function assertInArray(value, array) {
+ var idx = array.indexOf(value);
+ assert.notEqual(idx, -1);
+}
+
describe("name.js", function () {
describe("firstName()", function () {
it("returns a random name", function () {
@@ -15,6 +20,24 @@ describe("name.js", function () {
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 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 () {
diff --git a/test/time.unit.js b/test/time.unit.js
new file mode 100644
index 00000000..7b2c7bae
--- /dev/null
+++ b/test/time.unit.js
@@ -0,0 +1,30 @@
+if (typeof module !== 'undefined') {
+ 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());
+ });
+
+ 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());
+ });
+ });
+
+});