Skip to content

Commit ba7d69e

Browse files
committed
fix(test): test coverage
1 parent ce1031e commit ba7d69e

File tree

4 files changed

+294
-1573
lines changed

4 files changed

+294
-1573
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"test": "vitest --run",
9+
"test:cov": "vitest run --coverage",
910
"test:watch": "yarnr test",
1011
"build": "yarn clean && tsc",
1112
"watch": "tsc -w",
@@ -54,6 +55,7 @@
5455
"@types/qs": "^6.9.7",
5556
"@typescript-eslint/eslint-plugin": "^5.9.0",
5657
"@typescript-eslint/parser": "^5.9.0",
58+
"@vitest/coverage-c8": "^0.27.2",
5759
"@vue/test-utils": "^1.2.2",
5860
"axios-mock-adapter": "^1.20.0",
5961
"eslint": "^8.13.0",
@@ -62,6 +64,7 @@
6264
"eslint-plugin-prettier": "^4.0.0",
6365
"eslint-plugin-promise": "^6.0.0",
6466
"husky": "^8.0.1",
67+
"jsdom": "^21.0.0",
6568
"lint-staged": ">=10",
6669
"nodemon": "^2.0.12",
6770
"nuxt-edge": "^2.16.0-27217455.034b9901",

src/__tests__/__snapshots__/package.spec.ts.snap

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,3 @@ exports[`Vue Api Queries > Get plugin installed 1`] = `
2525
/>
2626
</body>
2727
`;
28-
29-
exports[`Vue Api Queries Get errors from vue component 1`] = `
30-
Object {
31-
"$_vueTestUtils_original": [Circular],
32-
"_Ctor": Object {},
33-
"data": [Function],
34-
"name": undefined,
35-
"render": [Function],
36-
"staticRenderFns": Array [],
37-
"template": "
38-
<div>
39-
<input type=\\"checkbox\\" name=\\"t1\\" class=\\"foo\\" v-model=\\"t1\\" />
40-
<input type=\\"radio\\" name=\\"t2\\" class=\\"foo\\" value=\\"foo\\" v-model=\\"t2\\"/>
41-
<input type=\\"radio\\" name=\\"t2\\" class=\\"bar\\" value=\\"bar\\" v-model=\\"t2\\"/>
42-
<span id=\\"age\\">{{ $errors.first('age') }}</span>
43-
</div>",
44-
}
45-
`;
46-
47-
exports[`Vue Api Queries Get plugin installed 1`] = `
48-
<body>
49-
<div
50-
data-app="true"
51-
/>
52-
</body>
53-
`;

src/core/Validator.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@ class Validator {
4141

4242
first(field: string | string[]): string | object {
4343
if (Array.isArray(field)) {
44-
for (let i = 0; i < field.length; i++) {
45-
if (!has(this.errors, field[i])) {
46-
continue
47-
}
48-
return this.first(field[i])
44+
for (const f of field) {
45+
if (has(this.errors, f)) return this.first(f)
4946
}
5047
}
51-
const value = this.get(field as string)
48+
const value = this.get(field)
5249
if (Array.isArray(value)) return value[0]
5350
return value
5451
}
@@ -89,7 +86,7 @@ class Validator {
8986
return Object.keys(errors).length > 0
9087
}
9188

92-
get(field: string): string | string[] {
89+
get(field: string | string[]): string | string[] {
9390
return get(this.errors, field, [])
9491
}
9592

0 commit comments

Comments
 (0)