Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post: angular unit testing with spectator #65

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ Edgar Barragan:
name : "Edgar Garcia Barragan"
avatar : "assets/images/avatars/edgar_barragan.png"
bio : "Senior Android Engineer - Customer Success"

Utku:
name : "Utku"
avatar : "assets/images/avatars/utku.jpeg"
bio : "Frontend Engineer - Customer Success"
255 changes: 255 additions & 0 deletions _posts/2023-10-25-angular-unit-testing-with-spectator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
---
title: "Angular Unit Testing with Spectator"
excerpt: "A robust testing library for unit testing"
tags: Web Angular testing
authors:
- Utku
header:
teaser: /assets/images/post/spectator-banner.png
teaser_alt: Spectator banner
category: Frontend
---

![](/assets/images/post/spectator-banner.png)

# Introduction

Spectator is a powerful testing tool designed to simplify Angular testing. It is built on top of the TestBed API and effectively reduces the boilerplate code associated with the built-in TestBed API. By doing so, Spectator delivers a more efficient and developer-friendly testing experience. In this article, we discuss Spectator test cases, installation, testing components and services, advantages, drawbacks, and migrating to Spectator.

Check warning on line 17 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L17

[write-good.TooWordy] 'It is' is too wordy.
Raw output
{"message": "[write-good.TooWordy] 'It is' is too wordy.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 17, "column": 76}}}, "severity": "WARNING"}

Check warning on line 17 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L17

[write-good.Passive] 'is built' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'is built' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 17, "column": 79}}}, "severity": "WARNING"}

Check warning on line 17 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L17

[Google.We] Try to avoid using first-person plural like 'we'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 17, "column": 310}}}, "severity": "WARNING"}

# Understanding Spectator Test Cases

Check warning on line 19 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L19

[Google.Headings] 'Understanding Spectator Test Cases' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Understanding Spectator Test Cases' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 19, "column": 3}}}, "severity": "WARNING"}

Spectator supports three main types of test cases:

1. **Isolated unit tests**:
Corresponding to [**Component class testing**](https://angular.io/guide/testing-components-basics#component-class-testing) mentioned in Angular.io.
These tests focus on testing component, directive, pipe, and service classes in isolation. Additionally, Spectator supports writing tests for routing and HTTP communication. It is essential to mock dependencies to ensure tests are isolated.

Check warning on line 25 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L25

[write-good.Weasel] 'Additionally' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'Additionally' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 25, "column": 95}}}, "severity": "WARNING"}

Check warning on line 25 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L25

[write-good.TooWordy] 'It is' is too wordy.
Raw output
{"message": "[write-good.TooWordy] 'It is' is too wordy.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 25, "column": 178}}}, "severity": "WARNING"}

Check warning on line 25 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L25

[write-good.Passive] 'are isolated' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'are isolated' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 25, "column": 231}}}, "severity": "WARNING"}

2. **Shallow component tests**:
Corresponding to [**Component DOM testing**](https://angular.io/guide/testing-components-basics#component-dom-testing) mentioned in Angular.io.
Shallow component tests focus on testing a component with a template, but ignoring the rendering of child components. By passing the 'shallow: true' option into the configuration, we can achieve this quite easily with Spectator.

Check warning on line 29 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L29

[Google.We] Try to avoid using first-person plural like 'we'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 29, "column": 184}}}, "severity": "WARNING"}

Check warning on line 29 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L29

[write-good.Weasel] 'easily' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'easily' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 29, "column": 210}}}, "severity": "WARNING"}

3. **Integration tests**:
Corresponding to [**Component DOM testing**](https://angular.io/guide/testing-components-basics#component-dom-testing) mentioned in Angular.io.
Integration tests focus on testing how two or more components work together. These tests are particularly useful when components depend on each other.

Check warning on line 33 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L33

[write-good.Weasel] 'particularly' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'particularly' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 33, "column": 97}}}, "severity": "WARNING"}

In the following sections, we delve deeper into the installation process, testing components and services, and the advantages and drawbacks of using Spectator.

Check warning on line 35 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L35

[Google.We] Try to avoid using first-person plural like 'we'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'we'.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 35, "column": 28}}}, "severity": "WARNING"}

## Installing Spectator

Check warning on line 37 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L37

[Google.Headings] 'Installing Spectator' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Installing Spectator' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 37, "column": 4}}}, "severity": "WARNING"}

To install Spectator, you can use either yarn or npm:

`yarn add @ngneat/spectator --dev`

`npm install @ngneat/spectator --save-dev`

Spectator uses **Jasmine** by default, but it supports **Jest** as well.
To be able to use it with Jest, make sure to target your imports from `@ngneat/spectator/jest` instead of `@ngneat/spectator`.

# Testing Components with Spectator

Check warning on line 48 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L48

[Google.Headings] 'Testing Components with Spectator' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Testing Components with Spectator' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 48, "column": 3}}}, "severity": "WARNING"}

When testing components with Spectator, the first step is to create a component factory using the `createComponentFactory` function and pass the component class you want to test. This factory function returns a new component for each test block. Spectator offers various options for the `createComponentFactory` function, allowing you to customize your testing environment.

```typescript
import { Spectator, createComponentFactory } from "@ngneat/spectator";
import { ButtonComponent } from "./button.component";

describe("ButtonComponent", () => {
let spectator: Spectator<ButtonComponent>;
const createComponent = createComponentFactory(ButtonComponent);

beforeEach(() => (spectator = createComponent()));

it("should have a success class by default", () => {
expect(spectator.query("button")).toHaveClass("success");
});

it("should set the class name according to the [className] input", () => {
spectator.setInput("className", "danger");
expect(spectator.query("button")).toHaveClass("danger");
expect(spectator.query("button")).not.toHaveClass("success");
});
});
```

The `createComponentFactory` function can optionally take the following options which extends the basic Angular Testing Module options:

```typescript
const createComponent = createComponentFactory({
component: ButtonComponent,
imports: [],
providers: [],
declarations: [],
entryComponents: [],
componentProviders: [], // Override the component's providers
componentViewProviders: [], // Override the component's view providers
overrideModules: [], // Override modules
mocks: [], // Providers that will automatically be mocked
componentMocks: [], // Component providers that will automatically be mocked
componentViewProvidersMocks: [], // Component view providers that will be automatically mocked
detectChanges: false, // Defaults to true
declareComponent: false, // Defaults to true
disableAnimations: false, // Defaults to true
shallow: true, // Defaults to false
});
```

After creating the component factory, you can use the `createComponent` function to test different aspects of your component, such as setting inputs, testing outputs, or running detectChanges().

The `createComponent` function optionally takes the following options:

```typescript
it("should...", () => {
spectator = createComponent({
// The component inputs
props: {
title: "Click",
},
// Override the component's providers
providers: [],
// Whether to run change detection (defaults to true)
detectChanges: false,
});

expect(spectator.query("button")).toHaveText("Click");
});
```

The `createComponent()` method returns an instance of `Spectator` which exposes the following properties:

- `fixture` - The tested component's fixture
- `component` - The tested component's instance
- `element` - The tested component's native element
- `debugElement` - The tested fixture's debug element

And the following methods:

- **inject()**
<br>
Provides a wrapper for Ivy's `TestBed.inject()`:

```typescript
const service = spectator.inject(QueryService);
const fromComponentInjector = true;
const service = spectator.inject(QueryService, fromComponentInjector);
```

- **detectChanges()**
<br>
Runs `detectChanges` on the tested element/host:

```typescript
spectator.detectChanges();
```

- **setInput()**
<br>
Changes the value of an `@Input()` of the tested component:

```typescript
it("should...", () => {
spectator.setInput("className", "danger");

spectator.setInput({
className: "danger",
});
});
```

- **output()**
<br>
Returns an observable `@Output()` of the tested component:

```typescript
it("should emit the $event on click", () => {
let output;
spectator.output("click").subscribe((result) => (output = result));

spectator.component.onClick({ type: "click" });
expect(output).toEqual({ type: "click" });
});
```

- **tick(millis?: number)**
<br>
Run the fakeAsync `tick` function and call `detectChanges()`:
```typescript
it("should work with tick", fakeAsync(() => {
spectator = createComponent(ZippyComponent);
spectator.component.update();
expect(spectator.component.updatedAsync).toBeFalsy();
spectator.tick(6000);
expect(spectator.component.updatedAsync).not.toBeFalsy();
}));
```

# Testing Services with Spectator

Check warning on line 185 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L185

[Google.Headings] 'Testing Services with Spectator' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Testing Services with Spectator' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 185, "column": 3}}}, "severity": "WARNING"}

To test services with Spectator, import the `createServiceFactory` and `SpectatorService` functions, and then create a service factory using the `createServiceFactory` function.

```typescript
import { createServiceFactory, SpectatorService } from "@ngneat/spectator";

import { AuthService } from "auth.service.ts";

describe("AuthService", () => {
let spectator: SpectatorService<AuthService>;
const createService = createServiceFactory(AuthService);

beforeEach(() => (spectator = createService()));

it("should not be logged in", () => {
expect(spectator.service.isLoggedIn()).toBeFalsy();
});
});
```

The `createService` function returns `SpectatorService` with the following properties:

- `service` - Get an instance of the service
- `inject()` - A proxy for Angular `TestBed.inject()`

**For detailed examples, further information and other use cases, please refer to the official Spectator documentation:** [https://github.com/ngneat/spectator](https://github.com/ngneat/spectator/)

# Generating Spec Files with Angular CLI and Spectator Schematics

Check warning on line 213 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L213

[Google.Headings] 'Generating Spec Files with Angular CLI and Spectator Schematics' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Generating Spec Files with Angular CLI and Spectator Schematics' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 213, "column": 3}}}, "severity": "WARNING"}

Check warning on line 213 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L213

[Google.WordList] Use 'command-line tool' instead of 'CLI'.
Raw output
{"message": "[Google.WordList] Use 'command-line tool' instead of 'CLI'.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 213, "column": 38}}}, "severity": "WARNING"}

Creating spec files with Spectator configuration is made simple with the provided schematics.

Check warning on line 215 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L215

[write-good.Passive] 'is made' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'is made' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 215, "column": 50}}}, "severity": "WARNING"}

To generate spec files:

For a component spec, run: `ng g cs example-component`

For a service spec, run: `ng g ss example-service`

For a directive spec, run: `ng g ds example-directive`

# Advantages of Using Spectator

Check warning on line 225 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L225

[Google.Headings] 'Advantages of Using Spectator' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Advantages of Using Spectator' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 225, "column": 3}}}, "severity": "WARNING"}

Testing can sometimes be more challenging and time-consuming than the actual implementation. Configuring TestBed correctly may even take longer than writing the tests themselves. Spectator significantly improves the developer experience by making it easier and faster to write tests. As a result, it helps overcome the tendency to skip writing tests. Spectator achieves this by:

Check warning on line 227 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L227

[write-good.Weasel] 'correctly' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'correctly' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 227, "column": 114}}}, "severity": "WARNING"}

Check warning on line 227 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L227

[write-good.Weasel] 'significantly' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'significantly' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 227, "column": 190}}}, "severity": "WARNING"}

- Simplifying test spec configuration by providing readable and concise API which helps to reduce boilerplate code.
- Improving readability and maintainability by providing a set of expressive and easier to understand custom matchers and assertions.
- Making mocking and spying easier.

# Drawbacks of Using Spectator

Check warning on line 233 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L233

[Google.Headings] 'Drawbacks of Using Spectator' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'Drawbacks of Using Spectator' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 233, "column": 3}}}, "severity": "WARNING"}

- Learning curve might be considered steep.

Check warning on line 235 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L235

[write-good.Passive] 'be considered' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be considered' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 235, "column": 24}}}, "severity": "WARNING"}
- Official documentation might be considered relatively limited.

Check warning on line 236 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L236

[write-good.Passive] 'be considered' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be considered' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 236, "column": 32}}}, "severity": "WARNING"}

Check warning on line 236 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L236

[write-good.Weasel] 'relatively' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'relatively' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 236, "column": 46}}}, "severity": "WARNING"}
- Compatibility issues may arise with newer Angular version even though it might be temporary.

# Migrating

Spectator can be adopted gradually since it is not a complete replacement rather an enhancement. Whenever Spectator test suits are started to be written, these test suits can be kept in a separate file with `spectator` suffix. For example, `transactions.component.spectator.spec.ts`. Once the project is fully migrated to spectator, the `spectator` suffix can be omitted from all test file names.

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.Passive] 'be adopted' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be adopted' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 15}}}, "severity": "WARNING"}

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.TooWordy] 'it is' is too wordy.
Raw output
{"message": "[write-good.TooWordy] 'it is' is too wordy.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 42}}}, "severity": "WARNING"}

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.Passive] 'are started' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'are started' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 128}}}, "severity": "WARNING"}

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.Passive] 'be written' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be written' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 143}}}, "severity": "WARNING"}

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.Passive] 'be kept' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be kept' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 176}}}, "severity": "WARNING"}

Check warning on line 241 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L241

[write-good.Passive] 'be omitted' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be omitted' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 241, "column": 361}}}, "severity": "WARNING"}

For integration tests, there is also an approach that to create a separate test file with `integration` suffix to keep integration tests separate from rest of the test suites. For example, `transactions.component.integration.spec.ts`.

With a proper migration plan in place, developers can smoothly transition from their existing testing setup to Spectator without disrupting the project.

Check warning on line 245 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L245

[write-good.Weasel] 'smoothly' is a weasel word!
Raw output
{"message": "[write-good.Weasel] 'smoothly' is a weasel word!", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 245, "column": 55}}}, "severity": "WARNING"}

# Conclusion

By leveraging the power of Spectator, developers can enjoy a more efficient and user-friendly testing experience. With its simplified test spec configuration, improved readability, and enhanced mocking capabilities, Spectator is a valuable addition to any Angular project. Although it comes with a learning curve, the advantages it offers make it a worthwhile investment for improving your testing workflow. For developers looking to streamline their Angular testing process, Spectator is a powerful and versatile tool that can help you achieve your goals.

# References and Additional Resources

Check warning on line 251 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L251

[Google.Headings] 'References and Additional Resources' should use sentence-style capitalization.
Raw output
{"message": "[Google.Headings] 'References and Additional Resources' should use sentence-style capitalization.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 251, "column": 3}}}, "severity": "WARNING"}

Check warning on line 251 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L251

[write-good.TooWordy] 'Additional' is too wordy.
Raw output
{"message": "[write-good.TooWordy] 'Additional' is too wordy.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 251, "column": 18}}}, "severity": "WARNING"}

- [Spectator Documentation](https://github.com/ngneat/spectator)
- [testing-angular.com](https://testing-angular.com/testing-components-with-spectator/#testing-components-with-spectator)
- An in depth comparison between regular test specs and spectator test specs can be found in this open-source project: [https://github.com/9elements/angular-workshop](https://github.com/9elements/angular-workshop). <br> Each test spec in this project has a jasmine and a spectator alternative allowing to make comparison as well as serving as a reference for additional use cases.

Check warning on line 255 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L255

[write-good.Passive] 'be found' may be passive voice. Use active voice if you can.
Raw output
{"message": "[write-good.Passive] 'be found' may be passive voice. Use active voice if you can.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 255, "column": 82}}}, "severity": "WARNING"}

Check warning on line 255 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L255

[Google.WordList] Use 'open source' instead of 'open-source'.
Raw output
{"message": "[Google.WordList] Use 'open source' instead of 'open-source'.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 255, "column": 99}}}, "severity": "WARNING"}

Check warning on line 255 in _posts/2023-10-25-angular-unit-testing-with-spectator.md

View workflow job for this annotation

GitHub Actions / vale

[vale] _posts/2023-10-25-angular-unit-testing-with-spectator.md#L255

[write-good.TooWordy] 'additional' is too wordy.
Raw output
{"message": "[write-good.TooWordy] 'additional' is too wordy.", "location": {"path": "_posts/2023-10-25-angular-unit-testing-with-spectator.md", "range": {"start": {"line": 255, "column": 360}}}, "severity": "WARNING"}
Binary file added assets/images/avatars/utku.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/post/spectator-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading