Skip to content

Commit

Permalink
fix(test): test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chantouchsek committed Jan 18, 2023
1 parent ce1031e commit ba7d69e
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 1,573 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "dist/index.d.ts",
"scripts": {
"test": "vitest --run",
"test:cov": "vitest run --coverage",
"test:watch": "yarnr test",
"build": "yarn clean && tsc",
"watch": "tsc -w",
Expand Down Expand Up @@ -54,6 +55,7 @@
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"@vitest/coverage-c8": "^0.27.2",
"@vue/test-utils": "^1.2.2",
"axios-mock-adapter": "^1.20.0",
"eslint": "^8.13.0",
Expand All @@ -62,6 +64,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.1",
"jsdom": "^21.0.0",
"lint-staged": ">=10",
"nodemon": "^2.0.12",
"nuxt-edge": "^2.16.0-27217455.034b9901",
Expand Down
26 changes: 0 additions & 26 deletions src/__tests__/__snapshots__/package.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,3 @@ exports[`Vue Api Queries > Get plugin installed 1`] = `
/>
</body>
`;
exports[`Vue Api Queries Get errors from vue component 1`] = `
Object {
"$_vueTestUtils_original": [Circular],
"_Ctor": Object {},
"data": [Function],
"name": undefined,
"render": [Function],
"staticRenderFns": Array [],
"template": "
<div>
<input type=\\"checkbox\\" name=\\"t1\\" class=\\"foo\\" v-model=\\"t1\\" />
<input type=\\"radio\\" name=\\"t2\\" class=\\"foo\\" value=\\"foo\\" v-model=\\"t2\\"/>
<input type=\\"radio\\" name=\\"t2\\" class=\\"bar\\" value=\\"bar\\" v-model=\\"t2\\"/>
<span id=\\"age\\">{{ $errors.first('age') }}</span>
</div>",
}
`;
exports[`Vue Api Queries Get plugin installed 1`] = `
<body>
<div
data-app="true"
/>
</body>
`;
11 changes: 4 additions & 7 deletions src/core/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ class Validator {

first(field: string | string[]): string | object {
if (Array.isArray(field)) {
for (let i = 0; i < field.length; i++) {
if (!has(this.errors, field[i])) {
continue
}
return this.first(field[i])
for (const f of field) {
if (has(this.errors, f)) return this.first(f)
}
}
const value = this.get(field as string)
const value = this.get(field)
if (Array.isArray(value)) return value[0]
return value
}
Expand Down Expand Up @@ -89,7 +86,7 @@ class Validator {
return Object.keys(errors).length > 0
}

get(field: string): string | string[] {
get(field: string | string[]): string | string[] {
return get(this.errors, field, [])
}

Expand Down
Loading

0 comments on commit ba7d69e

Please sign in to comment.