Questions tagged [spectator]

18 questions
4
votes
1 answer

Testing text field input with Spectator

I'm trying to test my directive with @ngneat/spectator version 6.1.1 it('should allow all numbers', () => { spectator = createDirective('') const input = spectator.query('input') as HTMLInputElement …
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
3
votes
1 answer

How to provide service mock in SpectatorRouting

I implemented a test using Spectator for the Angular component. Try to find a solution to mocking service with SpectatorRouting. I have simple service like the below: export class ProductService { constructor(private http: HttpClient) {} …
marianciu
  • 557
  • 4
  • 12
2
votes
1 answer

Global import of modules with Jest and Spectator

In my Angular project, I have removed Karma in order to use Jest.js with Spectator instead. It works well, but now, as the module related to translations is a bit verbose, I am trying to import it globally. I read in the documentation of Spectator…
Pierre
  • 1,044
  • 15
  • 27
2
votes
1 answer

Spectator: override provider for single test (angular universal)

I built a small angular app and now I'm writing unit tests. So far so good, but when I try to test my authGuard I ran into some problems. I am using Spectator. I provide the platformId in the providers section in my spec, but I want to be able to…
Chai
  • 1,796
  • 2
  • 18
  • 31
1
vote
1 answer

Testing Angular 14 Standalone Components with Spectator

Our test runner is Jest. Our component is marked as standalone: true, If try to set up spectator like this: describe('OurComponent', () => { let spectator: Spectator; const fakeActivatedRoute: ActivatedRoute = { …
1
vote
0 answers

Spectator Jest Angular cant find nested text with byText or ByTextContent

I try to test my template, if a certain text was rendered. The first result with "textICanFindWithByText" works great with ByText. The text im looking for and where I have problems with is "textIWantToFindWithByTextOrByTextContent" I cant seem to…
s.stkvc
  • 127
  • 1
  • 2
  • 12
1
vote
0 answers

OpenAPI / Spectator do not validate response definitions

In phpunit, I validate the API responses to be compatible with the OpenAPI 3.0 spec by using Spectator. None of the response objects seem to be validated though when using $response->assertValidRequest()->assertValidResponse(200); A controller that…
Ron Wanink
  • 11
  • 1
1
vote
1 answer

`TypeError: Converting circular structure to JSON` error when writing tests for an angular component that utilizes routerLink, Spectator, and Jest

I'm trying to slowly whittle away at errors within a complex module in my application while setting up a new testbed for my application. I'm utilizing the routing factory api from spectator to create my test bed…
1
vote
0 answers

How can I import a module from another library for an Angular Jest test?

I can successfully run a jest test for a component that uses the import command IF I am importing from a relative path or from node_modules. So, this is working for my.component.spec.ts: import {MyComponent} from './my.component'; import…
Tim
  • 1,605
  • 6
  • 31
  • 47
1
vote
1 answer

Angular component test with spectator logs "can't bind to input" warnings for mocked child component

I'm facing an issue mocking a child component in an Angular 9 component test using @ngneat/spectator. The mocking and passing of the mock work fine, but it throws warnings in the logs for the inputs (even though they are valid). The simplified…
bbop99
  • 1,625
  • 1
  • 11
  • 25
1
vote
1 answer

Angular Jest Spectator - focus function does not work

So, I have Angular component that looks like this
and I'm trying to write test for case - when user is focused in div, pressing enter should call doSomething(). Unfortunately, I cannot mock…
Kamil Naja
  • 6,267
  • 6
  • 33
  • 47
0
votes
0 answers

Ionic Angular tests with Spectator/Jest: Are sleeps necessary?

I am trying to write Unit Tests for my Angular App that uses Ionic Components. My HTML looks like this:
Cola_Colin
  • 415
  • 5
  • 16
0
votes
1 answer

Is this correct that I would have to modify all the code that uses arrow functions in order to test them?

My background with unit testing is minimal. From what I've found on Google it appears that I would have to change a lot of the code in our application in order to unit test arrow function code. So, if code were as follow class MyComponent { fun:…
edjm
  • 4,830
  • 7
  • 36
  • 65
0
votes
1 answer

Angular unit test case for @HostListener escape key event

I have below code in my component @HostListener('document:keydown', ['$event']) onKeydownHandler(event: KeyboardEvent) { if (event.key === 'Escape') { this.showDialogPopup = false; this.showPortfolioDialogPopup = false; } } And I am using…
vamsi
  • 1,488
  • 3
  • 28
  • 66
0
votes
1 answer

Use jest-mock-extended and Spectator for angular components testing

I'm already using successfully using jest-mock-extended to test services and it works fine for me. It's simple, easy to use and type safe. Now I have to test Angular components. For this purpose I've found Spectator. I managed to write tests for…
chenny
  • 769
  • 2
  • 17
  • 44
1
2