spec没有扩展名茉莉花

问题描述 投票:0回答:1

这是我第一次进行角度测试。我正在使用茉莉花和业力。诀窍在于,该测试实际上通过了,我在覆盖率报告中看到了它。但是测试给我一个错误,“ Spec'AppComponent应该检查功能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;
  }));
});

我在这里做错什么了吗?

感谢您的帮助,祝您有美好的一天:)

angular jasmine karma-runner karma-coverage
1个回答
1
投票

您期望中缺少()

expect(app.sidenavbar.close).toHaveBeenCalled();
© www.soinside.com 2019 - 2024. All rights reserved.