aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarak <[email protected]>2021-10-16 14:56:01 -0400
committerGitHub <[email protected]>2021-10-16 14:56:01 -0400
commit58dedb90efa59e4c7e9c481d9466f2b23ae30477 (patch)
treeb9f669d96a3709ff98d66a9aa8208160c113dec0
parentdae790119f20a6d0a9d8ab98d8d7f4aaaa19853b (diff)
parenta5f25f7fa1027df4b2e522728a3279f7f76e85ff (diff)
downloadfaker-58dedb90efa59e4c7e9c481d9466f2b23ae30477.tar.xz
faker-58dedb90efa59e4c7e9c481d9466f2b23ae30477.zip
Merge pull request #1225 from edwinsamodra/create-bigInt
rebuild bigInt generator pull request
-rw-r--r--lib/datatype.js14
-rw-r--r--test/datatype.unit.js23
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/datatype.js b/lib/datatype.js
index 02ea3759..63ebd65c 100644
--- a/lib/datatype.js
+++ b/lib/datatype.js
@@ -220,6 +220,20 @@ function Datatype (faker, seed) {
};
+ /**
+ * returns a Big Integer with values generated by faker.datatype.bigInt
+ * @method faker.datatype.bigInt
+ * @param { number } value
+ */
+
+ this.bigInt = function bigInt(value) {
+ if(value === undefined){
+ value = Math.floor(Math.random() * 99999999999) + 10000000000;
+ }
+
+ return BigInt(value);
+ };
+
return this;
}
diff --git a/test/datatype.unit.js b/test/datatype.unit.js
index b206ca47..84a24fd5 100644
--- a/test/datatype.unit.js
+++ b/test/datatype.unit.js
@@ -286,4 +286,27 @@ describe("datatype.js", function () {
});
});
+ describe('bigInt', function () {
+ it('should generate a bigInt value', function () {
+ var generateBigInt = faker.datatype.bigInt();
+ assert.strictEqual(typeof generateBigInt, 'bigint');
+ });
+
+ it('Generate and compare two numbers of data type BigInt, with seeding', function () {
+ faker.seed(123);
+ var generateBigInt1 = faker.datatype.bigInt();
+ faker.seed(123);
+ var generateBigInt2 = faker.datatype.bigInt();
+ assert.strictEqual(generateBigInt1, generateBigInt2);
+ });
+
+ it('summing with the Number datatype should be an error', function(done) {
+ try {
+ faker.datatype.bigInt() + 10
+ } catch (error) {
+ done();
+ }
+ });
+ });
+
}); \ No newline at end of file