Skip to content

Commit 5a348cd

Browse files
author
Matteo Bilotta
committed
[ADD] Added and configured 'jest' for unit tests.
1 parent a23fdbe commit 5a348cd

File tree

7 files changed

+2918
-37
lines changed

7 files changed

+2918
-37
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
env: {
66
browser: true,
77
es2021: true,
8+
jest: true,
89
node: true
910
},
1011
extends: ["eslint:recommended"],

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
moduleNameMapper: { "^@/(.*)$": "<rootDir>/src/$1" }
8+
};

jsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": { "@/*": ["./src/*"] }
5+
},
6+
"exclude": ["node_modules"]
7+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@
3939
"ci": "yarn install --frozen-lockfile",
4040
"lint": "eslint --ignore-path .gitignore .",
4141
"lint:prod": "export NODE_ENV='production' && yarn lint",
42-
"test": "echo \"Sorry! No test specified yet. 😭\" && exit 1"
42+
"test": "jest"
4343
},
4444
"devDependencies": {
4545
"@babel/core": "^7.13.16",
4646
"@babel/eslint-parser": "^7.13.14",
4747
"@babel/plugin-proposal-class-properties": "^7.13.0",
4848
"@babel/preset-env": "^7.13.15",
4949
"eslint": "^7.25.0",
50+
"jest": "^26.6.3",
5051
"vite": "^2.2.3"
5152
}
5253
}

tests/html-element-style.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import HTMLElementStyle from "@/html-element-style";
2+
3+
const style = new HTMLElementStyle(document.body);
4+
5+
test("Valorize 'margin-top' to '10px'", () =>
6+
{
7+
style["margin-top"] = 10;
8+
9+
expect(+style.marginTop).toBe(10);
10+
expect(`${style.marginTop}`).toBe("10px");
11+
});

vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
name: "HTMLElementStyle"
88
},
99
sourcemap: true
10-
}
10+
},
11+
resolve: { alias: { "@": PATH.resolve(__dirname, "src") } }
1112
};

0 commit comments

Comments
 (0)