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

霸气de小男生 提交于 2019-12-24 05:07:05

问题


Setting up jasmine-query-matches in angular6

On angular 5 project it looks at simple as

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

On angular 6 i have tried the following

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';

OR

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

Usage as follows

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

and

expect(imagesEL).toBeVisible();

or

expect(imagesEL.nativeElement).toBeVisible();

But every thing seems to be giving the same error

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

Thanks for helping

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


回答1:


try to use this as your imports

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

Please note that jasmine-jquery-matchers does not have a default export




回答2:


toBeVisible() should be applied on nativeElement

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


来源:https://stackoverflow.com/questions/51463562/angular6-jasmine-typeerror-expect-tobevisible-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!