• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

ui5-best-practices-qunit

プラグイン
ui5
ソース
GitHub で見る ↗
説明

次のような場合に使用: - ユーザーが「QUnitテスト(JavaScriptの自動テストコード)を書く」「失敗しているQUnitテストを修正する」「QUnitモジュールを追加する」「QUnitテストを最新化する」「QUnit 1から移行する」と依頼した場合 - または assert.async、nextUIUpdate、Core.applyChanges、sinon sandbox(テストの補助ツール)、asyncTest、QUnit.module など、QUnit固有の機能や手法が言及された場合 このスキルが対応する内容: OpenUI5/SAPUI5(SAP提供のUIフレームワーク)の単体テストファイルに関する、以下のコーディング基準を網羅しています: - 変数宣言: var の代わりに const/let を使用 - 関数構文: .bind(this) の代わりにアロー関数を使用 - 非同期処理: assert.async() の代わりに async/await を使用 - 非同期テスト内に assert.expect() を必ず記述 - sinon.createSandbox() によるテスト環境の準備 - テストの意図が明確な名前付け - beforeEach/afterEach による各テストの独立性確保 - nextUIUpdate と Core.applyChanges の使い分けルール - ヘルパー関数内での try/finally によるクリーンアップ処理 - QUnit 1から QUnit 2へのグローバル変数移行 - テストコード内での非ASCII文字の回避

原文を表示

Use when the user asks to "write a QUnit test", "fix a failing QUnit test", "add a QUnit module", "modernize QUnit tests", "migrate from QUnit 1", or mentions QUnit-specific constructs such as assert.async, nextUIUpdate, Core.applyChanges, sinon sandbox, asyncTest, or QUnit.module. Covers coding standards for OpenUI5/SAPUI5 unit test files: const/let over var, arrow functions over .bind(this), async/await over assert.async(), assert.expect() in every async test, sinon.createSandbox(), descriptive test names, beforeEach/afterEach module isolation, nextUIUpdate vs Core.applyChanges rules, try/finally teardown in helpers, QUnit 1 to QUnit 2 globals migration, and non-ASCII character avoidance.

ユースケース
  • QUnitテストコードを書くとき
  • 失敗しているテストを修正するとき
  • QUnitモジュールを追加するとき
  • QUnit 1から2へ移行するとき
  • QUnit固有機能が言及されたとき
本文(日本語訳)

QUnit テストのベストプラクティス(UI5向け)

各リファレンスの読み込み時機

状況 読み込むリファレンス
QUnit テストファイルまたはモジュールを新規作成する references/writing-new-tests.md
既存のテストコードを最新化、リファクタリング、またはレビューする references/modernizing-tests.md
QUnit 1(グローバル変数: test、asyncTest、ok、stop、start)から QUnit 2 へ移行する references/modernizing-tests.md
テストで nextUIUpdate、Core.applyChanges、assert.async、フェイクタイマー、またはイベントベースの非同期処理に触れる references/async-patterns.md

何か出力する前に、リファレンスを読み込んでください。記憶に頼らないでください。


基本ルール(常に適用)

ルール 詳細
var を使わない const または let を使用。1行に1つの宣言 — カンマで連ねない
.bind(this) を使わない 独自の this が不要なコールバック関数は、アロー関数を使う
すべての async テストに assert.expect(N) 非同期コールバックが実行されない場合の見落とし合格を防ぐ。同期テストでは不要
sinon.createSandbox() を使う sinon.sandbox.create() は Sinon 5 以上で実行時の非推奨警告が出るため、sinon.createSandbox() を使う。または QUnit-sinon ブリッジ(this.stub()、this.spy()、this.mock(); this.clock は sinon.config.useFakeTimers が真の場合のみ)を使う。同じモジュール内で両方のアプローチを混ぜない
わかりやすいテスト名 動作を説明する文。「it should」で始めない。モジュール内では一意
すべてのモジュールに beforeEach / afterEach すべてのコントロール(UI部品)を beforeEach で作成し、afterEach で破棄。テスト間で変更可能な状態を共有しない
ヘルパー関数内に try/finally コントロールを作成するヘルパー関数は、finally で破棄するので、アサーション(検証)が失敗してもクリーンアップされる
ASCII 以外の文字を使わない コメント、文字列、JSDoc に ASCII 以外の文字を使わない。em ダッシュ(—)ではなく、通常のハイフン(-)を使う。UTF-8 が必須だが、コメント内の ASCII 以外の文字は歴史的にエンコーディングの問題を起こしている
ESLint — エラーなし 既存パターンの警告(max-nested-callbacks、no-use-before-define、valid-jsdoc)は許容

クイックリファレンス チェックリスト

次のような場合に使用: QUnit テストファイルを作成またはレビューする場合

  • [ ] var を使わない — const または let を使い、1行に1つの宣言(カンマで連ねない)
  • [ ] .bind(this) を使わない — 独自の this が不要なコールバック関数はアロー関数を使う
  • [ ] シンプルな場合に assert.async() を使わない — async function + await new Promise(...) を使う
  • [ ] すべての async テストが assert.expect(N) を持つ
  • [ ] 新しいコードで sinon.sandbox.create() を使わない — sinon.createSandbox() またはブリッジ(this.stub()、this.spy()、this.mock())を使う;this.clock はフェイクタイマーが有効な場合のみ
  • [ ] テスト名を「it should...」で始めない — わかりやすい文を使う
  • [ ] すべての QUnit.module が beforeEach / afterEach を持ち、すべてのコントロールを作成・破棄する
  • [ ] フェイクタイマー使用時:Core.applyChanges() より await nextUIUpdate(this.clock) を優先;nextUIUpdate(clock) で対応できない場合のみ Core.applyChanges() を残す
  • [ ] コントロールを作成するヘルパー関数は try/finally で破棄する
  • [ ] コメントや文字列に ASCII 以外の文字を入れない(UTF-8 が必須だが、ASCII 以外はエンコーディング問題を起こす)
原文(English)を表示

QUnit Test Best Practices for UI5

When to load each reference

Trigger Load
Writing a new QUnit test file or module from scratch references/writing-new-tests.md
Modernizing, refactoring, or reviewing existing test code references/modernizing-tests.md
Migrating from QUnit 1 (globals: test, asyncTest, ok, stop, start) to QUnit 2 references/modernizing-tests.md
Any test touches nextUIUpdate, Core.applyChanges, assert.async, fake timers, or event-based async references/async-patterns.md

Load the reference before producing any output. Do not work from memory.


Core rules (always apply)

Rule Detail
No var Use const or let. One declaration per line - no comma chains.
No .bind(this) Use arrow functions for callbacks that do not need their own this.
assert.expect(N) in every async test Guards against silent passes when async callbacks never fire. Not required for sync tests.
sinon.createSandbox() sinon.sandbox.create() emits a runtime deprecation warning in Sinon 5+ - prefer sinon.createSandbox(). Alternatively use the QUnit-sinon bridge (this.stub(), this.spy(), this.mock(); this.clock only when sinon.config.useFakeTimers is truthy). Do not mix both approaches in the same module.
Descriptive test names Sentence describing behavior. Never start with "it should". Unique within each module.
beforeEach / afterEach in every module Create all controls in beforeEach, destroy them in afterEach. No shared mutable state between tests.
try/finally in helper-created controls Helpers that create a control must destroy it in finally so it is cleaned up even when assertions throw.
No non-ASCII characters No non-ASCII characters in comments, strings, or JSDoc. Use plain ASCII hyphens, not em dashes. UTF-8 is required, but non-ASCII in comments has historically caused encoding issues.
ESLint - 0 errors Warnings for pre-existing patterns (max-nested-callbacks, no-use-before-define, valid-jsdoc) are acceptable.

Quick-reference checklist

Use when authoring or reviewing a QUnit test file:

  • [ ] No var - use const or let; one declaration per line (no comma chains)
  • [ ] No .bind(this) - use arrow functions for callbacks that do not need their own this
  • [ ] No assert.async() in simple cases - use async function + await new Promise(...)
  • [ ] Every async test has assert.expect(N)
  • [ ] No sinon.sandbox.create() in new code - use sinon.createSandbox() or the bridge (this.stub(), this.spy(), this.mock()); this.clock only when fake timers are enabled
  • [ ] No "it should..." test titles - use descriptive sentences
  • [ ] Every QUnit.module has beforeEach / afterEach that create and destroy all controls
  • [ ] With fake timers: prefer await nextUIUpdate(this.clock) over Core.applyChanges(); only keep Core.applyChanges() when nextUIUpdate(clock) cannot handle the case
  • [ ] Helper functions that create controls destroy them in try/finally
  • [ ] No non-ASCII characters in comments or strings (UTF-8 required, but non-ASCII causes encoding issues)

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。