mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
port typescript approval tests from jest to vitest
This commit is contained in:
parent
c4cfa7b38e
commit
673cec6f83
54
TypeScript/test/vitest/approvals.spec.ts
Normal file
54
TypeScript/test/vitest/approvals.spec.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { execSync } from "node:child_process";
|
||||||
|
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:
|
||||||
|
* <li>"foo" is more similar to the unit test from the 'Java' version
|
||||||
|
* <li>"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", () => {
|
||||||
|
execSync(`ts-node test/golden-master-text-test.ts 30`, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(gameConsoleOutput).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user