From d6ee1c544f33722852b024994d150cd4703b0972 Mon Sep 17 00:00:00 2001 From: Luiz Strobelt Date: Thu, 1 Oct 2020 01:14:54 -0300 Subject: Add auto formatting to finance.amount --- test/finance.unit.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/finance.unit.js b/test/finance.unit.js index 8935eaaa..79ac26db 100644 --- a/test/finance.unit.js +++ b/test/finance.unit.js @@ -150,7 +150,7 @@ describe('finance.js', function () { }); - describe('amount(min, max, dec, symbol)', function () { + describe.only('amount(min, max, dec, symbol)', function () { it("should use the default amounts when not passing arguments", function () { var amount = faker.finance.amount(); @@ -223,6 +223,20 @@ describe('finance.js', function () { assert.strictEqual(typeOfAmount , "string", "the amount type should be number"); }); + it("should return unformatted if autoformat i false", function() { + + }); + + it("should return with a comma separator", function() { + + const symbol = "$", number = 6000, decimalPlaces = 2; + const expected = symbol + number.toLocaleString(undefined, {minimumFractionDigits: decimalPlaces}); + + const amount = faker.finance.amount(number, number, decimalPlaces, symbol, true); + + assert.strictEqual(amount, expected); + }); + }); describe('transactionType()', function () { -- cgit v1.2.3 From d9ed407cab9dd1031e20caa9ebec2612ddbd8f8e Mon Sep 17 00:00:00 2001 From: Luiz Strobelt Date: Thu, 1 Oct 2020 22:17:02 -0300 Subject: Test passing false or undefined to autoFormat --- test/finance.unit.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/finance.unit.js b/test/finance.unit.js index 79ac26db..4c0b09c9 100644 --- a/test/finance.unit.js +++ b/test/finance.unit.js @@ -150,7 +150,7 @@ describe('finance.js', function () { }); - describe.only('amount(min, max, dec, symbol)', function () { + describe('amount(min, max, dec, symbol)', function () { it("should use the default amounts when not passing arguments", function () { var amount = faker.finance.amount(); @@ -223,16 +223,22 @@ describe('finance.js', function () { assert.strictEqual(typeOfAmount , "string", "the amount type should be number"); }); - it("should return unformatted if autoformat i false", function() { + [false, undefined].forEach(function (autoFormat){ + it(`should return unformatted if autoformat is ${autoFormat}`, function() { + const number = 6000; + const amount = faker.finance.amount(number, number, 0, undefined, autoFormat); + + assert.strictEqual(amount, number.toString()); + }); }); - it("should return with a comma separator", function() { + it("should return the number formatted on the current locale", function() { - const symbol = "$", number = 6000, decimalPlaces = 2; - const expected = symbol + number.toLocaleString(undefined, {minimumFractionDigits: decimalPlaces}); + const number = 6000, decimalPlaces = 2; + const expected = number.toLocaleString(undefined, {minimumFractionDigits: decimalPlaces}); - const amount = faker.finance.amount(number, number, decimalPlaces, symbol, true); + const amount = faker.finance.amount(number, number, decimalPlaces, undefined, true); assert.strictEqual(amount, expected); }); -- cgit v1.2.3