QUnitjQuery 单元测试框架

联合创作 · 2023-10-01 16:12

QUnit 是一个功能强大、易于使用的 JavaScript 单元测试框架。它被 jQuery 项目用于测试代码和插件,它能够测试任何通用的 JavaScript 代码(甚至能够在服务器端测试 JavaScript 代码)。

    示例代码:

test("a basic test example", function() {
  ok( true, "this test is fine" );
  var value = "hello";
  equals( "hello", value, "We expect value to be hello" );
});

module("Module A");

test("first test within module", function() {
  ok( true, "all pass" );
});

test("second test within module", function() {
  ok( true, "all pass" );
});

module("Module B");

test("some other test", function() {
  expect(2);
  equals( true, false, "failing test" );
  equals( true, true, "passing test" );
});

    测试结果页面:

浏览 3
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报