spec 没有 expextations Jasmine
spec has no expextations Jasmine
这是我第一次 angular 测试。我为此使用 Jasmine 和 Karma。所以诀窍是,这个测试实际上通过了,我在覆盖率报告中看到了它。但是测试给了我一个错误,“Spec 'AppComponent should check function closeMenus()' 没有期望。”尽管。我有以下代码:
app.components.ts
import { Component, ViewChild, Directive } from '@angular/core';
import { MatSidenav } from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'myApp';
@ViewChild('sidenav', {static:true}) sidenavbar : MatSidenav;
openmenu : string = "";
closeMenus() {
this.sidenavbar.close();
}
}
app.component.spec.ts
import { AppComponent } from './app.component';
import { TestBed, async, fakeAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import * as material from '@angular/material';
describe('AppComponent', async() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
material.MatAutocompleteModule,
...
material.MatTooltipModule,
],
declarations: [
AppComponent,
],
}).compileComponents();
}));
// works but SPEC HAS NO EXPECTATIONS
it('should check function closeMenus()', (() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
spyOn(app.sidenavbar, 'close');
app.closeMenus();
expect(app.sidenavbar.close).toHaveBeenCalled;
}));
});
我是不是做错了什么?
感谢您的帮助,祝您有愉快的一天:)
您未达到预期 ()
:
expect(app.sidenavbar.close).toHaveBeenCalled();
这是我第一次 angular 测试。我为此使用 Jasmine 和 Karma。所以诀窍是,这个测试实际上通过了,我在覆盖率报告中看到了它。但是测试给了我一个错误,“Spec 'AppComponent should check function closeMenus()' 没有期望。”尽管。我有以下代码:
app.components.ts
import { Component, ViewChild, Directive } from '@angular/core';
import { MatSidenav } from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'myApp';
@ViewChild('sidenav', {static:true}) sidenavbar : MatSidenav;
openmenu : string = "";
closeMenus() {
this.sidenavbar.close();
}
}
app.component.spec.ts
import { AppComponent } from './app.component';
import { TestBed, async, fakeAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import * as material from '@angular/material';
describe('AppComponent', async() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
material.MatAutocompleteModule,
...
material.MatTooltipModule,
],
declarations: [
AppComponent,
],
}).compileComponents();
}));
// works but SPEC HAS NO EXPECTATIONS
it('should check function closeMenus()', (() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
spyOn(app.sidenavbar, 'close');
app.closeMenus();
expect(app.sidenavbar.close).toHaveBeenCalled;
}));
});
我是不是做错了什么?
感谢您的帮助,祝您有愉快的一天:)
您未达到预期 ()
:
expect(app.sidenavbar.close).toHaveBeenCalled();