鲍勃の部屋
  • Blog
  • Work
  • About
  • Contact

Jasmine 使用初探

6/26/2014

0 Comments

 
什么是JASMINE:

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests. This guide is running against Jasmine version 2.0.0.

第一步:安装

bob采用的是bower安装, so

1.安装nodeJS
2.npm install bower -g
3.bower install jasmine


第二步:看官方demo
在$YOUR_PATH/bower_components\jasmine\dist\ 下 解压jasmine-standalone-2.0.0.zip
然后运行里面的 SpecRunner.html

可以看到jasmine的运行界面如下
Picture
第三步:自己动手体验jasmine

假设自己已有一个index.js
function getName() {
    return "Bob";
}

要测试它, 新建一个BobSpecRunner.html, 内容和 standalone-2.0.0里的SpecRunner.html一样,但需要修改 源文件为自己的index.js , 还有 jasmine相关文件的路径,改完后如下 :
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Bob Spec Runner v2.0.0</title>

  <link rel="shortcut icon" href="../bower_components/jasmine/lib/jasmine-core/jasmine_favicon.png">
  <link rel="stylesheet" href="../bower_components/jasmine/lib/jasmine-core/jasmine.css">

  <script src="../bower_components/jasmine/lib/jasmine-core/jasmine.js"></script>
  <script src="../bower_components/jasmine/lib/jasmine-core/jasmine-html.js"></script>
  <script src="../bower_components/jasmine/lib/jasmine-core/boot.js"></script>

  <!-- include source files here... -->
  <script src="index.js"></script>


  <!-- include spec files here... -->
  <script src="spec/IndexSpec.js"></script>

</head>

<body>
</body>
</html>
新建一个 spec/IndexSpec.js 内容如下:
describe ("test bob", function () {
it ("test if", function () {
    expect(getName()).toEqual("Bobo");
});
});
好了,用浏览器打开BobSpecRunner.html 就可以看到测试的结果了。

更多详情可以参考 官网
0 Comments



Leave a Reply.

    Author

    鲍勃 (上海)
    互联网码农

    小A

    Archives

    July 2014
    June 2014
    May 2014

    Categories

    All
    AngularJS
    App
    Bootstrap
    Cocos2dx-c++
    Css
    CSS3
    Design Pattern
    Express
    Funny
    Game
    Html5
    Jasmine
    Javascript
    Lua
    Music
    Node.js
    Pattern
    Phonegap
    Php
    Python
    Tdd
    Tips

    RSS Feed

Powered by Create your own unique website with customizable templates.