From d9f80abd06fc2d9ce935ed20f3ee86804f00b296 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Thu, 23 Nov 2023 13:58:37 +0100 Subject: [PATCH] TS: Add an Approval base test similar to Java-Approvals and CS-xunit-verify using Jest Snapshot. --- TypeScript/test/jest/approvals.spec.ts | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 TypeScript/test/jest/approvals.spec.ts diff --git a/TypeScript/test/jest/approvals.spec.ts b/TypeScript/test/jest/approvals.spec.ts new file mode 100644 index 00000000..bb7f45f9 --- /dev/null +++ b/TypeScript/test/jest/approvals.spec.ts @@ -0,0 +1,54 @@ +import { Item, GildedRose } from '@/gilded-rose'; + +/** + * This unit test uses [Jest Snapshot](https://goo.gl/fbAQLP). + * + * There are two test cases here with different styles: + *
  • "foo" is more similar to the unit test from the 'Java' version + *
  • "thirtyDays" is more similar to the TextTest from the 'Java' version + * + * I suggest choosing one style to develop and deleting the other. + */ + +describe('Gilded Rose Approval', () => { + + let gameConsoleOutput: string; + let originalConsoleLog: (message: any) => void; + let originalProcessArgv: string[] + + function gameConsoleLog(msg: string) { + if (msg) { + gameConsoleOutput += msg; + } + gameConsoleOutput += "\n"; + } + + beforeEach(() => { + // prepare capturing console.log to our own gameConsoleLog. + gameConsoleOutput = ""; + originalConsoleLog = console.log; + console.log = gameConsoleLog; + originalProcessArgv = process.argv; + }); + + afterEach(() => { + // reset original console.log + console.log = originalConsoleLog; + process.argv = originalProcessArgv; + }); + + it('should foo', () => { + const gildedRose = new GildedRose([new Item('foo', 0, 0)]); + const items = gildedRose.updateQuality(); + + expect(items).toMatchSnapshot(); + }); + + it('should thirtyDays', () => { + process.argv = ["", "