Skip to content

Commit

Permalink
✅ test: create tests
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 24, 2016
1 parent 9dffac8 commit 0148185
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/fakerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = function(localeID = "default") {
self.capitalize = capitalize;

self.slugify = function (str = "") {
return str.replace(/ /g, '-').replace(/[^\w\.\-]+/g, '');
return str.trim().replace(/ /g, '-').replace(/[^\w\.\-]+/g, '');
};

self.replaceSymbols = function (format, numberSymbol = "#", alphaSymbol = "\\?") {
Expand All @@ -109,6 +109,7 @@ module.exports = function(localeID = "default") {
};

self.shuffle = function (o) {
if (isNil(o)) return;
for (let j, x, i = o.length-1; i; j = self.random.number(i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
Expand Down Expand Up @@ -185,7 +186,6 @@ module.exports = function(localeID = "default") {
self[category][item] = function(...args) {
return self.populate("#{" + category + "." + item + "}", ...args);
}

}
//console.log("Set " + category + "." + item);
});
Expand Down
38 changes: 38 additions & 0 deletions test/specs/others.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from "chai";

import Fakerator from "lib/fakerator";

describe("Fakerator utils", () => {

let fakerator;

beforeEach( () => {
fakerator = new Fakerator();
fakerator.seed(4278);
});

it("check slugify function", () => {
expect(fakerator.slugify(" This is a * very_complex-text!with Extra character(s). "))
.to.be.equal("This-is-a--very_complex-textwith---Extra-characters.");
});

it("check replaceSymbols function", () => {
expect(fakerator.replaceSymbols("ABC-###-XYZ"))
.to.be.equal("ABC-445-XYZ");

expect(fakerator.replaceSymbols("???-###-???"))
.to.be.equal("arp-306-gxi");

});

it("check shuffle function", () => {
let arr = [1,2,3,4,5,6,7,8,9];

expect(fakerator.shuffle())
.to.be.undefined;

expect(fakerator.shuffle(arr))
.to.be.deep.equal([ 6, 8, 3, 1, 2, 7, 4, 5, 9 ]);

});
})
Empty file added test/specs/populate.spec.js
Empty file.
2 changes: 1 addition & 1 deletion test/specs/random.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from "chai";

import Fakerator from "lib/fakerator";

describe("Fakerator.seed", () => {
describe("Fakerator.random", () => {

let fakerator;

Expand Down
28 changes: 28 additions & 0 deletions test/specs/times.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from "chai";

import Fakerator from "lib/fakerator";

describe("Fakerator.times", () => {

let fakerator;

beforeEach( () => {
fakerator = new Fakerator();
fakerator.seed(4278);
});

it("check times function with names", () => {
let res = fakerator.times(fakerator.names.name, 3);
expect(res).to.be.an("Array");
expect(res).to.be.length(3);
expect(res).to.be.deep.equal([ "Ross Hansen", "Thomas Pfeffer", "Alexis Hauck I" ]);
});

it("check times function with random.number", () => {
let res = fakerator.times(fakerator.random.number, 10, 50, 1);
expect(res).to.be.an("Array");
expect(res).to.be.length(10);
expect(res).to.be.deep.equal( [25, 24, 29, 17, 2, 33, 1, 35, 31, 13] );
});

})

0 comments on commit 0148185

Please sign in to comment.