嗨,我是刚接触karma Jasmine测试的。我试图测试一个函数,但它在我尚未测试的值上抛出了一个错误。这里是错误
TypeError: Cannot set property 'statement' of undefined
下面是我得到错误的描述块切换选项按钮中的相关代码(这是我为注入rootscope而添加的唯一代码)
fdescribe('Online Statements', () => {
const module = window.module;
const inject = window.inject;
beforeEach(module('wbbUiApp'));
describe('Controller', () => {
let scope;
let controller;
let injectibles;
let bindings;
const createController = userDetails => {
inject(($componentController,
$window,
$filter,
$rootScope) => {
// The same `$inject` array values listed in `account-activity.controller.js`
injectibles = {
$window,
$filter,
$rootScope
};
// The same bindings listed in `account-activity.component.js`
bindings = {
accountDetails
};
controller = $componentController('onlineStatements', injectibles, bindings);
});
};
describe('toggle options button', () => {
//beforeEach(controller.statement = { showOptions: true })
it('should set the scope value to the index', () => {
const index = 1;
const dateId = 1290488400000;
controller.toggleOptions(index, dateId)
expect(controller.activeRow).toEqual(index);
})
})
});
这是控制器中发生错误的代码
this.statement.showOptions
我试着对它进行注释,如果它不在控制器中,效果很好。我试着在construtor和on init中设置它,就像这样
statement: { showOptions: false }
这样地
this.statement.showOptions = true;
toggleOptions(index, currentDate) {
// toggle the dropdown with all buttons if its new then showing options is always true
if (currentDate === this.currentSelectedDate) {
this.statement.showOptions = !this.statement.showOptions;
} else {
this.statement.showOptions = true;
}
this.activeRow = index;
this.currentSelectedDate = currentDate;
}
这可能很简单,因为我才刚刚开始。提前谢谢你。