本文档描述了 reveal.js 中使用的测试框架,包括测试的组织、结构和执行方式。有关构建系统的信息,请参阅 构建系统,有关依赖管理的信息,请参阅 依赖管理。
reveal.js 测试框架基于 QUnit 构建,这是一个 JavaScript 单元测试框架。测试被组织成 HTML 文件,这些文件会实例化实际的 reveal.js 演示文稿,并针对它们运行断言,从而为全面测试提供真实的执行环境。
来源: test/test.html1-897 test/test-auto-animate.html1-152 test/test-pdf.html1-97 test/test-grid-navigation.html1-75 test/test-state.html1-134 test/test-iframes.html1-102
每个测试文件都遵循一个标准结构,包括 QUnit 组件、reveal.js 演示实例和测试脚本。
来源: test/test.html1-20 test/test.html83-100
典型的测试文件 HTML 结构包括:
来源: test/test.html1-20 test/test.html83-100
测试被组织成逻辑模块,将相关功能分组。
| 模块 | 目的 |
|---|---|
| DOM | 测试正确的 DOM 结构和 CSS 类。 |
| API | 测试公共 API 方法和属性。 |
| URL | 测试 URL 处理和导航。 |
| 键盘 | 测试键盘导航和快捷键。 |
| 片段 | 测试片段(fragment)功能。 |
| 自动播放 | 测试自动播放幻灯片。 |
| 配置 | 测试配置选项。 |
| 延迟加载 | 测试资源的延迟加载。 |
| 事件 | 测试事件触发和处理。 |
单独的测试文件专门用于特定功能。
| 测试文件 | 目的 |
|---|---|
| test.html | 核心功能的主测试套件。 |
| test-auto-animate.html | 测试幻灯片之间的自动动画。 |
| test-pdf.html | 测试 PDF 导出模式。 |
| test-grid-navigation.html | 测试网格导航模式。 |
| test-iframe-backgrounds.html | 测试 iframe 背景。 |
| test-state.html | 测试状态管理。 |
| test-iframes.html | 测试 iframe 加载。 |
| test-dependencies.html | 测试依赖加载。 |
| test-dependencies-async.html | 测试异步依赖加载。 |
来源: test/test.html test/test-auto-animate.html test/test-pdf.html test/test-grid-navigation.html test/test-state.html test/test-iframes.html test/test-dependencies.html test/test-dependencies-async.html
reveal.js 中的测试遵循标准的 QUnit 模式,并带有一些 reveal.js 特有的方法。
测试被组织成模块和单独的测试用例。
来源: test/test.html110-129 test/test.html130-197
测试使用了几种常见的断言模式。
来源: test/test.html158-167 test/test.html269-271
来源: test/test.html201-217 test/test.html287-296
来源: test/test.html220-227 test/test.html112-123
该框架支持使用 QUnit 的 assert.async() 方法进行异步测试。
来源: test/test.html591-618 test/test.html862-894
Promise-based async testing is also supported
要运行 reveal.js 测试
npm run build)QUnit 在浏览器中报告测试结果,显示
测试套件包含辅助函数以简化测试
大多数 API 测试遵循调用方法并验证其返回值的一个模式
事件测试验证事件是否在适当的时间正确触发
片段测试验证幻灯片片段的行为
reveal.js 测试框架提供了一套全面的测试,可在真实环境中验证库的功能。通过使用 QUnit 和基于 HTML 的测试文件模式,该框架可确保演示行为在各种浏览器和环境中按预期工作。
来源: test/test.html test/test-auto-animate.html test/test-pdf.html test/test-grid-navigation.html test/test-state.html test/test-iframes.html test/test-dependencies.html test/test-dependencies-async.html