1
0
Fork 0

lint(tests): helper for friendly error tests

This commit is contained in:
ssube 2019-11-13 07:26:09 -06:00
parent 0eae9e63e5
commit eff5f648a8
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
1 changed files with 27 additions and 40 deletions

View File

@ -158,28 +158,34 @@ describeLeaks('schema rule', async () => {
}); });
}); });
function createErrorContext() {
const rule = new SchemaRule({
check: {},
desc: TEST_NAME,
level: LogLevel.Info,
name: TEST_NAME,
select: '',
tags: [TEST_NAME],
});
const ctx = new VisitorContext({
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
});
ctx.visitData = {
itemIndex: 0,
rule,
};
return { ctx, rule };
}
describe('friendly errors', () => { describe('friendly errors', () => {
it('should have a message', () => { it('should have a message', () => {
const rule = new SchemaRule({ const { ctx } = createErrorContext();
check: {},
desc: TEST_NAME,
level: LogLevel.Info,
name: TEST_NAME,
select: '',
tags: [TEST_NAME],
});
const ctx = new VisitorContext({
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
});
ctx.visitData = {
itemIndex: 0,
rule,
};
const err = friendlyError(ctx, { const err = friendlyError(ctx, {
dataPath: 'test-path', dataPath: 'test-path',
keyword: TEST_NAME, keyword: TEST_NAME,
@ -190,27 +196,8 @@ describe('friendly errors', () => {
}); });
it('should handle errors with an existing message', () => { it('should handle errors with an existing message', () => {
const { ctx } = createErrorContext();
const TEST_MESSAGE = 'test-message'; const TEST_MESSAGE = 'test-message';
const rule = new SchemaRule({
check: {},
desc: TEST_NAME,
level: LogLevel.Info,
name: TEST_NAME,
select: '',
tags: [TEST_NAME],
});
const ctx = new VisitorContext({
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
});
ctx.visitData = {
itemIndex: 0,
rule,
};
const err = friendlyError(ctx, { const err = friendlyError(ctx, {
dataPath: 'test-path', dataPath: 'test-path',
keyword: TEST_NAME, keyword: TEST_NAME,