lint(tests): helper for friendly error tests
This commit is contained in:
parent
0eae9e63e5
commit
eff5f648a8
|
@ -158,8 +158,7 @@ describeLeaks('schema rule', async () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('friendly errors', () => {
|
function createErrorContext() {
|
||||||
it('should have a message', () => {
|
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
check: {},
|
check: {},
|
||||||
desc: TEST_NAME,
|
desc: TEST_NAME,
|
||||||
|
@ -180,6 +179,13 @@ describe('friendly errors', () => {
|
||||||
itemIndex: 0,
|
itemIndex: 0,
|
||||||
rule,
|
rule,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return { ctx, rule };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('friendly errors', () => {
|
||||||
|
it('should have a message', () => {
|
||||||
|
const { ctx } = createErrorContext();
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue