karma+requirejs+angular 测试
http://karma-runner.github.io/0.8/plus/RequireJS.html
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.1",
"karma-jasmine": "^0.3.6",
"karma-mocha": "^0.2.0", //与jasmine 二选一即可,建议使用jasmine,mocha需要其他的断言包
"karma-requirejs": "^0.2.2",
karma init
// Karma configuration
// Generated on Tue Nov 10 2015 09:39:31 GMT+0800 (中国标准时间)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// 配置要加载的文件
//字符串形式的表示 通过<script>标签进行加载
//对象形式的必须包含pattern、included属性,pattern进行匹配文件,included为true表示通过requirejs进行加载(后面会结束配置说明),否则通过script标签进行加载
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/components/**/*.js',
'app/view*/**/*.js',
{pattern: 'app/define/*.js', included: false},
{pattern: 'app/test/*.js', included: false},
'test-main.js'
],
// list of files to exclude
exclude: [
'**/*.swp'
],
proxies: {
//'/static': 'http://gstatic.com',
'/log': 'http://localhost:3000' //避免跨域,测试异步请求时如果指定完整url就是跨域,会出错,如果只写路径会请求到karma服务器localhsot:9876/
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
/**
* Created by weichunhe on 2015/11/10.
*/
var tests = [];
for (var file in window.__karma__.files) { //这里的文件路径已经包含了 /base了
if (window.__karma__.files.hasOwnProperty(file)) {
if (/test1\.js$/.test(file)) {
tests.push(file);
}
}
}
console.log(window.__karma__.files);
console.log(tests);
requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/app/define',
paths: {},
shim: {},
// ask Require.js to load these files (all our tests)
deps: tests, //这里只包含需要测试的文件就可以了
// start test run, once Require.js is done
callback: window.__karma__.start
});
$injector = angular.injector(['app']); //执行这步之后 注册的controller可以injector获取到
require('app').register.controller('testCtrl', function (name) {
console.log('controller', name);
});
$injector.invoke(function ($controller) {
$controller('testCtrl', {name: 'testCtrl'});
});
karma+requirejs+angular 测试的更多相关文章
- angular测试-Karma + Jasmine配置
首先讲一下大致的流程: 需要node环境,首先先要安装node,node不会?请自行搜索.版本>0.8 安装node完成之后先要测试下npm是否测试通过,如下图所示 首先看下目录结构 目录为:F ...
- karma和jasmine的测试(包括angular测试)
本篇博客主要就是针对现在日新月异的技术和快速开发,测试被很多人忽略,其实在开发中如何保证代码的质量以及逻辑的完整性,测试显得十分重要,本文就是负责karma+jasmine来测试. 1.搭建测试的环境 ...
- 浅谈HTML5单页面架构(一)——requirejs + angular + angular-route
心血来潮,打算结合实际开发的经验,浅谈一下HTML5单页面App或网页的架构. 众所周知,现在移动Webapp越来越多,例如天猫.京东.国美这些都是很好的例子.而在Webapp中,又要数单页面架构体验 ...
- H5单页面架构:requirejs + angular + angular-route
说到项目架构,往往要考虑很多方面: 方便.例如使用jquery,必然比没有使用jquery方便很多,所以大部分网站都接入类似的库: 性能优化.包括加载速度.渲染效率: 代码管理.大型项目需要考虑代码的 ...
- AngularJS进阶(二十五)requirejs + angular + angular-route 浅谈HTML5单页面架构
requirejs + angular + angular-route 浅谈HTML5单页面架构 众所周知,现在移动Webapp越来越多,例如天猫.京东.国美这些都是很好的例子.而在Webapp中,又 ...
- Angular测试遇到的小坑
Angular测试遇到的小坑 Error: Expected to be running in 'ProxyZone', but it was not found 检查doneFn的写法是否正确,位置 ...
- 用Karma和Jasmine测试Angular应用
TEST: Before you've written any of the code, you know how you want it to behave. You have a specific ...
- karma mocha angular angular-mock 测试
describe('工具方法测试', function () { var utilsModule; beforeEach(function () { module('Admin'); // modul ...
- karma+requirejs
下面的介绍以karma能正常运行为前提,看karma系列文章:http://www.cnblogs.com/laixiangran/tag/Karma/ 目录结构 步骤 安装 npm install ...
随机推荐
- Effective C++ Item 41 了解隐式接口和编译期多态
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:class 和 templates 都支持接口和多态. 对 classes 而言接口是 ...
- spring test---restful与文件上传
spring提供了大量经常使用的功能測试,如文件上传.restful风格url訪问.以下介绍主要介绍下test中经常使用功能的使用方法: 首先能够静态导入类.方便在測试类中使用,导入的类有 impor ...
- Windows 驱动开发 - 7
在<Windows 驱动开发 - 5>我们所说的读写操作在本篇实现. 在WDF中实现此功能主要为:EvtIoRead和EvtIoWrite. 首先,在EvtDeviceAdd设置以上两个回 ...
- tt1
DIm #include iostream.h#include iostream.h# #include iostream.h http://www.cnblogs.com/cmt/archive/2 ...
- Python常用数据处理函数
1.基本统计特征函数 方法名 函数功能 所属库 使用格式 sum() 计算数据样本综合(按列计算) Pandas D.sum() mean() 计算数据样本算数平均数 Pandas D.mean() ...
- 安装 matplotlib
比较推荐还是用pip来安装,用源码安装还是会比较麻烦,进入到CMD窗口下,执行python -m pip install -U pip setuptools进行升级. 接着键入python -m pi ...
- go2基本类型
/* Go基本类型 布尔型:bool - 长度:1字节 - 取值范围:true, false - 注意事项:不可以用数字代表true或false 整型:int/uint - 根据运行平台可能为32或6 ...
- 今晚的两道 bc
第一道题 Beautiful Palindrome Number ,简单组合计数问题,手算打表就好~大概十五分钟左右搞定[第一次 提交竟然 wa了一次 有一个小小的坑在那.... /******** ...
- python-----删除文件到回收站
python删除文件一般使用os.remove,但这样删是直接删除文件,不删到回收站的,那么想删除文件到回收站怎么办? 这时,就需要使用shell模块了 from win32com.shell imp ...
- 编译Ruby2.0 问题解决
compiling readline.creadline.c: In function ‘Init_readline’:readline.c:1886:26: error: ‘Function’ un ...