Attributes not present in elements returned by ngneat/spectator query

567 views Asked by At

I'm sure this is something simple but I can't figure out why the elements returned from a call to spectator.query() don't have any attributes.

Here's the code in my template:

<div class="my-4">
    <a [routerLink]="['../']">Back to Results</a>
</div>

I want to test that the href is going to the correct place for the routerLink.

   it('should have a routerLink back', () => {
        const link = spectator.query<HTMLAnchorElement>('a');
        expect(link).toBeTruthy();
        expect(link).toHaveAttribute('href');
    });

The test fails when trying to check for the href attribute but checking the app in the browser, the href is definitely there on the anchor tag.

Note; if I use any other type of way of setting attributes I get the same falsy result in the test e.g.

    <a data-cy="test1" [attr.test]="'test2'" [routerLink]="['../']">Back to Results</a>

I've checked the docs for spectator but can't see anything I'm missing.

0

There are 0 answers