- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Jasmine Test</title>
- <link rel="shortcut icon" type="image/png" href="lib/jasmine-2.4.1/jasmine_favicon.png">
- <link rel="stylesheet" href="lib/jasmine-2.4.1/jasmine.css">
- <script src="lib/jasmine-2.4.1/jasmine.js"></script>
- <script src="lib/jasmine-2.4.1/jasmine-html.js"></script>
- <script src="lib/jasmine-2.4.1/boot.js"></script>
- <script src="src/cici.js"></script>
- <script src="spec/ciciSpec.js"></script>
- </head>
- <body>
- </body>
- </html>
- <script src="src/cici.js"></script> //需要测试的function
- <script src="spec/ciciSpec.js"></script> //测试期望
1. 做AngularJS测试:
cici.js
- function PhoneListCtrl($scope) {
- $scope.phones = [
- {"name": "Nexus S",
- "snippet": "Fast just got faster with Nexus S."},
- {"name": "Motorola XOOM? with Wi-Fi",
- "snippet": "The Next, Next Generation tablet."},
- {"name": "MOTOROLA XOOM?",
- "snippet": "The Next, Next Generation tablet."}
- ];
- }
- describe('PhoneCat controllers', function() {
- describe('PhoneListCtrl', function(){
- it('should create "phones" model with 3 phones', function() {
- var scope = {},
- ctrl = new PhoneListCtrl(scope);
- expect(scope.phones.length).toBe(3);
- });
- });
- });
2.做Javascript测试
cici.js
- function maximizing(a,b){
- if(a>b){
- return a;
- }else{
- return b;
- }
- }
- describe("cici specs",function(){
- it("test maximizing",function(){
- expect(maximizing(3,5)).toEqual(5);
- })
- })