aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorborel <pbborel.gmail.com>2020-11-11 14:52:02 +0100
committerborel <pbborel.gmail.com>2020-11-11 14:52:02 +0100
commit9dc301f22680ff7edaf0c0b68e001281ff4b9ac7 (patch)
tree9e9d877fe94276af4825538b7eda8d8f290dcfc1 /test
parent4d08fa776fe164f748fdde29e8e7e0296723ad02 (diff)
parent91dc8a3372426bc691be56153b33e81a16459f49 (diff)
downloadfaker-9dc301f22680ff7edaf0c0b68e001281ff4b9ac7.tar.xz
faker-9dc301f22680ff7edaf0c0b68e001281ff4b9ac7.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'test')
-rw-r--r--test/finance.unit.js17
-rw-r--r--test/music.unit.js17
-rw-r--r--test/name.unit.js45
3 files changed, 71 insertions, 8 deletions
diff --git a/test/finance.unit.js b/test/finance.unit.js
index a5a2c354..8935eaaa 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -163,15 +163,16 @@ describe('finance.js', function () {
it("should use the default decimal location when not passing arguments", function () {
- var amount = faker.finance.amount().toString();
+ var amount = faker.finance.amount();
var decimal = '.';
var expected = amount.length - 3;
- var actual = amount.indexOf(decimal);
+ var amount = faker.finance.amount(100, 100, 1);
- assert.equal(actual, expected, 'The expected location of the decimal is ' + expected + ' but it was ' + actual + ' amount ' + amount);
+ assert.ok(amount);
+ assert.strictEqual(amount , '100.0', "the amount should be equal 100.0");
});
-
+
//TODO: add support for more currency and decimal options
it("should not include a currency symbol by default", function () {
@@ -201,7 +202,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 () {
@@ -209,17 +210,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() {
+ it("it should return a string", 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");
+ assert.strictEqual(typeOfAmount , "string", "the amount type should be number");
});
});
diff --git a/test/music.unit.js b/test/music.unit.js
new file mode 100644
index 00000000..df679333
--- /dev/null
+++ b/test/music.unit.js
@@ -0,0 +1,17 @@
+if (typeof module !== 'undefined') {
+ 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();
+
+ assert.equal(genre, 'Rock');
+ faker.music.genre.restore();
+ });
+ });
+});
diff --git a/test/name.unit.js b/test/name.unit.js
index 8cf25bab..361fde4e 100644
--- a/test/name.unit.js
+++ b/test/name.unit.js
@@ -52,6 +52,51 @@ describe("name.js", function () {
});
});
+ describe("middleName()", function () {
+
+ it("returns a random middle name", function () {
+ sinon.stub(faker.name, 'middleName').returns('foo');
+
+ var middle_name = faker.name.middleName();
+
+ assert.equal(middle_name, 'foo');
+
+ faker.name.middleName.restore();
+ });
+
+ 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']
+ }
+ };
+ });
+
+ afterEach(function () {
+ faker.locale = this.oldLocale;
+ delete faker.locale['TEST'];
+ })
+
+ it("returns male prefix", function () {
+ var middle_name = faker.name.middleName(0);
+
+ assert.equal(middle_name, 'Genaddiesvich')
+ });
+
+ it("returns female prefix", function () {
+ var middle_name = faker.name.middleName(1);
+
+ assert.equal(middle_name, 'Genaddievna');
+ });
+ });
+ });
+
+
describe("findName()", function () {
it("usually returns a first name and last name", function () {
sinon.stub(faker.random, 'number').returns(5);