Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
テストの設置場所を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
takahash committed Oct 9, 2023
1 parent 2944c74 commit eea8572
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 112 deletions.
18 changes: 18 additions & 0 deletions __tests__/basic/script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, test, expect } from "vitest";
import { func1, func2 } from "../../basic/script";

describe("ループ・配列の問題", () => {
test("func1", () => expect(func1(5)).toEqual([1, 2, 3, 4, 5]));
test("func1", () => expect(func1(8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]));
test("func1", () => expect(func1(-1)).toEqual([]));
});

describe("条件分岐・データ型の問題", () => {
test("func2", () => expect(func2(1)).toEqual("1"));
test("func2", () => expect(func2(3)).toEqual("Fizz"));
test("func2", () => expect(func2(5)).toEqual("Buzz"));
test("func2", () => expect(func2(15)).toEqual("FizzBuzz"));
test("func2", () => expect(func2(22)).toEqual("22"));
test("func2", () => expect(func2(30)).toEqual("FizzBuzz"));
test("func2", () => expect(func2("hogehoge")).toEqual("error"));
});
4 changes: 2 additions & 2 deletions dom/script.test.ts → __tests__/dom/script.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, describe, beforeEach } from "vitest";
import { screen } from "@testing-library/dom";

import { main } from "./script";
import { main } from "../../dom/script";

beforeEach(() => {
document.body.innerHTML = `
Expand All @@ -12,7 +12,7 @@ beforeEach(() => {
`;
});

describe("", () => {
describe("DOM操作の問題", () => {
test("リンクが正しく追加されている", () => {
main();
const a = screen.queryByTestId<HTMLAnchorElement>("a");
Expand Down
14 changes: 14 additions & 0 deletions __tests__/function/script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, test, expect } from "vitest";
import { func1, func2 } from "../../function/script";

describe("関数型プログラミングの問題1", () => {
test("正しい結果が返ってきている", () => {
expect(func1()).toEqual(["Ken", "Hana"]);
});
});

describe("関数型プログラミングの問題2", () => {
test("正しい結果が返ってきている", () => {
expect(func2()).toEqual(125);
});
});
37 changes: 37 additions & 0 deletions __tests__/object/script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, test, expect } from "vitest";
import { func1, func2, func3 } from "../../object/script";

describe("オブジェクトの問題1", () => {
test("正しい結果が返ってきている", () => {
expect(func1()).toMatchObject({
firstName: "Ken",
lastName: "Takahashi",
age: 29,
gender: "male",
interests: [
{
name: "programming",
emoji: "💻",
},
{
name: "motorcycle",
emoji: "🏍",
},
],
});
});
});

describe("オブジェクトの問題2", () => {
test("正しい結果が返ってきている", () => {
expect(func2()).toEqual(
'{"firstName":"Ken","lastName":"Takahashi","age":29}'
);
});
});

describe("オブジェクトの問題3", () => {
test("正しい結果が返ってきている", () => {
expect(func3()).toEqual("Leanne Graham,[email protected]");
});
});
66 changes: 66 additions & 0 deletions __tests__/promise/script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, test, expect, vi } from "vitest";
import { func1, func2, func3 } from "../../promise/script";

const results = [
{
userId: 1,
id: 1,
title: "delectus aut autem",
completed: false,
},
{
userId: 1,
id: 2,
title: "quis ut nam facilis et officia qui",
completed: false,
},
{
userId: 1,
id: 3,
title: "fugiat veniam minus",
completed: false,
},
{
userId: 1,
id: 4,
title: "et porro tempora",
completed: true,
},
{
userId: 1,
id: 5,
title: "laboriosam mollitia et enim quasi adipisci quia provident illum",
completed: false,
},
];

describe("非同期処理の問題", () => {
test("正しい値が取得できている", async () => {
const json = await func1();
expect(json).toMatchObject(results[0]);
});
});

describe("非同期処理の問題 - 直列処理", () => {
test("正しい順番で実行できている", async () => {
const spy = vi
.spyOn(global.console, "log")
.mockImplementation((args) => args);
await func2();
for (const result of results) {
expect(spy).toHaveReturnedWith(result);
}
});
});

describe("非同期処理の問題 - 並列処理", () => {
test("正しい値が取得できている", async () => {
const json = await func3();
expect(json).toMatchObject(results);
});
test("Promise.allが使われている", async () => {
const spy = vi.spyOn(Promise, "all");
await func3();
expect(spy).toHaveBeenCalled();
});
});
14 changes: 0 additions & 14 deletions basic/script.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions function/script.test.js

This file was deleted.

31 changes: 0 additions & 31 deletions object/script.test.js

This file was deleted.

55 changes: 0 additions & 55 deletions promise/script.test.ts

This file was deleted.

0 comments on commit eea8572

Please sign in to comment.