博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FireUnit:基于Firebug的JavaScript单元测试扩展
阅读量:3604 次
发布时间:2019-05-20

本文共 1303 字,大约阅读时间需要 4 分钟。

John Resig最近在他的博客中发表文章.发布了他与合作开发的一款基于Firebug的扩展。(Firebug真是越来越强大了……)

简单说来,FireUnit给Firebug增加了一个标签面板,并提供了一些简单的JavaScript API来记录和查看测试。
举例来说:

  1. // Simple true-like/false-like testing
  2. fireunit.ok( true, "I'm going to pass!" );
  3. fireunit.ok( false, "I'm going to fail!" );
  4. // Compare two strings - shows a diff of the
  5. // results if they're different
  6. fireunit.compare(
  7.   "The lazy fox jumped over the log.",
  8.   "The lazy brown fox jumped the log.",
  9.   "Are these two strings the same?"
  10. );
  11. // Compare a string using a regular expression
  12. fireunit.reCompare(
  13.   /The .* fox jumped the log./,
  14.   "The lazy brown fox jumped the log.",
  15.   "Compare a string using a RegExp."
  16. );
  17. // Display the total results
  18. fireunit.testDone();

就可以在Firebug中的Test标签面板中看到下图:

FireUnit还可以模拟触发原生浏览器事件:

  1. // You can also simulate browser events
  2. var input = document.getElementsByTagName("input")[0];
  3. fireunit.mouseDown( input );
  4. fireunit.click( input );
  5. fireunit.focus( input );
  6. fireunit.key( input, "a" );

此外,可以批量测试文件(每个文件都含有一些独立测试)

  1. // Or run multiple pages of tests:
  2. fireunit.runTests("test2.html", "test3.html");
  3. // Place at the end of every test file in order to continue
  4. fireunit.testDone();

推荐把测试代码包含在下面的if语句内

  1. if ( typeof fireunit === "object" ) {
  2.         //Your code for test
  3. }

如果感兴趣,可以访问下载并测试(这个网站内就包含了测试代码,安装后即可看到第一张图的内容)

可以在Github上获取,得用git而不是svn
Jan也写了一篇,可以看看。

转载地址:http://poizn.baihongyu.com/

你可能感兴趣的文章
2019/07/19 kvm虚拟化(05)
查看>>
2019/07/21 git基础(01)
查看>>
2019/07/21 git基本应用(02)
查看>>
2019/07/23 git分支及分布式协作(03)
查看>>
2019/07/23 git分支及远程仓库(04)
查看>>
2019/07/24 git server(05)
查看>>
2019/07/24 搜索引擎及ES概述(01)
查看>>
2019/07/25 es集群部署及简单使用(02)
查看>>
2019/07/27 elk基础应用(03)
查看>>
2019/07/29 elk应用进阶(04)
查看>>
2019/07/29 elastic stack geoip(05)
查看>>
2019/07/29 Linux容器和lxc(01)
查看>>
2019/07/3 docker入门(02)
查看>>
2019/07/31 docker容器和镜像(03)容器部分
查看>>
2019/07/31 docker容器和镜像(03)镜像部分
查看>>
2019/08/01 docker镜像和卷(04)
查看>>
2019/08/01 docker网络(05)
查看>>
2019/08/02 docker镜像文件制作(01)
查看>>
2019/08/03 docker镜像和Registry(02)docker镜像
查看>>
2019/08/04 docker镜像和Registry(02) Registry部分
查看>>