问题
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