• 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

  • 相关阅读:
    thinkpad--Windows8 F11一键恢复方法
    ThinkPad---Windows8更换Windows7方法
    断网问题360解决方案
    网络故障诊断指南
    重装系统指南
    题目1123:采药
    题目1019:简单计算器
    题目1012:畅通工程
    你的隐私数据真的安全吗之memset()使用分析
    高光谱图像处理深度学习方法综述(一)
  • 原文地址:https://www.cnblogs.com/yfann/p/4610590.html
Copyright © 2020-2023  润新知