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

  • 相关阅读:
    [计算机网络] 互联网协议栈(TCP/IP参考模型)各层的主要功能及相应协议
    [计算机网络-应用层] P2P应用
    [剑指Offer] 45.扑克牌顺子
    [剑指Offer] 44.翻转单词顺序列
    [STL] 如何将一个vector赋给另一个vector
    最近更新少,是因为在用框架做项目
    转收藏:Git常用命令速查表
    CentOS常用指令
    CentOS修改服务器系统时间
    Javascript定时跳转
  • 原文地址:https://www.cnblogs.com/yfann/p/4610590.html
Copyright © 2011-2022 走看看