✅ util unit tests
This commit is contained in:
parent
b57f8b33d4
commit
01ead4f734
@ -5,10 +5,11 @@
|
|||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"start": "npm run build && node dist/",
|
||||||
|
"test": "npm run build && jest",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"build": "npx tsc -b .",
|
"build": "npx tsc -b .",
|
||||||
"generate:schema": "npx typescript-json-schema tsconfig.json '*' -o src/models/schema.json"
|
"generate:schema": "npx typescript-json-schema tsconfig.json '*' -o src/entities/schema.json"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -41,6 +42,7 @@
|
|||||||
"class-validator": "^0.13.1",
|
"class-validator": "^0.13.1",
|
||||||
"dot-prop": "^6.0.1",
|
"dot-prop": "^6.0.1",
|
||||||
"env-paths": "^2.2.1",
|
"env-paths": "^2.2.1",
|
||||||
|
"jest-test-performance": "^1.0.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"missing-native-js-functions": "^1.2.10",
|
"missing-native-js-functions": "^1.2.10",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
@ -50,5 +52,10 @@
|
|||||||
"typeorm": "^0.2.37",
|
"typeorm": "^0.2.37",
|
||||||
"typescript": "^4.3.5",
|
"typescript": "^4.3.5",
|
||||||
"typescript-json-schema": "github:fosscord/typescript-json-schema"
|
"typescript-json-schema": "github:fosscord/typescript-json-schema"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"setupFilesAfterEnv": [
|
||||||
|
"jest-test-performance"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
util/tests/validate.test.js
Normal file
27
util/tests/validate.test.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const { initDatabase } = require("../dist/util/Database");
|
||||||
|
const { User } = require("../dist/entities/User");
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await initDatabase();
|
||||||
|
|
||||||
|
new User().validate(); // initalize schema validator
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Validate model class properties", () => {
|
||||||
|
describe("validation should be faster than 20ms", () => {
|
||||||
|
expect(() => new User().validate()).toBeFasterThan(20);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("User", () => {
|
||||||
|
test("object instead of string", () => {
|
||||||
|
expect(() => {
|
||||||
|
new User({ username: {} }).validate();
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should not set opts", () => {
|
||||||
|
const user = new User({ opts: { id: 0 } });
|
||||||
|
expect(user.opts.id).not.toBe(0);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user