From 4a5de1ab467cba4dd4b61ed5a16f6816fb7c38f9 Mon Sep 17 00:00:00 2001 From: FotoVerite Date: Mon, 27 Oct 2014 15:04:44 -0400 Subject: adds ability to get random country code and tests. --- test/address.unit.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/address.unit.js b/test/address.unit.js index b03a3be4..f6b299a1 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -63,7 +63,7 @@ describe("address.js", function () { assert.ok(faker.address.citySuffix.calledOnce); }); }); - + describe("streetName()", function () { beforeEach(function () { @@ -100,8 +100,8 @@ describe("address.js", function () { assert.ok(faker.address.streetSuffix.calledOnce); }); }); - - + + describe("streetAddress()", function () { beforeEach(function () { @@ -157,7 +157,7 @@ describe("address.js", function () { }); }); }); - + describe("secondaryAddress()", function () { it("randomly chooses an Apt or Suite number", function () { @@ -196,6 +196,16 @@ describe("address.js", function () { }); }); + 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(); + }); + }); + describe("state()", function () { it("returns random state", function () { sinon.spy(faker.address, 'state'); -- cgit v1.2.3 From 3ee7219df7a2d5353fe171b2c30b864d5e0c3a31 Mon Sep 17 00:00:00 2001 From: JKillian Date: Tue, 9 Dec 2014 16:22:03 -0500 Subject: Add new jobTitle function to name object. I had to make a few concessions when doing this. Ideally I would have added this function under the 'company' module, but I chose to add it to the 'name' object instead, as the data happened to already exist in the locale files under 'name.title'. However, I felt that the field names in the locale files were confusing, so their wrappers in the name module are renamed for clarity. For example, faker.name.jobArea() returns a random element from locale.name.title.level. In my opinion, 'jobArea' was a much better description of the data than 'level'. Finally, fixed a bug in one unit test which didn't restore a function to its original state after watching it. --- test/all.functional.js | 2 +- test/internet.unit.js | 1 + test/name.unit.js | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/all.functional.js b/test/all.functional.js index 1a2e836a..0aefec5f 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -18,7 +18,7 @@ var modules = { lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'], - name: ['firstName', 'lastName', 'findName'], + name: ['firstName', 'lastName', 'findName', 'jobTitle'], phone: ['phoneNumber'], diff --git a/test/internet.unit.js b/test/internet.unit.js index 2fc0db10..ecc03c39 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -44,6 +44,7 @@ describe("internet.js", function () { faker.random.number.restore(); faker.name.firstName.restore(); faker.name.lastName.restore(); + faker.random.array_element.restore(); }); }); diff --git a/test/name.unit.js b/test/name.unit.js index b34cbd1b..a9d8fa6f 100644 --- a/test/name.unit.js +++ b/test/name.unit.js @@ -67,4 +67,25 @@ describe("name.js", function () { var name = faker.name.findName(); }); }); + + describe("jobTitle()", function () { + it("returns a job title consisting of a descriptor, area, and type", function () { + sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + assert.ok(faker.name.jobDescriptor.calledOnce); + assert.ok(faker.name.jobArea.calledOnce); + assert.ok(faker.name.jobType.calledOnce); + + faker.random.array_element.restore(); + faker.name.jobDescriptor.restore(); + faker.name.jobArea.restore(); + faker.name.jobType.restore(); + }); + }); }); -- cgit v1.2.3 From 2a46c19f932da6f08a0fc71cb92def44f4f08075 Mon Sep 17 00:00:00 2001 From: James Drew Date: Mon, 22 Dec 2014 21:52:01 +0000 Subject: Added unit test for uuid generator --- test/random.unit.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index 6071767b..da1274fd 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -61,4 +61,12 @@ describe("random.js", function () { assert.equal(opts.max, max); }); }); + + describe('UUID', function() { + it('should generate a valid UUID', function() { + var UUID = faker.random.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)); + }) + }) }); -- cgit v1.2.3 From 291464fdd87593246b51979a1ba41a03a3592683 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sun, 25 Jan 2015 15:35:36 -0500 Subject: added protocol() and url() --- test/internet.unit.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/internet.unit.js b/test/internet.unit.js index 2fc0db10..1f8893a3 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -73,6 +73,44 @@ describe("internet.js", function () { }); }); + 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.random, 'number').returns(0); + var protocol = faker.internet.protocol(); + assert.ok(protocol); + assert.strictEqual(protocol, 'http'); + + faker.random.number.restore(); + }); + + it('should occasionally return https', function () { + sinon.stub(faker.random, 'number').returns(1); + var protocol = faker.internet.protocol(); + assert.ok(protocol); + assert.strictEqual(protocol, 'https'); + + faker.random.number.restore(); + }); + }); + + 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(); + + 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(); -- cgit v1.2.3 From 3418839d8b818485331ef7931dea1de26c751da2 Mon Sep 17 00:00:00 2001 From: "rob.scott" Date: Tue, 10 Mar 2015 13:57:02 +0000 Subject: Add Commerce functions from https://github.com/stympy/faker into javascript --- test/all.functional.js | 4 +- test/commerce.unit.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 test/commerce.unit.js (limited to 'test') diff --git a/test/all.functional.js b/test/all.functional.js index 1a2e836a..966987e3 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -22,7 +22,9 @@ var modules = { phone: ['phoneNumber'], - finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol'] + finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol'], + + commerce: ['color', 'department', 'productName', 'price'] }; describe("functional tests", function () { diff --git a/test/commerce.unit.js b/test/commerce.unit.js new file mode 100644 index 00000000..856c3be6 --- /dev/null +++ b/test/commerce.unit.js @@ -0,0 +1,112 @@ +if(typeof module !== 'undefined') { + 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); + }); + }); + + 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 <= 4); + }); + + it("should return only one value if we specify a maximum of one", function() { + sinon.spy(faker.random, 'array_element'); + + var department = faker.commerce.department(1); + + assert.strictEqual(department.split(" ").length, 1); + assert.ok(faker.random.array_element.calledOnce); + + faker.random.array_element.restore(); + }); + + it("should return the maxiumum value if we specify the fixed value", function() { + sinon.spy(faker.random, 'array_element'); + + var department = faker.commerce.department(5, true); + + console.log(department); + + // account for the separator + assert.strictEqual(department.split(" ").length, 6); + // Sometimes it will generate duplicates that aren't used in the final string, + // so we check if array_element has been called exactly or more than 5 times + assert.ok(faker.random.array_element.callCount >= 5); + + faker.random.array_element.restore(); + }) + }); + + describe("productName()", function() { + it("returns name comprising of an adjective, material and product", function() { + sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + assert.ok(faker.commerce.productAdjective.calledOnce); + assert.ok(faker.commerce.productMaterial.calledOnce); + assert.ok(faker.commerce.product.calledOnce); + + faker.random.array_element.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(); + + assert.ok(price); + assert.equal((price > 0), true, "the amount should be greater than 0"); + assert.equal((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 decimal = "."; + var expected = price.length - 3; + var actual = price.indexOf(decimal); + + assert.equal(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 regexp = new RegExp(/[0-9.]/); + + var expected = true; + var actual = regexp.test(amount); + + assert.equal(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); + + assert.ok(amount); + assert.equal((amount == 0.00), true, "the amount should equal 0"); + }); + }); + +}); \ No newline at end of file -- cgit v1.2.3 From b6629e42a114b87e82130bc1e7cb01b202af8291 Mon Sep 17 00:00:00 2001 From: "rob.scott" Date: Thu, 12 Mar 2015 10:31:57 +0000 Subject: Adjusted the random test on an object as the random number generator is inclusive of the max number, so sometimes the test would fail. --- test/random.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index da1274fd..a67e42fd 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -17,7 +17,7 @@ describe("random.js", function () { it("returns a random number given a maximum value as Object", function() { var options = { max: 10 }; - assert.ok(faker.random.number(options) < options.max); + assert.ok(faker.random.number(options) <= options.max); }); it("returns a random number between a range", function() { -- cgit v1.2.3 From 22488b7b678e00b7db591f4bcd91dbdd57ed450e Mon Sep 17 00:00:00 2001 From: Evan Sharp Date: Tue, 17 Mar 2015 08:58:46 -0400 Subject: Fix random number unit test spec Updated the "returns a random number given a maximum value as Object" to include the max value in the check (changed `<` to `<=`) --- test/random.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index da1274fd..a67e42fd 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -17,7 +17,7 @@ describe("random.js", function () { it("returns a random number given a maximum value as Object", function() { var options = { max: 10 }; - assert.ok(faker.random.number(options) < options.max); + assert.ok(faker.random.number(options) <= options.max); }); it("returns a random number between a range", function() { -- cgit v1.2.3 From aa242f7a4bf0cfd15ebcb7f5dcd799d27de6792b Mon Sep 17 00:00:00 2001 From: Sherman Mui Date: Thu, 4 Jun 2015 11:43:49 -0700 Subject: Fix issue Marak/faker.js#214 with shuffle() Add a dubious spec. --- test/helpers.unit.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/helpers.unit.js b/test/helpers.unit.js index 425167e2..e58e04e7 100644 --- a/test/helpers.unit.js +++ b/test/helpers.unit.js @@ -21,6 +21,16 @@ describe("helpers.js", function () { }); }); + describe("shuffle()", function () { + it("the output is the same length as the input", function () { + sinon.spy(faker.random, 'number'); + var shuffled = faker.helpers.shuffle(["a", "b"]); + assert.ok(shuffled.length === 2); + assert.ok(faker.random.number.calledWith(1)); + faker.random.number.restore(); + }); + }); + describe("slugify()", function () { it("removes unwanted characters from URI string", function () { assert.equal(faker.helpers.slugify("Aiden.HarÂȘann"), "Aiden.Harann"); -- cgit v1.2.3 From cb82376c37716f765aee2a856567a02d1d1233ff Mon Sep 17 00:00:00 2001 From: Phil Greenberg Date: Wed, 10 Jun 2015 22:49:12 -0700 Subject: Fixing bug in random.number when max = 0 Also added tests for random.array_element --- test/random.unit.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index a67e42fd..97612c47 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -14,12 +14,16 @@ describe("random.js", function () { assert.ok(faker.random.number(max) <= max); }); - it("returns a random number given a maximum value as Object", function() { var options = { max: 10 }; assert.ok(faker.random.number(options) <= options.max); }); + it("returns a random number given a maximum value of 0", function() { + var options = { max: 0 }; + assert.ok(faker.random.number(options) === 0); + }); + it("returns a random number between a range", function() { var options = { min: 22, max: 33 }; for(var i = 0; i < 100; i++) { @@ -62,6 +66,18 @@ describe("random.js", function () { }); }); + describe('array_element', function() { + it('returns a random element in the array', function() { + var testArray = ['hello', 'to', 'you', 'my', 'friend']; + assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + }); + + it('returns a random element in the array when there is only 1', function() { + var testArray = ['hello']; + assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + }); + }); + describe('UUID', function() { it('should generate a valid UUID', function() { var UUID = faker.random.uuid(); -- cgit v1.2.3 From c0b64f7c0f9bd921a8c719a9763d4397ecbf4749 Mon Sep 17 00:00:00 2001 From: Phil Greenberg Date: Wed, 10 Jun 2015 22:58:26 -0700 Subject: Adding test for negative minimum and max = 0 --- test/random.unit.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index 97612c47..c5991d5c 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -24,6 +24,11 @@ describe("random.js", function () { assert.ok(faker.random.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.random.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++) { -- cgit v1.2.3 From 687e01b61440a638e7a28d88b33379994ac16cb2 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 10 Apr 2015 08:15:14 +0100 Subject: resolves #176 Add random boolean generator --- test/random.unit.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index c5991d5c..ad4ec1c2 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -90,4 +90,11 @@ describe("random.js", function () { assert.ok(RFC4122.test(UUID)); }) }) + + describe('boolean', function() { + it('should generate a boolean value', function() { + var bool = faker.random.boolean(); + assert.ok(typeof bool == 'boolean'); + }); + }); }); -- cgit v1.2.3 From d25a3c1e9e82d248428e2672e3ec11c8eb7636b9 Mon Sep 17 00:00:00 2001 From: Ivan Velasquez Date: Mon, 30 Mar 2015 15:29:38 -0600 Subject: add faker.name.title() tests --- test/name.unit.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/name.unit.js b/test/name.unit.js index b34cbd1b..2c358a4c 100644 --- a/test/name.unit.js +++ b/test/name.unit.js @@ -67,4 +67,16 @@ describe("name.js", function () { var name = faker.name.findName(); }); }); + + describe("title()", function () { + it("returns a random title", function () { + sinon.stub(faker.name, 'title').returns('Lead Solutions Supervisor'); + + var title = faker.name.title(); + + assert.equal(title, 'Lead Solutions Supervisor'); + + faker.name.title.restore(); + }); + }); }); -- cgit v1.2.3 From 8b7bdd431c7dd38f004847771083df6684d28f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Sat, 13 Jun 2015 17:36:13 -0300 Subject: Including a MAC Address generator --- test/internet.unit.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/internet.unit.js b/test/internet.unit.js index 1f8893a3..679881a7 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -132,4 +132,11 @@ describe("internet.js", function () { assert.ok(color.match(/^#[a-f0-9]{6}$/)); }); }); + + describe("macAddess()", 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}$/)); + }); + }); }); -- cgit v1.2.3 From 888c6469bfeec476333e16e3be4217b9cdf33753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Sat, 13 Jun 2015 17:38:59 -0300 Subject: Fixing method name references to mac generator in tests --- test/internet.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/internet.unit.js b/test/internet.unit.js index 679881a7..a18c1cc4 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -133,7 +133,7 @@ describe("internet.js", function () { }); }); - describe("macAddess()", function () { + 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}$/)); -- cgit v1.2.3 From 2907c27ca9cf3657188470094a689decda3df65a Mon Sep 17 00:00:00 2001 From: Marak Date: Sat, 4 Jul 2015 23:42:43 -0700 Subject: [api] [fix] Remove tabs from paragraph generation. Make paragraph separator configurable. Closes #223 --- test/lorem.unit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/lorem.unit.js b/test/lorem.unit.js index 3b554d47..4fecb4ba 100644 --- a/test/lorem.unit.js +++ b/test/lorem.unit.js @@ -158,7 +158,7 @@ describe("lorem.js", function () { var paragraphs = faker.lorem.paragraphs(); assert.ok(typeof paragraphs === 'string'); - var parts = paragraphs.split('\n \r\t'); + var parts = paragraphs.split('\n \r'); assert.equal(parts.length, 3); assert.ok(faker.lorem.paragraph.calledThrice); @@ -172,7 +172,7 @@ describe("lorem.js", function () { var paragraphs = faker.lorem.paragraphs(5); assert.ok(typeof paragraphs === 'string'); - var parts = paragraphs.split('\n \r\t'); + var parts = paragraphs.split('\n \r'); assert.equal(parts.length, 5); faker.lorem.paragraph.restore(); -- cgit v1.2.3 From edccd6c227773207d7e9555f2cdb466c6baf04d3 Mon Sep 17 00:00:00 2001 From: Marak Date: Sun, 5 Jul 2015 00:35:41 -0700 Subject: [fix] [minor] Typo --- test/name.unit.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/name.unit.js b/test/name.unit.js index ce4936f4..bd3d4c23 100644 --- a/test/name.unit.js +++ b/test/name.unit.js @@ -69,14 +69,17 @@ describe("name.js", function () { }); describe("title()", function () { - it("returns a random title", function () { - sinon.stub(faker.name, 'title').returns('Lead Solutions Supervisor'); + 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.equal(title, 'Lead Solutions Supervisor'); + assert.equal(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, 'array_element'); -- cgit v1.2.3 From eaf5c65cfae0a6636555884c18e6c955fae7887e Mon Sep 17 00:00:00 2001 From: Marak Date: Tue, 7 Jul 2015 16:22:50 -0700 Subject: [refactor] [dist] Allow for node to require individual locales ( to avoid the default behavior of requiring all locale data. #125 #167 --- test/all.functional.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/all.functional.js b/test/all.functional.js index 72ca2eeb..605aad2a 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -22,9 +22,9 @@ var modules = { phone: ['phoneNumber'], - finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol'], + finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol'] - commerce: ['color', 'department', 'productName', 'price'] +// commerce: ['color', 'department', 'productName', 'price'] }; describe("functional tests", function () { -- cgit v1.2.3 From ef2fca0fbff4dbc3b8970f35e5b0fc61f4c5da33 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 8 Jul 2015 14:39:35 -0700 Subject: [test] Comment out commerce test ( for now ) --- test/commerce.unit.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/commerce.unit.js b/test/commerce.unit.js index 856c3be6..ce12d3cc 100644 --- a/test/commerce.unit.js +++ b/test/commerce.unit.js @@ -1,3 +1,5 @@ +return; + if(typeof module !== 'undefined') { var assert = require('assert'), sinon = require('sinon'), -- cgit v1.2.3 From 7ce7987bf0d0a750bf40fe8405eedfa346360114 Mon Sep 17 00:00:00 2001 From: portse Date: Wed, 8 Jul 2015 23:30:20 -0400 Subject: * Added unit tests as per request in PR comment. --- test/address.unit.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/address.unit.js b/test/address.unit.js index f6b299a1..03411d25 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -216,6 +216,37 @@ describe("address.js", function () { }); }); + 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); + assert.match(zipCode, /^[A-Za-z]\d[A-Za-z]\s\d[A-Za-z]\d$/, 'Expected zip code format does not match.'); + // try another format + zipCode = faker.address.zipCode("###-###"); + assert.ok(zipCode); + assert.match(zipCode, /^\d{3}-\d{3}$/, 'Expected zip code format does not match.'); + }); + + 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); + assert.match(zipCode, /^[A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d$/, 'Expected zip code format for en_CA locale does not match.'); + }); + }); + describe("latitude()", function () { it("returns random latitude", function () { for (var i = 0; i < 100; i++) { -- cgit v1.2.3 From 2e0cb637011e43820fe1066a6ebbfb0b828ecb07 Mon Sep 17 00:00:00 2001 From: portse Date: Wed, 8 Jul 2015 23:45:09 -0400 Subject: * Fixed up assertions. --- test/address.unit.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/address.unit.js b/test/address.unit.js index 03411d25..bfe9e0ce 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -220,30 +220,24 @@ describe("address.js", 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); - assert.match(zipCode, /^[A-Za-z]\d[A-Za-z]\s\d[A-Za-z]\d$/, 'Expected zip code format does not match.'); + 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); - assert.match(zipCode, /^\d{3}-\d{3}$/, 'Expected zip code format does not match.'); + 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); - assert.match(zipCode, /^[A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d$/, 'Expected zip code format for en_CA locale does not match.'); + assert.ok(zipCode.match(/^[A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d$/)); }); }); -- cgit v1.2.3 From a118970baa9953a7fcbc9b01f7780046b3840ede Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 8 Jul 2015 20:48:15 -0700 Subject: [fix] [api] Add back commerce methods. --- test/commerce.unit.js | 165 +++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 83 deletions(-) (limited to 'test') diff --git a/test/commerce.unit.js b/test/commerce.unit.js index ce12d3cc..7abcf888 100644 --- a/test/commerce.unit.js +++ b/test/commerce.unit.js @@ -1,6 +1,4 @@ -return; - -if(typeof module !== 'undefined') { +if (typeof module !== 'undefined') { var assert = require('assert'), sinon = require('sinon'), faker = require('../index'); @@ -8,107 +6,108 @@ if(typeof module !== 'undefined') { 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); - }); - }); - - 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 <= 4); - }); - - it("should return only one value if we specify a maximum of one", function() { - sinon.spy(faker.random, 'array_element'); - - var department = faker.commerce.department(1); + 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); + }); + }); - assert.strictEqual(department.split(" ").length, 1); - assert.ok(faker.random.array_element.calledOnce); + describe("department(max, fixedValue)", function() { - faker.random.array_element.restore(); - }); + it("should use the default amounts when not passing arguments", function() { + var department = faker.commerce.department(); - it("should return the maxiumum value if we specify the fixed value", function() { - sinon.spy(faker.random, 'array_element'); + assert.ok(department.split(" ").length <= 4); + }); - var department = faker.commerce.department(5, true); + it("should return only one value if we specify a maximum of one", function() { + sinon.spy(faker.random, 'array_element'); - console.log(department); + var department = faker.commerce.department(1); - // account for the separator - assert.strictEqual(department.split(" ").length, 6); - // Sometimes it will generate duplicates that aren't used in the final string, - // so we check if array_element has been called exactly or more than 5 times - assert.ok(faker.random.array_element.callCount >= 5); + assert.strictEqual(department.split(" ").length, 1); + assert.ok(faker.random.array_element.calledOnce); - faker.random.array_element.restore(); - }) + faker.random.array_element.restore(); }); - describe("productName()", function() { - it("returns name comprising of an adjective, material and product", function() { - sinon.spy(faker.random, 'array_element'); - 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.array_element.calledThrice); - assert.ok(faker.commerce.productAdjective.calledOnce); - assert.ok(faker.commerce.productMaterial.calledOnce); - assert.ok(faker.commerce.product.calledOnce); - - faker.random.array_element.restore(); - faker.commerce.productAdjective.restore(); - faker.commerce.productMaterial.restore(); - faker.commerce.product.restore(); - }); + it("should return the maxiumum value if we specify the fixed value", function() { + sinon.spy(faker.random, 'array_element'); + + var department = faker.commerce.department(5, true); + + console.log(department); + + // account for the separator + assert.strictEqual(department.split(" ").length, 6); + // Sometimes it will generate duplicates that aren't used in the final string, + // so we check if array_element has been called exactly or more than 5 times + assert.ok(faker.random.array_element.callCount >= 5); + + faker.random.array_element.restore(); + }) + }); + + describe("productName()", function() { + it("returns name comprising of an adjective, material and product", function() { + sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + assert.ok(faker.commerce.productAdjective.calledOnce); + assert.ok(faker.commerce.productMaterial.calledOnce); + assert.ok(faker.commerce.product.calledOnce); + + faker.random.array_element.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(); + + assert.ok(price); + assert.equal((price > 0), true, "the amount should be greater than 0"); + assert.equal((price < 1001), true, "the amount should be less than 1000"); }); - describe("price(min, max, dec, symbol", function() { - it("should use the default amounts when not passing arguments", function() { - var price = faker.commerce.price(); - - assert.ok(price); - assert.equal((price > 0), true, "the amount should be greater than 0"); - assert.equal((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(); + it("should use the default decimal location when not passing arguments", function() { + 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.equal(actual, expected, "The expected location of the decimal is " + expected + " but it was " + actual + " amount " + price); - }); + assert.equal(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 () { + 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.equal(actual, expected, 'The expected match should not include a currency symbol'); - }); + assert.equal(actual, expected, 'The expected match should not include a currency symbol'); + }); - it("it should handle negative amounts, but return 0", function () { + 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.equal((amount == 0.00), true, "the amount should equal 0"); - }); + assert.ok(amount); + assert.equal((amount == 0.00), true, "the amount should equal 0"); }); + }); }); \ No newline at end of file -- cgit v1.2.3 From edb7d482a40e98ce25cd6ba296818be14f291aa1 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 8 Jul 2015 21:18:48 -0700 Subject: [fix] Comment out a few methods sections of commerce section. Needs some work. #183 --- test/commerce.unit.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/commerce.unit.js b/test/commerce.unit.js index 7abcf888..759c3962 100644 --- a/test/commerce.unit.js +++ b/test/commerce.unit.js @@ -17,10 +17,11 @@ describe("commerce.js", function() { it("should use the default amounts when not passing arguments", function() { var department = faker.commerce.department(); - - assert.ok(department.split(" ").length <= 4); + assert.ok(department.split(" ").length === 1); }); + /* + it("should return only one value if we specify a maximum of one", function() { sinon.spy(faker.random, 'array_element'); @@ -46,7 +47,8 @@ describe("commerce.js", function() { assert.ok(faker.random.array_element.callCount >= 5); faker.random.array_element.restore(); - }) + }); + */ }); describe("productName()", function() { -- cgit v1.2.3 From 4c1b454b8e3c8d87f2569a2ce0d7730dc31ee821 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 8 Jul 2015 23:56:22 -0700 Subject: [api] [refactor] Rename `array_element` and `object_element` to camelCase. Set default max random number to 99999. Added default arguments to some methods. --- test/address.unit.js | 6 +++--- test/commerce.unit.js | 20 ++++++++++---------- test/company.unit.js | 12 ++++++------ test/internet.unit.js | 6 +++--- test/name.unit.js | 6 +++--- test/random.unit.js | 6 +++--- 6 files changed, 28 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/address.unit.js b/test/address.unit.js index bfe9e0ce..1ea76452 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -161,7 +161,7 @@ describe("address.js", function () { describe("secondaryAddress()", function () { it("randomly chooses an Apt or Suite number", function () { - sinon.spy(faker.random, 'array_element'); + sinon.spy(faker.random, 'arrayElement'); var address = faker.address.secondaryAddress(); @@ -171,8 +171,8 @@ describe("address.js", function () { ]; assert.ok(address); - assert.ok(faker.random.array_element.calledWith(expected_array)); - faker.random.array_element.restore(); + assert.ok(faker.random.arrayElement.calledWith(expected_array)); + faker.random.arrayElement.restore(); }); }); diff --git a/test/commerce.unit.js b/test/commerce.unit.js index 759c3962..06445e34 100644 --- a/test/commerce.unit.js +++ b/test/commerce.unit.js @@ -23,18 +23,18 @@ describe("commerce.js", function() { /* it("should return only one value if we specify a maximum of one", function() { - sinon.spy(faker.random, 'array_element'); + sinon.spy(faker.random, 'arrayElement'); var department = faker.commerce.department(1); assert.strictEqual(department.split(" ").length, 1); - assert.ok(faker.random.array_element.calledOnce); + assert.ok(faker.random.arrayElement.calledOnce); - faker.random.array_element.restore(); + faker.random.arrayElement.restore(); }); it("should return the maxiumum value if we specify the fixed value", function() { - sinon.spy(faker.random, 'array_element'); + sinon.spy(faker.random, 'arrayElement'); var department = faker.commerce.department(5, true); @@ -43,29 +43,29 @@ describe("commerce.js", function() { // account for the separator assert.strictEqual(department.split(" ").length, 6); // Sometimes it will generate duplicates that aren't used in the final string, - // so we check if array_element has been called exactly or more than 5 times - assert.ok(faker.random.array_element.callCount >= 5); + // so we check if arrayElement has been called exactly or more than 5 times + assert.ok(faker.random.arrayElement.callCount >= 5); - faker.random.array_element.restore(); + faker.random.arrayElement.restore(); }); */ }); describe("productName()", function() { it("returns name comprising of an adjective, material and product", function() { - sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + 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.array_element.restore(); + faker.random.arrayElement.restore(); faker.commerce.productAdjective.restore(); faker.commerce.productMaterial.restore(); faker.commerce.product.restore(); diff --git a/test/company.unit.js b/test/company.unit.js index c324a4ba..f863d83d 100644 --- a/test/company.unit.js +++ b/test/company.unit.js @@ -59,19 +59,19 @@ describe("company.js", function () { describe("catchPhrase()", function () { it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () { - sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + 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.array_element.restore(); + faker.random.arrayElement.restore(); faker.company.catchPhraseAdjective.restore(); faker.company.catchPhraseDescriptor.restore(); faker.company.catchPhraseNoun.restore(); @@ -80,19 +80,19 @@ describe("company.js", function () { describe("bs()", function () { it("returns phrase comprising of a BS adjective, buzz, and noun", function () { - sinon.spy(faker.random, 'array_element'); + sinon.spy(faker.random, 'arrayElement'); sinon.spy(faker.company, 'bsAdjective'); sinon.spy(faker.company, 'bsBuzz'); sinon.spy(faker.company, 'bsNoun'); var bs = faker.company.bs(); assert.ok(typeof bs === 'string'); - assert.ok(faker.random.array_element.calledThrice); + assert.ok(faker.random.arrayElement.calledThrice); assert.ok(faker.company.bsAdjective.calledOnce); assert.ok(faker.company.bsBuzz.calledOnce); assert.ok(faker.company.bsNoun.calledOnce); - faker.random.array_element.restore(); + faker.random.arrayElement.restore(); faker.company.bsAdjective.restore(); faker.company.bsBuzz.restore(); faker.company.bsNoun.restore(); diff --git a/test/internet.unit.js b/test/internet.unit.js index 1965a1bd..9218a56e 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -33,18 +33,18 @@ describe("internet.js", function () { sinon.stub(faker.random, 'number').returns(1); sinon.spy(faker.name, 'firstName'); sinon.spy(faker.name, 'lastName'); - sinon.spy(faker.random, 'array_element'); + 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.array_element.calledWith(['.', '_'])); + assert.ok(faker.random.arrayElement.calledWith(['.', '_'])); faker.random.number.restore(); faker.name.firstName.restore(); faker.name.lastName.restore(); - faker.random.array_element.restore(); + faker.random.arrayElement.restore(); }); }); diff --git a/test/name.unit.js b/test/name.unit.js index bd3d4c23..e1d2e871 100644 --- a/test/name.unit.js +++ b/test/name.unit.js @@ -82,19 +82,19 @@ describe("name.js", function () { describe("jobTitle()", function () { it("returns a job title consisting of a descriptor, area, and type", function () { - sinon.spy(faker.random, 'array_element'); + 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.array_element.calledThrice); + 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.array_element.restore(); + faker.random.arrayElement.restore(); faker.name.jobDescriptor.restore(); faker.name.jobArea.restore(); faker.name.jobType.restore(); diff --git a/test/random.unit.js b/test/random.unit.js index ad4ec1c2..201c2267 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -71,15 +71,15 @@ describe("random.js", function () { }); }); - describe('array_element', function() { + describe('arrayElement', function() { it('returns a random element in the array', function() { var testArray = ['hello', 'to', 'you', 'my', 'friend']; - assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + assert.ok(testArray.indexOf(faker.random.arrayElement(testArray)) > -1); }); it('returns a random element in the array when there is only 1', function() { var testArray = ['hello']; - assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + assert.ok(testArray.indexOf(faker.random.arrayElement(testArray)) > -1); }); }); -- cgit v1.2.3 From af543acc8de24bd13986f53706dce3da3937f52a Mon Sep 17 00:00:00 2001 From: Marak Date: Thu, 9 Jul 2015 18:29:07 -0700 Subject: [test] [fix] Remove test for legacy method. --- test/helpers.unit.js | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test') diff --git a/test/helpers.unit.js b/test/helpers.unit.js index e58e04e7..fa2f4a90 100644 --- a/test/helpers.unit.js +++ b/test/helpers.unit.js @@ -52,14 +52,6 @@ describe("helpers.js", function () { }); }); - // Make sure we keep this function for backward-compatibility. - describe("randomNumber()", function () { - it("returns an integer", function () { - var num = faker.helpers.randomNumber(); - assert.ok(typeof num === 'number'); - }); - }); - // Make sure we keep this function for backward-compatibility. describe("randomize()", function () { it("returns a random element from an array", function () { -- cgit v1.2.3 From 40c13f210afd9a2cd5bf5f60fba7169c6e35ea44 Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Wed, 15 Jul 2015 13:31:51 -0500 Subject: Implemented faker.seed method for randomization seeding --- test/random.unit.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/random.unit.js b/test/random.unit.js index 201c2267..8f047ee5 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -65,10 +65,16 @@ describe("random.js", function () { }; faker.random.number(opts); - + assert.equal(opts.min, min); assert.equal(opts.max, max); }); + + it('should return deterministic results when seeded', function() { + faker.seed(100); + var name = faker.name.findName(); + assert.equal(name, 'Dulce Jenkins'); + }) }); describe('arrayElement', function() { -- cgit v1.2.3 From 7e1d18b7b897921e50f810bd7397dcec6f5bd40c Mon Sep 17 00:00:00 2001 From: Michael Radionov Date: Sat, 18 Jul 2015 14:38:12 +0300 Subject: Adding generators: faker.date.month(), faker.date.weekday() --- test/date.unit.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'test') diff --git a/test/date.unit.js b/test/date.unit.js index cc0cddc7..ffbc3201 100644 --- a/test/date.unit.js +++ b/test/date.unit.js @@ -78,4 +78,89 @@ describe("date.js", function () { assert.ok(date > from && date < to); }); }); + + 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.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.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); + + 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; + + 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; + }); + }); + + 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.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.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); + + 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; + + 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; + }); + }); + }); -- cgit v1.2.3 From cab6575c7378cc8f1e6426acc47fac09b415e21b Mon Sep 17 00:00:00 2001 From: Tom Collier Date: Thu, 30 Jul 2015 09:42:27 -0700 Subject: Only append suffix to streetName if suffix is present When streetSuffix returns an empty string, do not append a space to the end of the name part of streetName. With the prior behavior, occasionally, this streetName would return something like "Ashley " (notice the trailing space), which is undesirable in many circumstances. --- test/address.unit.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/address.unit.js b/test/address.unit.js index 1ea76452..b5df1d24 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -73,7 +73,6 @@ describe("address.js", function () { }); afterEach(function () { - faker.random.number.restore(); faker.name.firstName.restore(); faker.name.lastName.restore(); faker.address.streetSuffix.restore(); @@ -87,6 +86,8 @@ describe("address.js", function () { assert.ok(!faker.name.firstName.called); assert.ok(faker.name.lastName.calledOnce); assert.ok(faker.address.streetSuffix.calledOnce); + + faker.random.number.restore(); }); it("occasionally returns first name + suffix", function () { @@ -98,6 +99,16 @@ describe("address.js", function () { assert.ok(faker.name.firstName.calledOnce); assert.ok(!faker.name.lastName.called); assert.ok(faker.address.streetSuffix.calledOnce); + + faker.random.number.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(/ $/)); }); }); -- cgit v1.2.3