Skip to content

Commit 79dace8

Browse files
committed
feat: test perform
1 parent 1e3b486 commit 79dace8

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
yarn.lock
2+
yarn.lock
3+
coverage
4+
.nyc_output

.nycrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"branches": 100,
3+
"lines": 100,
4+
"functions": 100,
5+
"statements": 100,
6+
"checkCoverage": true,
7+
"reporter": ["html", "text"]
8+
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
"author": "Saamu192 <samuelpr192@gmail.com>",
77
"license": "MIT",
88
"scripts": {
9-
"dev": "npx nodemon --ignore database.json --exec node --experimental-json-modules src/index.js"
9+
"dev": "npx nodemon --ignore database.json --exec node --experimental-json-modules src/index.js",
10+
"test": "npx mocha -w --parallel test/*.test.js",
11+
"test:cov": "npx nyc npx mocha -r reify --parallel test/*.test.js"
1012
},
1113
"dependencies": {
1214
"chalk": "^5.1.2",
1315
"chalk-table": "^1.0.2",
1416
"draftlog": "^1.0.13"
1517
},
1618
"devDependencies": {
17-
"nodemon": "^2.0.20"
19+
"chai": "^4.3.6",
20+
"mocha": "^10.1.0",
21+
"nodemon": "^2.0.20",
22+
"nyc": "^15.1.0",
23+
"reify": "^0.20.12",
24+
"sinon": "^14.0.1"
1825
}
1926
}

test/person.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import mocha from "mocha";
2+
const { describe, it } = mocha;
3+
import chai from "chai";
4+
const { expect } = chai;
5+
import Person from "../src/persons.js";
6+
7+
describe("Person", () => {
8+
it("should return a person instance from a string", () => {
9+
const person = Person.generateInstanceFromString(
10+
"1 Bike,Carro 20000 2020-01-01 2020-02-01"
11+
);
12+
const expected = {
13+
from: "2020-01-01",
14+
to: "2020-02-01",
15+
vehicles: ["Bike", "Carro"],
16+
kmTraveled: "20000",
17+
id: "1",
18+
};
19+
20+
expect(person).to.be.deep.equal(expected);
21+
});
22+
23+
it("should format values", () => {
24+
const person = new Person({
25+
from: "2020-01-01",
26+
to: "2020-02-01",
27+
vehicles: ["Bike", "Carro"],
28+
kmTraveled: "20000",
29+
id: "1",
30+
});
31+
32+
const result = person.formatted("pt-BR");
33+
const expected = {
34+
id: 1,
35+
vehicles: "Bike e Carro",
36+
kmTraveled: "20.000 km",
37+
from: "01 de janeiro de 2020",
38+
to: "01 de fevereiro de 2020",
39+
};
40+
expect(result).to.be.deep.equal(expected);
41+
});
42+
});

0 commit comments

Comments
 (0)