zoukankan      html  css  js  c++  java
  • UT----回调函数 和 promise angularjs + jasmine + karma

    1、测试回调函数  和  promise

       
    contextBrokerService.addOnMessageListener(function (message) {
      MetaService.GetBondNameByXref(message).then(function (res) {
        vm.defaultBondName = res.data;
      });
    }
     
     
    UT

    spyOn(contextBrokerService, 'addOnMessageListener').and.callFake(function(){
      arguments[0]({message: 'msgValue'})       //   spyOn().and.callFake(function() {arguments[0]({message: 'value'})})     用来执行回调函数
    });
    spyOn(MetaService, 'GetBondNameByXref').and.returnValue(q.resolve({data: 'defaultBondName'}));  // q  是注入的$q的别名, 这里不能用Promise.resolve代替
    scope.$emit('GridsLoaded');
    scope.$digest();        //   会把所有的异步($q的异步方法,不执行Promise的异步)方法执行完,如果有刷新页面或请求页面的请求, 用$httpBackend mock 掉。 如请求了pages/BWICColor.html.  
    这样去mock 解决, 一般会放在beforeEach中  $httpBackend.whenGET("pages/BWICColor.html").respond({});
    done();
    expect(ctrl.defaultBondName).toBe('defaultBondName');
  • 相关阅读:
    python之Selenium
    Python常用集锦(upgrading...)
    豆瓣爬虫
    poj 2299 Ultra-QuickSort(求逆序对)
    nyoj117 求逆序数
    codeforces 644A Parliament of Berland
    codeforces 659A Round House
    poj 3264 Balanced Lineup(RMQ裸题)
    nyoj 119 士兵杀敌(三)(RMQ)
    hdu 5655 CA Loves Stick
  • 原文地址:https://www.cnblogs.com/hellobeen/p/10117734.html
Copyright © 2011-2022 走看看