Skip to content

Commit

Permalink
chore: format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 12, 2022
1 parent 3f7d698 commit 3071af0
Show file tree
Hide file tree
Showing 32 changed files with 8,611 additions and 7,696 deletions.
418 changes: 269 additions & 149 deletions test/address.unit.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions test/all.functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ var functionalHelpers = require('./support/function-helpers.js');

var modules = functionalHelpers.modulesList();

describe("functional tests", function () {
for(var locale in faker.locales) {
describe('functional tests', function () {
for (var locale in faker.locales) {
faker.locale = locale;
Object.keys(modules).forEach(function (module) {
describe(module, function () {
modules[module].forEach(function (meth) {
it(meth + "()", function () {
it(meth + '()', function () {
var result = faker[module][meth]();
if (meth === 'boolean') {
assert.ok(result === true || result === false);
Expand All @@ -28,14 +28,14 @@ describe("functional tests", function () {
}
});

describe("faker.fake functional tests", function () {
for(var locale in faker.locales) {
describe('faker.fake functional tests', function () {
for (var locale in faker.locales) {
faker.locale = locale;
faker.seed(1);
Object.keys(modules).forEach(function (module) {
describe(module, function () {
modules[module].forEach(function (meth) {
it(meth + "()", function () {
it(meth + '()', function () {
var result = faker.fake('{{' + module + '.' + meth + '}}');
// just make sure any result is returned
// an undefined result usually means an error
Expand All @@ -52,4 +52,4 @@ describe("faker.fake functional tests", function () {
});
});
}
});
});
9 changes: 4 additions & 5 deletions test/animal.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ if (typeof module !== 'undefined') {
var faker = require('../index');
}

describe("animal.js", function() {

describe("dog()", function() {
it("returns random value from dog array", function() {
describe('animal.js', function () {
describe('dog()', function () {
it('returns random value from dog array', function () {
var dog = faker.animal.dog();
assert.ok(faker.definitions.animal.dog.indexOf(dog) !== -1);
});
});
});
});
59 changes: 31 additions & 28 deletions test/browser.unit.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../faker.js"></script>
<script src="./support/chai.js"></script>
<script src="./support/sinon-1.5.2.js"></script>
<script>assert = chai.assert;</script>
<script>mocha.setup('bdd');</script>
<script src="all.functional.js"></script>
<script src="address.unit.js"></script>
<script src="company.unit.js"></script>
<script src="helpers.unit.js"></script>
<script src="internet.unit.js"></script>
<script src="database.unit.js"></script>
<script src="datatype.unit.js"></script>
<script src="lorem.unit.js"></script>
<script src="name.unit.js"></script>
<script src="phone_number.unit.js"></script>
<script>
mocha.run();
</script>
</body>
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../faker.js"></script>
<script src="./support/chai.js"></script>
<script src="./support/sinon-1.5.2.js"></script>
<script>
assert = chai.assert;
</script>
<script>
mocha.setup('bdd');
</script>
<script src="all.functional.js"></script>
<script src="address.unit.js"></script>
<script src="company.unit.js"></script>
<script src="helpers.unit.js"></script>
<script src="internet.unit.js"></script>
<script src="database.unit.js"></script>
<script src="datatype.unit.js"></script>
<script src="lorem.unit.js"></script>
<script src="name.unit.js"></script>
<script src="phone_number.unit.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

79 changes: 46 additions & 33 deletions test/commerce.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ if (typeof module !== 'undefined') {
faker = require('../index');
}

describe("commerce.js", function() {

describe("color()", function() {
it("returns random value from commerce.color array", function() {
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() {
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);
assert.ok(department.split(' ').length === 1);
});

/*
Expand Down Expand Up @@ -51,8 +49,8 @@ describe("commerce.js", function() {
*/
});

describe("productName()", function() {
it("returns name comprising of an adjective, material and product", function() {
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');
Expand All @@ -72,65 +70,81 @@ describe("commerce.js", function() {
});
});

describe("price(min, max, dec, symbol)", function() {
it("should use the default amounts when not passing arguments", function() {
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");
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() {
it('should use the default decimal location when not passing arguments', function () {
var price = faker.commerce.price();

var decimal = ".";
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);
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 () {

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');
assert.strictEqual(
actual,
expected,
'The expected match should not include a currency symbol'
);
});

it("it should handle negative amounts, but return 0", function () {

it('it should handle negative amounts, but return 0', function () {
var amount = faker.commerce.price(-200, -1);

assert.ok(amount);
assert.strictEqual((amount == 0.00), true, "the amount should equal 0");
assert.strictEqual(amount == 0.0, true, 'the amount should equal 0');
});

it("it should handle argument dec", function () {

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");
assert.strictEqual(price, '100.0', 'the price should be equal 100.0');
});

it("it should handle argument dec = 0", function () {

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");
assert.strictEqual(price, '100', 'the price should be equal 100');
});

});

describe("productDescription()", function() {
it("returns a random product description", function() {
describe('productDescription()', function () {
it('returns a random product description', function () {
sinon.spy(faker.commerce, 'productDescription');
var description = faker.commerce.productDescription();

Expand All @@ -140,5 +154,4 @@ describe("commerce.js", function() {
faker.commerce.productDescription.restore();
});
});

});
25 changes: 12 additions & 13 deletions test/company.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ if (typeof module !== 'undefined') {
var faker = require('../index');
}

describe("company.js", function () {
describe("companyName()", function () {

it("sometimes returns three last names", function () {
describe('company.js', function () {
describe('companyName()', function () {
it('sometimes returns three last names', function () {
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.datatype, 'number').returns(2);
var name = faker.company.companyName();
Expand All @@ -20,7 +19,7 @@ describe("company.js", function () {
faker.name.lastName.restore();
});

it("sometimes returns two last names separated by a hyphen", function () {
it('sometimes returns two last names separated by a hyphen', function () {
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.datatype, 'number').returns(1);
var name = faker.company.companyName();
Expand All @@ -33,7 +32,7 @@ describe("company.js", function () {
faker.name.lastName.restore();
});

it("sometimes returns a last name with a company suffix", function () {
it('sometimes returns a last name with a company suffix', function () {
sinon.spy(faker.company, 'companySuffix');
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.datatype, 'number').returns(0);
Expand All @@ -50,15 +49,15 @@ describe("company.js", function () {
});
});

describe("companySuffix()", function () {
it("returns random value from company.suffixes array", function () {
describe('companySuffix()', function () {
it('returns random value from company.suffixes array', function () {
var suffix = faker.company.companySuffix();
assert.ok(faker.company.suffixes().indexOf(suffix) !== -1);
});
});

describe("catchPhrase()", function () {
it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
describe('catchPhrase()', function () {
it('returns phrase comprising of a catch phrase adjective, descriptor, and noun', function () {
sinon.spy(faker.random, 'arrayElement');
sinon.spy(faker.company, 'catchPhraseAdjective');
sinon.spy(faker.company, 'catchPhraseDescriptor');
Expand All @@ -78,8 +77,8 @@ describe("company.js", function () {
});
});

describe("bs()", function () {
it("returns phrase comprising of a BS buzz, adjective, and noun", function () {
describe('bs()', function () {
it('returns phrase comprising of a BS buzz, adjective, and noun', function () {
sinon.spy(faker.random, 'arrayElement');
sinon.spy(faker.company, 'bsBuzz');
sinon.spy(faker.company, 'bsAdjective');
Expand All @@ -92,7 +91,7 @@ describe("company.js", function () {
assert.ok(faker.company.bsAdjective.calledOnce);
assert.ok(faker.company.bsNoun.calledOnce);

faker.random.arrayElement.restore();
faker.random.arrayElement.restore();
faker.company.bsBuzz.restore();
faker.company.bsAdjective.restore();
faker.company.bsNoun.restore();
Expand Down
Loading

0 comments on commit 3071af0

Please sign in to comment.