Spectator is a helper for Angular testing, that provides cleaner API and custom matchers, that makes testing easier. It helps you write tests without so much boilerplate code.
Questions tagged [angular-spectator]
49 questions
11
votes
4 answers
ReferenceError: customElements is not defined
I'm using @angular@9.0.7, @ngneat/spectator@5.3.1 (with Jest), Inputmask@5.0.3 in a project and everything works on application when I run ng serve or even ng build, but it fails when I try to run a test suite for a @Pipe that uses…

dev_054
- 3,448
- 8
- 29
- 56
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
4
votes
1 answer
Testing Angular interceptors response with Jest and Spectator
I'm trying to test an Interceptor that modifies the response from an HTTP Request.
Here's my current code:
@Injectable()
export class ResponseCamelCaseInterceptor implements HttpInterceptor {
intercept(
httpRequest: HttpRequest

dev_054
- 3,448
- 8
- 29
- 56
4
votes
3 answers
Error: No test scheduler initialized when using jasmine-marbles with Spectator in Angular test
My component subscribes to an Observable in a Service, which is populated via an Ngrx selector, generalized here for brevity:
export class MyService {
signInFalied$: Observable;
constructor(
private store: Store,
) {
…

Brandon Taylor
- 33,823
- 15
- 104
- 144
4
votes
0 answers
Angular Spectator setInput not working for non-string input
I've successfully converted my project to use Jest in place of Karma/Jasmine and I have lots of tests that are working just fine. I'm trying to do what should be a very simple test using Spectator (^5.2.1) but it's not working.
I'm trying to test a…

Tracy Williams
- 49
- 3
4
votes
0 answers
Integration test ReactiveForm, valueChanges method not triggered
I test a component with Spectator which contain in it's ngInit
listenToSuggestions() {
this.querySuggestions$ =
this.searchControl.valueChanges
.pipe(
tap(value => console.log(value)),
filter(value => value…

zagoa
- 798
- 4
- 23
4
votes
2 answers
Spectator Angular testing - pass input before ngOnInit
I am using Spectator to write my Angular 8 tests and Jest to run them. According to the README I can use setInput() to assign my value to the name of the field, which works. The problem is that The input is being validated AFTER the component is…

Babyburger
- 1,730
- 3
- 19
- 32
4
votes
1 answer
Angular Unit Testing with Spectator - Unexpected value 'FormBuilder' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation
I want to use spectator to assist me with my unit tests as I have read great things about it. However I'm not sure about how to resolve a problem with my tests. In my component template I have a formGroup like so...
3
votes
0 answers
Use Spectator (with Jest) on Angular 13 fails with error "Cannot find module '@angular/core/testing'"
An app runs on Angular version 12. Testing is done via Spectator based on Jest.
How to upgrade Angular 13 and have a working Spectator (Jest) test environment?
How to reproduce?
In this sample Angular 12 project you clone a Angular 12 project. Then…

tm1701
- 7,307
- 17
- 79
- 168
3
votes
3 answers
Mocking NgRx store with Spectator
I'm trying to write unit tests together with Angular, Jest and Spectator. Right now I'm struggling with mocking NgRx store. I'm getting a "No provider for MockStore" error when trying to get an instance of the NgRx provided MockStore from the…

F4irline
- 58
- 1
- 7
3
votes
0 answers
TypeError: testing.TestBed.inject is not a function ( jestjs with spectator )
I have this error when i run one test. I use jestjs with spectator to test my angular service
it('url path exist', () => {
expect(spectator.service.getPath).toBeDefined();
});

Omar
- 31
- 1
- 4
3
votes
1 answer
Mock Angular Router with Spectator
I am using Spectator to write my Angular 8 tests and Jest to run them. I am new to frontend unit testing, so I may have overlooked something simple; any ideas are welcome.
I have the following method (in Typescript) that returns a boolean, based on…

Babyburger
- 1,730
- 3
- 19
- 32
3
votes
1 answer
angular spectator mock Observable
I am trying to write a (fairly) complicated test using https://github.com/ngneat/spectator
I have a component which has 3 http services in ngOnInit.
Two of them are easy to mock, I can do it 2 ways (I think):
const FieldServiceMock = {
list:…

r3plica
- 13,017
- 23
- 128
- 290
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
Angular jest spectator mock service dependency while testing another service
I am using,
Angular CLI: 10.2.3
Node: 12.22.1
The project builds and runs fine. I am trying to add tests now using Jest and Spectator. I have the following service; I am trying to run a very basic test (can mock most of the values).
@Injectable({
…

Mihir
- 531
- 2
- 10
- 35