zoukankan      html  css  js  c++  java
  • Jasmine

    describe(string,function)  //suite测试集,可包含多个Specs(it),每个Specs(it)可包含多个expect

    describe("A suite", function() {
      it("contains spec with an expectation", function() {
        expect(true).toBe(true);
      });
    });

    beforeAll,beforeEach,afterAll,afterEach  //beforeAll:每个suite(即describe)中所有spec(即it)运行之前运行, beforeEach:每个spec(即it)运行之前运行

    (function(){
        describe("Test 'this'", function() {
          beforeEach(function() {
            this.testCount = this.testCount || 0;
            this.testCount++;
          });
    
          afterEach(function() {
            //this.testCount = 0; //无论是否有这行,结果是一样的,因为this指定的变量只能在每个spec的beforeEach/it/afterEach过程中传递
          });
            
          it("Spec 1", function() {
            expect(this.testCount).toBe(1);
          });
          
          it("Spec 2", function() {
            expect(this.testCount).toBe(1);
          });
        });
    })();

    angular-mocks.js

    inject

    angular.module('myApplicationModule', [])
        .value('mode', 'app')
        .value('version', 'v1.0.1');
    
    
    describe('MyApp', function() {
    
      // You need to load modules that you want to test,
      // it loads only the "ng" module by default.
      beforeEach(module('myApplicationModule'));
    
    
      // inject() is used to inject arguments of all given functions
      it('should provide a version', inject(function(mode, version) {
        expect(version).toEqual('v1.0.1');
        expect(mode).toEqual('app');
      }));
    
    
      // The inject and module method can also be used inside of the it or beforeEach
      it('should override a version and test the new version is injected', function() {
        // module() takes functions or strings (module aliases)
        module(function($provide) {
          $provide.value('version', 'overridden'); // override version here
        });
    
        inject(function(version) {
          expect(version).toEqual('overridden');
        });
      });
    });

    url:http://jasmine.github.io/2.0/introduction.html

       https://docs.angularjs.org/api/ngMock

  • 相关阅读:
    统计创建对象个数
    动手动脑
    开学第一周心得
    放假第五周总结
    放假第四周总结
    第一周总结
    04-异常处理-动手动脑
    03-继承与多态-动手动脑
    02-类和对象-跟踪类对象创建个数
    02-类和对象-动手动脑
  • 原文地址:https://www.cnblogs.com/yfann/p/4610590.html
Copyright © 2011-2022 走看看