Skip to content

Commit

Permalink
refactor: object/array compare errmsg
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Jun 6, 2021
1 parent 8e2d223 commit 0b11e35
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import EchoClient from "./EchoClient";
import HttpClient from "./HttpClient";

export abstract class Client {
constructor(options: any) {}
constructor(_options: any) {}
abstract validate(unit: Unit);
abstract get name(): string;
abstract run(unit: Unit, req: any): Promise<any>;
Expand Down
6 changes: 4 additions & 2 deletions src/compareRes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ function compareValue(paths: string[], ctx: VmContext, v1: JsonaValue, v2: any)
const v1Keys = v1.properties.map(v => v.key);
const v2Keys = Object.keys(v2);
if (v1Keys.length !== v2Keys.length) {
throw new RunCaseError(paths, "", `keys length ${v1Keys.length}${v2Keys.length}`);
const v1x = _.difference(v1Keys, v2Keys);
const v2x = _.difference(v2Keys, v1Keys);
throw new RunCaseError(paths, "", `${JSON.stringify(v1x)}${JSON.stringify(v2x)}`);
}
}
for (const prop of v1.properties) {
Expand All @@ -91,7 +93,7 @@ function compareValue(paths: string[], ctx: VmContext, v1: JsonaValue, v2: any)
} else if (v1.type === "Array") {
if (!existAnno(paths, v1, "partial", "array")) {
if (v1.elements.length !== v2.length) {
throw new RunCaseError(paths, "", `elements length ${v1.elements.length}${v2.length}`);
throw new RunCaseError(paths, "", `size ${v1.elements.length}${v2.length}`);
}
}
for (const [i, ele] of v1.elements.entries()) {
Expand Down
12 changes: 6 additions & 6 deletions tests/__snapshots__/res.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ exports[`res data 1`] = `
fail# value not equal ✘
fail# nest value not equal ✘
fail# value type not equal ✘
fail# object prop length not equal ✘
fail# array elem length not equal ✘
fail# object not equal ✘
fail# array not equal ✘
1. fail# value not equal(main.test1)
main.test1.res.v1: 2 ≠ 3
Expand All @@ -17,11 +17,11 @@ exports[`res data 1`] = `
3. fail# value type not equal(main.test3)
main.test3.res.v1: type integer ≠ type string
4. fail# object prop length not equal(main.test4)
main.test4.res.v1: keys length 1 ≠ 2
4. fail# object not equal(main.test4)
main.test4.res.v1: [] ≠ [\\"a\\"]
5. fail# array elem length not equal(main.test5)
main.test5.res.v1: elements length 1 ≠ 2
5. fail# array not equal(main.test5)
main.test5.res.v1: size 1 ≠ 2
"
`;
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/res/data.jsona
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
v1: "3"
}
},
test4: { @describe("fail# object prop length not equal")
test4: { @describe("fail# object not equal")
req: {
v1: {
a: 3,
Expand All @@ -45,7 +45,7 @@
}
}
},
test5: { @describe("fail# array elem length not equal")
test5: { @describe("fail# array not equal")
req: {
v1: [
3,
Expand Down

0 comments on commit 0b11e35

Please sign in to comment.