Angular6 Jasmine TypeError: expect(...).toBeVisible is not a function

Angular6 Jasmine TypeError: expect(...).toBeVisible is not a function

在 angular6 中设置 jasmine-query-matches

在 angular 5 项目上它看起来很简单

import { } from 'jasmine-jquery/lib/jasmine-jquery';
import { } from 'jasmine-jquery-matchers';
import * as $ from 'jquery';

在 angular 6 我尝试了以下

import {} from "jasmine-jquery/lib/jasmine-jquery" ;
import {} from "jasmine-jquery-matchers/dist/jasmine-jquery-matchers" ;
import { } from "karma-jasmine-jquery";
import * as $ from 'jquery';

import {} from "jasmine-jquery" ;
import {} from "jasmine-jquery-matchers" ;
import { } from "karma-jasmine-jquery";
import * as $ from 'jquery';

用法如下

imagesEL = fixture.debugElement.query(By.css('.cycle'));

expect(imagesEL).toBeVisible();

expect(imagesEL.nativeElement).toBeVisible();

但是每件事似乎都给出了同样的错误

TypeError: expect(...).toBeVisible is not a function

感谢您的帮助

Sample Code : https://stackblitz.com/edit/ng-test-tobevisible?file=app/hello.component.spec.ts

toBeVisible() 应应用于 nativeElement

imagesEL = fixture.debugElement.query(By.css('.cycle'));
expect(imagesEL.nativeElement).toBeVisible();

尝试将其用作您的导入

import "jasmine-jquery/lib/jasmine-jquery" ;
import "jasmine-jquery-matchers/dist/jasmine-jquery-matchers" ;
import "karma-jasmine-jquery";
import 'jquery';

请注意 jasmine-jquery-matchers 没有默认导出