Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for combining schemas #29

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
run: yarn test --ci --coverage --maxWorkers=2

- name: Build
run: yarn build
run: yarn build
20 changes: 20 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ describe('betterAjvErrors', () => {
};
});

describe('combined schemas', () => {
it('should handle type errors', () => {
data = {
str: 123,
};
const combinedSchema = {type: 'boolean'};
const validateCombined = ajv.addSchema(combinedSchema).compile(schema);
validateCombined(data);
const betterErrors = betterAjvErrors({ data, schema, errors: validateCombined.errors });
expect(betterErrors).toEqual([
{
context: {
errorType: 'type',
},
message: "'str' property type must be string",
path: '{base}.str',
},
]);
});
});
describe('additionalProperties', () => {
it('should handle additionalProperties=false', () => {
data = {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7996,4 +7996,4 @@ yargs@^15.3.1:
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
Loading