我正在尝试使用Jasmine编写一个用Typescript编写的单元测试.在我的单元测试文件中有以下内容,Resharper提示我从jasmine.d.ts导入类型的链接.
/// <reference path="sut.ts" />
/// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" />
describe("Person FullName", function () {
var person;
BeforeEach(function () {
person = new Person();
person.setFirstName("Joe");
person.setLastName("Smith");
});
It("should concatenate first and last names", function () {
Expect(person.getFullName()).toBe("Joe, Smith");
});
});
Run Code Online (Sandbox Code Playgroud)
所以我点击链接并最终得到以下内容(实际上resharper只用"Jasmine."前缀了describe函数,所以我手动为其他Jasmine调用做了前缀):
/// <reference path="sut.ts" />
/// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" />
import Jasmine = require("../../../Scripts/typings/jasmine/jasmine");
Jasmine.describe("Person FullName", function () {
var person;
Jasmine.BeforeEach(function () {
person = new Person();
person.setFirstName("Joe");
person.setLastName("Smith");
});
Jasmine.It("should concatenate first and last names", function () {
Jasmine.Expect(person.getFullName()).toBe("Joe, Smith"); …
Run Code Online (Sandbox Code Playgroud) 我正在使用Chutzpah来执行我的JavaScript单元测试.
我引用了我的源文件的路径,下面有一系列的测试.Visual Studio中的Text Explorer列出了我的测试,我可以直接从IDE执行它们,所以一切似乎都正常工作.
但是,我想进入运行测试时正在执行的源代码.
这可能吗?
将茉莉花测试分成单独的视觉工作室项目是否可行/可行?
我刚开始使用angular,并且在开始实际角度实现之前尝试编写测试.我将使用Chutzpah测试运行器在Visual Studio 2012中编写我的项目,请参阅此视频.目前,我正在试图弄清楚如何组织我的文件夹结构.我知道角度种子和自耕农,但那些不适合启动.net项目.
我假设因为Visual Studio中的单元测试通常被分成一个单独的测试项目,按照惯例,茉莉花测试也应该.
但是,对于java脚本,没有项目dll可供引用,因此将测试分成不同的项目需要大量的复制和粘贴,我想.
asp.net-mvc jasmine asp.net-mvc-4 chutzpah visual-studio-2012
有谁知道如何让像Chutzpah的Visual Studio测试适配器这样的无头浏览器允许指令访问其.html模板文件?Chutzpah使用PhantomJS作为无头浏览器,似乎限制了我的选择.
我正在使用Chutzpah Test Adapter 2.5和AngularJS 1.2.0-r.2.
我收到错误:
意外请求:获取myApp/directives/template.html
这是由Angular尝试使用$ http服务访问我的指令模板引起的.
我找到了一些不同的解决方法:
$httpBackend.when('GET', 'myApp/directives/template.html').passThrough()
- 这仅适用于e2e测试,而不适用于单元测试.这些选择都没有特别让我满意.我希望能够让指令透明地加载它的模板,这样我就可以将它作为一个组件进行测试.有没有办法让这个场景有效?
示例代码:
angular.module('myDirective', []).directive('myDirective', function() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'myApp/directives/template.html',
// Some other options, omitted for brevity.
};
});
Run Code Online (Sandbox Code Playgroud)
template.html:
<div><div ng-transclude></div></div>
Run Code Online (Sandbox Code Playgroud)
茉莉花测试示例:
describe('myDirective', function() {
// Assign $scope using inject(), load module etc.
// Insert workaround for $httpBackend loading my templateUrl here.
it('should transclude content', function() {
var element = $compile("<my-directive>Look Mom, I'm in my directive!</my-directive>")($scope); …
Run Code Online (Sandbox Code Playgroud) 我只是想知道是否有一个简单的教程,展示了如何使用Chutzpah,require.js和jasmine在visual studio中测试javascript.
基本上,我想在不使用.html文件的情况下运行测试,这样我就可以在vs test explorer中看到结果.
我一直试图弄清楚在visual studio中编写/运行自动茉莉花测试的最佳方法是什么.目前,我正在使用茉莉花与Resharper(使用PhantomJS),测试可以从visual studio运行.现在我想将测试作为持续集成的一部分运行,并且正在使用TFS.在线搜索给我几个选项让我相当困惑.
1)使用Chutzpah作为测试运行器来执行茉莉花测试.
2)使用Karma作为测试运行器(但它也需要Chutzpah测试适配器用于visual studio).
我觉得使用Karma比其他任何东西都要好,但我无法理解Karma的好处,而不仅仅是使用Chutzpah.任何人都可以澄清应该是什么用法?
我正在尝试用PhantomJS运行qunit测试用例.当phantomJS尝试访问DOM的navigator.geolocation函数时,我的一个测试就悬而未决.相同的测试在浏览器中正常工作,只需使用phantomJS挂在控制台中.
doe phantomJS支持地理位置?有什么建议吗?
如果条件,则在以下中断
if(navigator.geolocation) {
window.navigator.geolocation.watchPosition(updateLocation, null, { frequency: 3000 });
}
Run Code Online (Sandbox Code Playgroud) 我正在使用TypeScript 1.0与Visual Studio 2012,Chutzpah 3.2.1.1和Jasmine 2.
我有一个非常基本的测试编译很好,但没有使用Visual Studio Chutzpah测试适配器或命令行传递.
我收到以下错误
ReferenceError:无法找到变量:MyProject in ....
我的项目结构如下:
**solution**
TypeScriptProject
X.ts
TestProject
chutzpah.json
compile.bat
Scripts\(contains typings)
Spec
TestX.ts
Run Code Online (Sandbox Code Playgroud)
TypeScriptProject\X.ts
module MyProject {
export class X {
getValue(): number {
return 5;
}
}
}
Run Code Online (Sandbox Code Playgroud)
TestProject\chutzpah.json
{
"Framework": "jasmine",
"Compile": {
"Extensions": [".ts"],
"ExtensionsWithNoOutput": [".d.ts"],
"Executable": "compile.bat"
},
"References": [
{ "Path": "../TypeScriptProject/X.ts"}
],
"Tests": [
{ "Path": "Spec"}
]
}
Run Code Online (Sandbox Code Playgroud)
TestProject \的compile.bat
@echo off
tsc Spec/TestX.ts ../TypeScriptProject/X.ts --sourcemap
Run Code Online (Sandbox Code Playgroud)
TestProject \规格\ TestX.ts
/// <reference path="../Scripts/typings/jasmine/jasmine.d.ts"/> …
Run Code Online (Sandbox Code Playgroud) 我有angularJs控制器
angular.module('App.ctrl.guests', [])
.controller('guestsController', ['$scope', '$http', '$location', '$timeout', 'guestsService', function ($scope, $http, $location, $timeout, guestsService) {
$scope.tiles = [];
}])
Run Code Online (Sandbox Code Playgroud)
和茉莉花测试
/// <reference path="~/Scripts/angular.js" />
/// <reference path="../../ProjectWeb/Scripts/app/guests/guestsCtrl.js" />
/// <reference path="~/Scripts/angular-mocks.js" />
/// <reference path="~/Scripts/jasmine.js" />
'use strict';
describe('App.ctrl.guests', function () {
var scope, controller;
beforeEach(function () {
module('App.ctrl.guests')
});
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('guestsController', {
$scope: scope
});
}));
it('should have empty array', function () {
expect(scope.tiles).toBe([]);
});
})
Run Code Online (Sandbox Code Playgroud)
每次我在Visual studio chutzpah运行时,我得到:
ReferenceError:找不到变量:file …
如何从项目中删除Chutzpah到不在测试资源管理器中显示结果?
我做了一个演示项目来学习Chutzpah并为VS2013安装它.现在在我的另一个项目中,我不使用Chutzpah而是使用Karma来测试Angularjs测试用例,但仍然测试资源管理器将Angularjs单元测试显示为失败测试,如何从测试资源管理器中删除angularjs测试用例?我只想在测试资源管理器中运行后端Csharp单元测试.
请尽快帮帮我
chutzpah ×10
jasmine ×7
javascript ×5
angularjs ×4
unit-testing ×4
karma-runner ×2
phantomjs ×2
typescript ×2
asp.net ×1
asp.net-mvc ×1
debugging ×1
qunit ×1
requirejs ×1