Javascript 单元测试-toEqual对象与数组
我知道这是一个愚蠢的问题,但我一辈子也弄不明白为什么。我不熟悉测试,也不熟悉JavaScript,所以请提前道歉 我有以下测试Javascript 单元测试-toEqual对象与数组,javascript,unit-testing,Javascript,Unit Testing,我知道这是一个愚蠢的问题,但我一辈子也弄不明白为什么。我不熟悉测试,也不熟悉JavaScript,所以请提前道歉 我有以下测试 describe('initialized from copy job functionality', () => { it('should initialize the constructor based on production selection', () => { spyOn(MockWizardService, 'load
describe('initialized from copy job functionality', () => {
it('should initialize the constructor based on production selection', () => {
spyOn(MockWizardService, 'loadViewsForWizardSteps').and.returnValue(q.resolve({
templates
}));
controller.Init();
scope.$digest();
expect(controller.templatesToBeDisplayed).toEqual(templatesAll);
});
这些是我的模板
let templates = [
'views/wizards/create_test/sortStep.html',
];
let templatesAll = [
'views/wizards/create_test/general.html',
templates,
'views/wizards/create_test/summary.html'
];
模板
将更改,这就是我将其设置为该格式的原因。
这就是我得到的错误
预期$[1]=对象({templates:['views/wizards/create_test/sortStep.html']})等于['views/wizards/create_test/sortStep.html']
我知道我需要改变模板在templatesAll中的方式,但我不知道怎么做 您不能通过更改您的
expect
来修复它吗
expect(controller.templatesToBeDisplayed.templates).toEqual(templatesAll)
也许试着对你的问题更明确一点。您是否注意到它返回一个对象
,其中包含一个数组模板
?
您的测试不是很明确,因为很多代码隐藏在控制器中。试着测试一下小函数,也许如果你给我们看代码,我们会更有帮助
祝你好运:)