我一直试图为一个小的JavaScript文件编写一个茉莉花测试。此文件为我的应用程序定义了一个名为“EIS”的事件。在我的茉莉花测试甚至运行之前,我在Jasmine规范运行程序中得到一条失败消息,因为它不能正确地读取我的过滤器。我遵循了这个问题的简单说明:
但这没有帮助,因为Jasmine甚至不会读取我原来的javascript文件中的过滤器。这里是(标题为eventModule.js):
var app = angular.module("eisViewerApp",['ngGrid', 'ngRoute']);
function EISE
更新:我知道问题是什么,见下面的评论。
在每一次茉莉花测试之前,有没有办法保证状态?例如:
describe('some thing', function () {
beforeEach(function () {
doSetup();
// this expect does not evaluate :(
expect(something).toBe(inSomeState);
});
it('has some behavior', function () {
// tes
来自茉莉花文档():
这个关键字
在beforeEach、it和afterEach之间共享变量的另一种方法是通过this关键字。每个规范在Each /it/beforeEach之前/it/beforeEach之前都有一个空对象,为下一个规范的afterEach/it/beforeEach设置为空对象。
我在Javascript中的理解是,这被限制在实际函数的范围内。因此,我预计它将绑定到ones / it /beforeEach之前内部的不同上下文(取决于函数的上下文)。
例如:
describe('Spec', function (){
var eachThis
我熟悉python测试,如果断言失败,则该测试被标记为“失败”,然后转移到其他测试。另一方面,茉莉花将继续通过所有的期望,即使其中一个失败。在第一次期望失败之后,我怎样才能让茉莉花停止处理测试?
it ("shouldn't need to test other expects if the first fails", function() {
expect(array.length).toBe(1);
// don't need to check this if the first failed.
expect(array[0]).t
这是我的函数
$scope.buildForm = function (majorObjectId, name) {
$window.open("/FormBuilder/Index#/" + $scope.currentAppId + "/form/" + majorObjectId + "/" + name);
};
这是我的茉莉花测试规范
it('should open new window for buildForm and with expected id', function
我使用茉莉花作为测试框架,我有下面的控制器我想测试。而且我总是有一个Init()函数,在这里我对这个Controller进行初始化调用。
现在,我想测试初始化控制器时是否调用了Init函数。
function UnitTestsCtrl() {
var that = this;
this.Init();
}
UnitTestsCtrl.prototype.Init = function() {
var that = this;
//Some more Stuff
}
angular.module("unitTestsCtrl", [])
我开始用茉莉花来测试,angularjs,但很快我开始想知道哪一种方法是好的,为什么呢?我选择了每种规格的单一expect。我喜欢它是因为一个非技术人员可以更好地理解它,这就是BDD的重点,不是吗?例如
describe('Testing multple expect per spec My Service', function() {
beforeEach(/* some stuff*/);
it('test part ',function(){
expect('part 1').toBe('part one