欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  资讯频道

FireUnit:JavaScript单元测试扩展

程序员文章站 2022-03-13 12:06:06
...
John Resig 和 Jan Odvarko发布了FireUnit,这是Firebug的JavaScript单元测试扩展。在Firebug中安装好扩展就能打开一个测试tab进行测试。

FireUnit:JavaScript单元测试扩展

详情查看:http://fireunit.org/

范例代码:

// Simple true-like/false-like testing

fireunit.ok( true, "I'm going to pass!" );

fireunit.ok( false, "I'm going to fail!" );

// Compare two strings - shows a diff of the

// results if they're different

fireunit.compare(
  "The lazy fox jumped over the log.",
  "The lazy brown fox jumped the log.",
  "Are these two strings the same?"
);

// Compare a string using a regular expression
fireunit.reCompare(

  /The .* fox jumped the log./,
  "The lazy brown fox jumped the log.",
  "Compare a string using a RegExp."
);

// Display the total results
fireunit.testDone();

// -- browser events
// You can also simulate browser events
var input = document.getElementsByTagName("input")[0];
fireunit.mouseDown( input );
fireunit.click( input );
fireunit.focus( input );
fireunit.key( input, "a" );

// -- Run batches

// Or run multiple pages of tests:
fireunit.runTests("test2.html", "test3.html");

// Place at the end of every test file in order to continue
fireunit.testDone();