diff options
| author | Shinigami <[email protected]> | 2022-01-21 22:29:24 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-21 22:29:24 +0100 |
| commit | 60c90028ba76b7e291fdb8152425b93c41b117c9 (patch) | |
| tree | cfaf146a883f902acc351c7c2cba095c459ec36f /test/commerce.unit.js | |
| parent | 2da0cec2f91f54f56b509414a8b29b3831d58412 (diff) | |
| download | faker-60c90028ba76b7e291fdb8152425b93c41b117c9.tar.xz faker-60c90028ba76b7e291fdb8152425b93c41b117c9.zip | |
chore(test): migrate to vitest (#235)
Diffstat (limited to 'test/commerce.unit.js')
| -rw-r--r-- | test/commerce.unit.js | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/test/commerce.unit.js b/test/commerce.unit.js deleted file mode 100644 index 5df8d400..00000000 --- a/test/commerce.unit.js +++ /dev/null @@ -1,157 +0,0 @@ -if (typeof module !== 'undefined') { - var assert = require('assert'); - var sinon = require('sinon'); - var faker = require('../lib').faker; -} - -describe('commerce.js', function () { - describe('color()', function () { - it('returns random value from commerce.color array', function () { - var color = faker.commerce.color(); - assert.ok(faker.definitions.commerce.color.indexOf(color) !== -1); - }); - }); - - describe('department(max, fixedValue)', function () { - it('should use the default amounts when not passing arguments', function () { - var department = faker.commerce.department(); - assert.ok(department.split(' ').length === 1); - }); - - /* - - it("should return only one value if we specify a maximum of one", function() { - sinon.spy(faker.random, 'arrayElement'); - - var department = faker.commerce.department(1); - - assert.strictEqual(department.split(" ").length, 1); - assert.ok(faker.random.arrayElement.calledOnce); - - faker.random.arrayElement.restore(); - }); - - it("should return the maximum value if we specify the fixed value", function() { - sinon.spy(faker.random, 'arrayElement'); - - var department = faker.commerce.department(5, true); - - console.log(department); - - // account for the separator - assert.strictEqual(department.split(" ").length, 6); - // Sometimes it will generate duplicates that aren't used in the final string, - // so we check if arrayElement has been called exactly or more than 5 times - assert.ok(faker.random.arrayElement.callCount >= 5); - - faker.random.arrayElement.restore(); - }); - */ - }); - - describe('productName()', function () { - it('returns name comprising of an adjective, material and product', function () { - sinon.spy(faker.random, 'arrayElement'); - sinon.spy(faker.commerce, 'productAdjective'); - sinon.spy(faker.commerce, 'productMaterial'); - sinon.spy(faker.commerce, 'product'); - var name = faker.commerce.productName(); - - assert.ok(name.split(' ').length >= 3); - assert.ok(faker.random.arrayElement.calledThrice); - assert.ok(faker.commerce.productAdjective.calledOnce); - assert.ok(faker.commerce.productMaterial.calledOnce); - assert.ok(faker.commerce.product.calledOnce); - - faker.random.arrayElement.restore(); - faker.commerce.productAdjective.restore(); - faker.commerce.productMaterial.restore(); - faker.commerce.product.restore(); - }); - }); - - describe('price(min, max, dec, symbol)', function () { - it('should use the default amounts when not passing arguments', function () { - var price = faker.commerce.price(); - - assert.ok(price); - assert.strictEqual( - price > 0, - true, - 'the amount should be greater than 0' - ); - assert.strictEqual( - price < 1001, - true, - 'the amount should be less than 1000' - ); - }); - - it('should use the default decimal location when not passing arguments', function () { - var price = faker.commerce.price(); - - var decimal = '.'; - var expected = price.length - 3; - var actual = price.indexOf(decimal); - - assert.strictEqual( - actual, - expected, - 'The expected location of the decimal is ' + - expected + - ' but it was ' + - actual + - ' amount ' + - price - ); - }); - - it('should not include a currency symbol by default', function () { - var amount = faker.commerce.price(); - - var regexp = new RegExp(/[0-9.]/); - - var expected = true; - var actual = regexp.test(amount); - - assert.strictEqual( - actual, - expected, - 'The expected match should not include a currency symbol' - ); - }); - - it('it should handle negative amounts, but return 0', function () { - var amount = faker.commerce.price(-200, -1); - - assert.ok(amount); - assert.strictEqual(amount == 0.0, true, 'the amount should equal 0'); - }); - - it('it should handle argument dec', function () { - var price = faker.commerce.price(100, 100, 1); - - assert.ok(price); - assert.strictEqual(price, '100.0', 'the price should be equal 100.0'); - }); - - it('it should handle argument dec = 0', function () { - var price = faker.commerce.price(100, 100, 0); - - assert.ok(price); - assert.strictEqual(price, '100', 'the price should be equal 100'); - }); - }); - - describe('productDescription()', function () { - it('returns a random product description', function () { - sinon.spy(faker.commerce, 'productDescription'); - var description = faker.commerce.productDescription(); - - assert.ok(typeof description === 'string'); - assert.ok(faker.commerce.productDescription.calledOnce); - - faker.commerce.productDescription.restore(); - }); - }); -}); |
