From 34588a512e7f6656331e2e7ecb9a231213e4cd94 Mon Sep 17 00:00:00 2001 From: Derk-Jan Karrenbeld Date: Sun, 14 Mar 2021 06:54:05 +0100 Subject: [PATCH] Add tests to capture incorrect analysis --- src/analyzers/practice/two-fer/index.ts | 2 ++ test/analyzers/two-fer/issue64.ts | 30 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/analyzers/two-fer/issue64.ts diff --git a/src/analyzers/practice/two-fer/index.ts b/src/analyzers/practice/two-fer/index.ts index 9a32859c..7580ae70 100644 --- a/src/analyzers/practice/two-fer/index.ts +++ b/src/analyzers/practice/two-fer/index.ts @@ -154,6 +154,8 @@ export class TwoFerAnalyzer extends AnalyzerImpl { this.comment(NO_NAMED_EXPORT({ 'export.name': 'twoFer' })) } + console.log(exported?.node.type, this.mainMethod.body.type) + if (this.hasCommentary) { this.disapprove() } diff --git a/test/analyzers/two-fer/issue64.ts b/test/analyzers/two-fer/issue64.ts new file mode 100644 index 00000000..2ecba0ed --- /dev/null +++ b/test/analyzers/two-fer/issue64.ts @@ -0,0 +1,30 @@ +import { TwoFerAnalyzer } from '~src/analyzers/practice/two-fer' +import { makeAnalyze } from '~test/helpers/smoke' + +const analyze = makeAnalyze(() => new TwoFerAnalyzer()) + +describe('When running analysis on two-fer', () => { + it('disapproves an incorrect solution without an explicit return', async () => { + const solutionContent = ` + export const twoFer = (name = 'you') => { + console.log(\`One for \${name}, one for me.\`) + } + `.trim() + + const output = await analyze(solutionContent) + + expect(output.comments.length).toBeGreaterThan(1) + expect(output.comments[0].type).not.toBe('celebratory') + }) + + it('disapproves an incorrect solution without a return value', async () => { + const solutionContent = ` + export const twoFer = (name = 'you') => console.log(\`One for \${name}, one for me.\`) + `.trim() + + const output = await analyze(solutionContent) + + expect(output.comments.length).toBeGreaterThan(1) + expect(output.comments[0].type).not.toBe('celebratory') + }) +})