Skip to content

Commit

Permalink
Merge pull request #994 from Lukazovic/Lukazovic-fix/amount-return-st…
Browse files Browse the repository at this point in the history
…ring

Fix return of finance.amount to string
  • Loading branch information
Marak authored Sep 6, 2020
2 parents 81f1adf + 30bc715 commit 46ad73d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var Finance = function (faker) {
var randValue = faker.random.number({ max: max, min: min, precision: Math.pow(10, -dec) });
var stringNumber = symbol + randValue.toFixed(dec);

return Number(stringNumber);
return symbol + randValue.toFixed(dec);
};

/**
Expand Down
19 changes: 9 additions & 10 deletions test/finance.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ describe('finance.js', function () {

});

/*
Remark: This needs to be fixed now see: https://github.com/Marak/faker.js/issues/984
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 () {

Expand Down Expand Up @@ -203,25 +202,25 @@ 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 () {

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");
});

});
Expand Down

0 comments on commit 46ad73d

Please sign in to comment.