Chinaunix首页 | 论坛 | 博客
  • 博客访问: 459407
  • 博文数量: 226
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2111
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-20 09:02
个人简介

web web web

文章分类

全部博文(226)

文章存档

2020年(2)

2019年(1)

2018年(3)

2017年(26)

2016年(57)

2015年(60)

2014年(77)

我的朋友

分类: JavaScript

2016-01-15 14:25:53


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Jasmine Test</title>

  6. <link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png">
  7. <link rel="stylesheet" href="lib/jasmine-2.4.1/jasmine.css">

  8. <script src="lib/jasmine-2.4.1/jasmine.js"></script>
  9. <script src="lib/jasmine-2.4.1/jasmine-html.js"></script>
  10. <script src="lib/jasmine-2.4.1/boot.js"></script>

  11. <script src="src/cici.js"></script>
  12. <script src="spec/ciciSpec.js"></script>

  13. </head>
  14. <body>

  15. </body>
  16. </html>
  1. <script src="src/cici.js"></script>          //需要测试的function
  2. <script src="spec/ciciSpec.js"></script>      //测试期望

1. 做AngularJS测试:
cici.js

  1. function PhoneListCtrl($scope) {
  2.   $scope.phones = [
  3.     {"name": "Nexus S",
  4.      "snippet": "Fast just got faster with Nexus S."},
  5.     {"name": "Motorola XOOM? with Wi-Fi",
  6.      "snippet": "The Next, Next Generation tablet."},
  7.     {"name": "MOTOROLA XOOM?",
  8.      "snippet": "The Next, Next Generation tablet."}
  9.   ];
  10. }
ciciSpec.js

  1. describe('PhoneCat controllers', function() {

  2.   describe('PhoneListCtrl', function(){

  3.     it('should create "phones" model with 3 phones', function() {
  4.       var scope = {},
  5.       ctrl = new PhoneListCtrl(scope);

  6.       expect(scope.phones.length).toBe(3);
  7.     });
  8.   });
  9. });
结果

2.做Javascript测试
cici.js

  1. function maximizing(a,b){
  2.     if(a>b){
  3.         return a;
  4.     }else{
  5.         return b;
  6.     }
  7. }
ciciSpec.js

  1. describe("cici specs",function(){
  2.     it("test maximizing",function(){
  3.         expect(maximizing(3,5)).toEqual(5);
  4.     })
  5. })
结果

阅读(1096) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~