用karma测试angularjs应用
来源:互联网 发布:淘宝产品拍照 编辑:程序博客网 时间:2024/06/05 20:36
介绍网上有很多就不赘述了
Karma的安装
sudo npm install karma -g
网上只给了这步,由于版本迭代会导致本地找不到KARMA命令。像很多模块的最新版本一样,只需再安装个客户端就OK了
sudo npm install karma-cli -g
karma init
Which testing framework do you want to use ?Press tab to list possible options. Enter to move to the next question.> jasmineDo you want to use Require.js ?This will add Require.js plugin.Press tab to list possible options. Enter to move to the next question.> noDo you want to capture any browsers automatically ?Press tab to list possible options. Enter empty string to move to the next question.> Chrome>What is the location of your source and test files ?You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".Enter empty string to move to the next question.>Should any of the files included by the previous patterns be excluded ?You can use glob patterns, eg. "**/*.swp".Enter empty string to move to the next question.>Do you want Karma to watch all the files and run the tests on change ?Press tab to list possible options.> yesConfig file generated at "/你的项目路径/karma.conf.js".
运行Karma
</pre><p><pre name="code" class="html">karma start karma.conf.js
以逆转字符串为例
home.js
function reverse(name){ return name.split("").reverse().join("");}
home.test.js
describe("A suite of basic functions", function() { it("reverse word",function(){ expect("DCBA").toEqual(reverse("ABCD")); expect("Conan").toEqual(reverse("nano")); });});
启动后会在终端中看到
karma start karma.config.jsINFO [karma]: Karma v0.12.31 server started at http://localhost:9876/INFO [launcher]: Starting browser ChromeINFO [Chrome 41.0.2272 (Mac OS X 10.10.2)]: Connected on socket VqxM2bXSv64g2MlvUIK_ with id 29138942Chrome 41.0.2272 (Mac OS X 10.10.2) A suite of basic functions reverse word FAILEDExpected 'Conan' to equal 'onan'. at Object.<anonymous> (/Users/Nathan/Workspaces/hnczb-web/test/home.test.js:4:25)Chrome 41.0.2272 (Mac OS X 10.10.2): Executed 1 of 1 (1 FAILED) (0 secs / 0.009 Chrome 41.0.2272 (Mac OS X 10.10.2): Executed 1 of 1 (1 FAILED) ERROR (0.014 secs / 0.009 secs)
注释掉
//expect("Conan").toEqual(reverse("nano"));
INFO [watcher]: Changed file "/Users/Nathan/Workspaces/hnczb-web/test/home.test.js".Chrome 41.0.2272 (Mac OS X 10.10.2): Executed 1 of 1 SUCCESS (0 secs / 0.003 secChrome 41.0.2272 (Mac OS X 10.10.2): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 secs)
0 0
- 用karma测试angularjs应用
- 使用 Karma 和 Jasmine 测试 AngularJs
- karma + Jasmine 自动化测试AngularJS代码
- angularjs karma安装小问题
- Karma测试环境搭建
- Karma自动化测试
- 安装测试系统karma
- 前端测试环境Karma简介
- play+angularjs+karma unit test(单元测试)
- ionic之如何应用karma进行单元测试(2)-测试controller和service
- karma
- karma
- angular+karma+bower搭建自动化测试环境
- 使用karma + mocha + sinon 测试 Ajax 请求
- karma 测试框架的前世今生
- ionic之如何应用karma进行单元测试
- 通过缓存安装Karma和Jasmine并进行AngularJS单元测试
- 基于Karma,Jasmine的AngularJS,RequireJS单元测试配置笔记
- 【jqgrid】简单封装
- android -- 蓝牙 bluetooth (五)接电话与听音乐
- 气体检测的本案电路相关
- 【POJ 1456】Supermarket
- 卷积操作的GPU粗粒度并行实现及测试(优化)
- 用karma测试angularjs应用
- WindowsApps删除注意事项,和删除Packages导致程序闪退解决办法
- Synergy 一套键鼠同时控制多台电脑的神器!超级方便!
- 数据结构:avl树
- 正则表达式(实例大全)
- 与Docker Hub一起工作
- Linux下Android Studio的安装步骤及关键点【整理】
- Rest API 学习笔记
- 数据结构--递归 协变 泛型方法 类型界限