aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTito Nobre <[email protected]>2018-10-15 02:27:07 +0100
committerTito Nobre <[email protected]>2018-10-15 02:50:03 +0100
commit31b3f48dd11dbbeb2e7e0a8b570295322ef5443f (patch)
tree107b776cc03732a55f06bf97ca8e93f949d6cdc5
parentf4ea60e2957435a7be71509863b645b6b2b00ca8 (diff)
downloadfaker-31b3f48dd11dbbeb2e7e0a8b570295322ef5443f.tar.xz
faker-31b3f48dd11dbbeb2e7e0a8b570295322ef5443f.zip
Improve unit tests for name.findName() and name.prefix()
-rw-r--r--test/name.unit.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/name.unit.js b/test/name.unit.js
index e470cfba..679f1202 100644
--- a/test/name.unit.js
+++ b/test/name.unit.js
@@ -51,6 +51,44 @@ describe("name.js", function () {
faker.random.number.restore();
});
+ it("occasionally returns a male full name with a prefix", function () {
+ sinon.stub(faker.random, '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');
+
+ var name = faker.name.findName();
+
+ assert.equal(name, 'X Y Z');
+
+ faker.random.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.random, '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');
+
+ var name = faker.name.findName();
+
+ assert.equal(name, 'J K L');
+
+ faker.random.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.random, 'number').returns(1);
sinon.stub(faker.name, 'suffix').returns('Jr.');
@@ -103,4 +141,61 @@ describe("name.js", function () {
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.equal(prefix, 'Mp')
+ });
+
+ it("returns female prefix", function () {
+ var prefix = faker.name.prefix(1);
+
+ assert.equal(prefix, 'Fp');
+ });
+ });
+
+ 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.equal(prefix, 'P');
+ });
+ });
+ });
});