karma mocha angular angular-mock 测试
describe(‘工具方法测试‘, function () { var utilsModule; beforeEach(function () { module(‘Admin‘); // module(‘app.menu‘); // utilsModule = module(‘blocks.utils‘); } ); it(‘数组转换方法测试‘, function () { var dataset = []; var arr = []; var level = 9999; // var utils = $service(‘utils‘); // utils.convertTreeDataToArr(dataset,arr,level); inject(function (utils) { utils.convertTreeDataToArr(dataset, arr, level); }); console.info(‘what?‘); }); it(‘service‘, function () { inject(function (Menu) { // var menuController = $controller(‘MenuController‘); console.info(‘getMenus before‘); // todo 异步,注入其他service Menu.getMenus(function(data){ console.log(data); }); console.info(‘getMenus after‘); }); }); it(‘controller‘, function () { inject(function ($controller) { // console.info(‘getMenus before‘); // todo 需要注入其他service var menuController = $controller(‘MenuController‘); menuController.activate(); // console.info(‘getMenus after‘); }); }); });
mocha 测试用例代码
准备环境:
angular admin 模块
karma.conf.js 配置karma 运行时环境,加载angular admin模块,需要引入angular.js等,类似正常开发过程中引入文件
引入mocha上述测试执行代码
对目标测试对象进行测试
使用angular mock 单元测试模块,对angular app 特定目标对象进行单元测试
相关推荐
83394193 2019-11-15
阿斌Elements 2020-06-11
QiaoranC 2020-09-25
颤抖吧腿子 2020-09-04
liduote 2020-06-16
xxuncle 2020-06-05
ChinaGuanq 2020-06-05
wanghongsha 2020-03-26
csm0 2020-03-05
shyoushine 2020-02-25
electronvolt 2020-02-12
jsonwoo 2020-01-20
ZadarrienChina 2020-01-07
wwwxuewen 2020-01-04
dynsxyc 2020-01-03
liangjielaoshi 2019-12-27
bowean 2019-12-27
wwwxuewen 2019-12-25
liwusen 2019-12-16