Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Nov 8, 2023
1 parent 10f6e46 commit 02c7ba7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/json-hover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ describe("JSONHover#getHoverTexts", () => {
);
expect(hoverTexts).toEqual({
message: "an example oneOf",
typeInfo: "oneOf: `string`, `array`, or `boolean`",
typeInfo:
"oneOf: <code>string</code>, <code>array</code>, or <code>boolean</code>",
});
});
it("should provide oneOf texts with valid values", async () => {
Expand All @@ -86,7 +87,8 @@ describe("JSONHover#getHoverTexts", () => {
);
expect(hoverTexts).toEqual({
message: "an example oneOf",
typeInfo: "oneOf: `string`, `array`, or `boolean`",
typeInfo:
"oneOf: <code>string</code>, <code>array</code>, or <code>boolean</code>",
});
});
});
Expand Down
16 changes: 11 additions & 5 deletions src/__tests__/json-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ const expectErrors = (
describe("json-validation", () => {
it("should provide range for a value error", () => {
expectErrors('{"foo": 123}', [
[8, 11, "Expected `string` but received `number`"],
[8, 11, "Expected <code>string</code> but received <code>number</code>"],
]);
});
it("should provide range for an unknown key error", () => {
expectErrors('{"foo": "example", "bar": 123}', [
[19, 24, "Additional property `bar` is not allowed"],
[19, 24, "Additional property <code>bar</code> is not allowed"],
]);
});
it("should not handle invalid json", () => {
expectErrors('{"foo": "example" "bar": 123}', []);
});
it("should provide range for invalid multline json", () => {
it("should provide range for invalid multiline json", () => {
expectErrors(
`{
"foo": "example",
"bar": "something else"
}`,
[[32, 37, "Additional property `bar` is not allowed"]]
[[32, 37, "Additional property <code>bar</code> is not allowed"]]
);
});
it("should provide formatted error message for oneOf fields with more than 2 items", () => {
Expand All @@ -63,7 +63,13 @@ describe("json-validation", () => {
"foo": "example",
"oneOfEg": 123
}`,
[[43, 46, 'Expected one of `"string"`, `"array"`, or `"boolean"`']],
[
[
43,
46,
"Expected one of <code>string</code>, <code>array</code>, or <code>boolean</code>",
],
],
testSchema2
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/json-hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
isJsonError,
} from "json-schema-library";

import { JSONMode, jsonPointerForPosition } from "./utils/jsonPointers.js";
import { jsonPointerForPosition } from "./utils/jsonPointers.js";
import { joinWithOr } from "./utils/formatting.js";
import { debug } from "./utils/debug.js";
import { Side } from "./types.js";
import { el } from "./utils/dom.js";
import { getJSONSchema } from "./state.js";

export type CursorData = { schema?: JsonSchema; pointer: string };

Expand Down Expand Up @@ -93,7 +94,6 @@ export class JSONHover {
let subSchema = this.schema.getSchema({
pointer,
data,
schema: this._schema,
withSchemaWarning: true,
});
if (isJsonError(subSchema)) {
Expand Down

0 comments on commit 02c7ba7

Please sign in to comment.