Skip to content

fetcher.tsのテスト環境のセットアップと実装 #14

@sakaritoru

Description

@sakaritoru

概要

fetcher.tsのユニットテストを実装するための環境整備とテストコードの実装が必要です。

必要な作業

テスト環境のセットアップ

  1. Jestのインストール
yarn add -D jest @types/jest ts-jest
  1. jest.config.jsの作成
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  transform: {
    '^.+\.ts$': 'ts-jest',
  },
  moduleFileExtensions: ['ts', 'js'],
  testMatch: ['**/__tests__/**/*.test.ts'],
};
  1. package.jsonのscriptsセクションにテストコマンドを追加
{
  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch"
  }
}

テストコードの実装予定内容

  • app/src/lib/__tests__/fetcher.test.tsを作成
  • 以下のテストケースを実装:
    1. 正常系: URLFetchAppが正常にレスポンスを返す場合
    2. 異常系: URLFetchAppがエラーを投げる場合
    3. 異常系: レスポンスのパースに失敗する場合

テスト実装時の考慮点

  • Google Apps ScriptのUrlFetchAppのモックが必要
  • テスト用のモックデータの準備が必要

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions