From eff5f648a8d6f23fb1e675368ab38ef5a6f96668 Mon Sep 17 00:00:00 2001 From: ssube Date: Wed, 13 Nov 2019 07:26:09 -0600 Subject: [PATCH] lint(tests): helper for friendly error tests --- test/rule/TestSchemaRule.ts | 67 +++++++++++++++---------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/test/rule/TestSchemaRule.ts b/test/rule/TestSchemaRule.ts index 01b91c3..fbe5865 100644 --- a/test/rule/TestSchemaRule.ts +++ b/test/rule/TestSchemaRule.ts @@ -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', () => { it('should have a 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 { ctx } = createErrorContext(); const err = friendlyError(ctx, { dataPath: 'test-path', keyword: TEST_NAME, @@ -190,27 +196,8 @@ describe('friendly errors', () => { }); it('should handle errors with an existing message', () => { + const { ctx } = createErrorContext(); 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, { dataPath: 'test-path', keyword: TEST_NAME,