Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type 'By' is not assignable to parameter of type 'Predicate<DebugElement>'

I'm experimenting with Protractor (5.4.2) and trying to test my Angular component. I created the following test, inspired by the Unit testing in Angular course from Joe Eames.

The (working) example from the course enter image description here

My (faulty) code

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DetailsComponent } from './details.component';
import { By } from 'protractor';

describe('DetailsComponent', () => {
    let fixture: ComponentFixture<DetailsComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [DetailsComponent]
        })
            .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(DetailsComponent);

        fixture.detectChanges();
    });

     it('contains 3 titles', () => {
        expect(fixture.debugElement.queryAll(By.css('.card-title')).length).toBe(3);
    });
});

However, the following type error occurres in the .query invocation in the test method:

Argument of type 'By' is not assignable to parameter of type 'Predicate'.

I don't understand why this error occurs as my code looks similair to the example.

like image 865
Wouter van Koppen Avatar asked Jul 16 '19 13:07

Wouter van Koppen


1 Answers

This error occurred because you imported By from the protractor instead of the @angular/platform-browser module.

Change this import { By } from 'protractor'; to the import { By } from '@angular/platform-browser';

like image 165
Yevhen Laichenkov Avatar answered Oct 19 '22 23:10

Yevhen Laichenkov