Is it necessary to create a unit test for a basic operation involving RxJS?

Imagine a straightforward class that triggers a new event to an RxJS subject whenever the window is resized. Disregard any perceived complexities, as the main point is that this class generates an event.

        export class ResizeService {
          private resizeSubject = new Subject();

          public onResize(): Observable<Window> {
            return this.resizeSubject.asObservable();
          }

          constructor(private eventManager: EventManager) {
            this.eventManager.addGlobalEventListener('window', 'resize', (e) => {
              this.resizeObject.next(<Window>event.target)   
            })
          }

          private onResize(event: UIEvent) {
            this.resizeObject.next(<Window>event.target);
          }
        }

The question at hand revolves around whether we should verify in our unit tests that the newly emitted event sent to the RxJS subject will indeed be received by the client calling the onResize method. Consider the following example:

it('should emit a value', fakeAsync(() => {
     let subscriptionWorks = false;
     fireWindowResizeEvent(new Event({width: 600; height: 400});
     resizeService.onResize().subscribe(() => subscriptionWorks = true);
     expect(subscriptionWorks).toBeTruthy();
  })
)

In the scenario where a developer alters the onResizeMethod to include additional logic like skipping elements, the test would fail:

public onResize(): Observable<Window> {
  return this.resizeSubject.asObservable().skip(10);
}

Answer №1

Based on my understanding, it seems like you are referring to conducting an integration test for the interaction between your ResizeService and client application. In this case, there is no requirement for a separate unit test as the integration test should cover it adequately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a visual representation of progress over time by utilizing a single horizontally stacked bar chart with ChartJS

Can chartjs be configured to show horizontal stacked bars for continuous data over time? It's more of a progress visualization than a traditional chart. I am struggling to display multiple data points per label and have them shown as one bar. I have ...

CORS regulations are preventing access

I have set up an Express server to run my Angular app for server-side rendering purposes. Initially, everything works fine when I make a request from the application. However, an issue arises when I navigate to another page and then return to the previous ...

The JSX component cannot be utilized as `ToastContainer`

Check out this Code: import axios from "axios"; import React, { useState, useEffect } from "react"; import { ToastContainer, toast } from "react-toastify"; import loaderIcon from "../../assets/images/loader.gif"; imp ...

Is there an automatic bottom padding feature?

Currently, I am facing a challenge in fitting the loader into the container without it being overridden by the browser. Using padding-bottom is not an ideal solution as it results in the loader appearing un-resized and unprofessional. Any suggestions or co ...

Tips for personalizing the ngx-bootstrap datepicker

I am looking to enhance the ngx-bootstrap datepicker popup by adding a link or button within the calendar to select dates with a single click. I have been exploring ways to customize the datepicker without success. Currently, my project is built using Angu ...

Using Angular2 Router can sometimes result in template "overwrites"

My routing implementation seems to be causing issues in my app. When I click the Login button, it should direct me to a new login page. However, instead of navigating away from the main page (VehicleComponent), it creates the login page within the main pag ...

Tips for automatically scrolling to the bottom of an element in NgFor when adding new elements

import { Component, Input, AfterViewInit, ViewChild } from '@angular/core'; @Component({ selector: 'hello', template: `<h1>Hello {{name}}!</h1> <div #commentDetailWrapper style="height: 100px; border: 1px solid; w ...

Implementing asynchronous validation in Angular 2

Recently started working with Angular 2 and encountered an issue while trying to validate an email address from the server This is the form structure I have implemented: this.userform = this._formbuilder.group({ email: ['', [Validators.requir ...

Tips for avoiding the influence of the parent div's opacity on child divs within a Primeng Carousel

I'm struggling to find a solution to stop the "opacity" effect of the parent container from affecting the child containers. In my code, I want the opacity not to impact the buttons within the elements. I have tried using "radial-gradient" for multipl ...

Displaying a list of items in a dropdown menu that includes both the item's ID and name using angular

I am currently utilizing the angular2-multiselect-dropdown to connect with server values. interface PayerDummyObjType{ id: string; itemName: string; } PayerDummyObjType: PayerDummyObjType[]; PayerDummyObjTypeSelected: PayerDummyObjType[]; dropdownSettin ...

The 'data' property is absent in the 'never[]' type, whereas it is necessary in the type of product data

Hello, I am new to TypeScript and I'm struggling with fixing this error message: Property 'data' is missing in type 'never[]' but required in type '{ data: { products: []; }; }'. Here is my code snippet: let medias :[] ...

Issue with importing aliases in Angular 7 production environment

Hello everyone! I have encountered an issue where using alias on import and building the project in production mode (--prod flag) results in the alias being undefined. Interestingly, this behavior does not occur in development mode. Any suggestions on how ...

I'm interested in knowing how to switch between two functions using Angular

I have developed a grocery list application where each row contains the name of a food item. The layout includes a left column for items that are not needed and a right column for items that are needed. Currently, I am able to change the state by clicking ...

Adding an object to an array in Postgres with TypeORM

I am currently facing an issue with the column in my Postgres database that has a data type of json. The code snippet for this scenario is as follows: @Column({ type: 'jsonb', nullable: false, default: [] }) us ...

Utilizing a variety of Reactive FormGroups to manage a shared data source

My data source is structured as follows: data = { Bob: { hobbies: ['cycling', 'swimming'], pets: ['cat', 'dog'] }, Alice: { hobbies: ['cycling, 'chess'] ...

Retrieving the attribute key from a dynamically typed object

Having this specific interface structure: interface test { [key: string]: string } along with an object defined as follows: const obj: test ={ name: 'mda', telephone: '1234' } Attempting to utilize this object in a variab ...

Deactivate a variable during operation

I have a unique component called book-smart that has the functionality to display either book-update or book-create based on the availability of a BookDto in my book.service. The update feature can be accessed by clicking a button in a table, while the cre ...

Using Typescript types or a linter can help avoid mistakenly rendering the raw function in JSX instead of its executed return value

Seeking a resolution to prevent the recurring mistake I often make, as shown below: export function scratch_1 (props: scratch_1Props): ReactElement | null { function renderA (): string { return "A"; } function renderB (): string { ...

What is the best way to design a circular icon using OpenLayers?

I am currently incorporating openlayers into my ionic app and working on placing users on the map. I have encountered a problem as I am unsure how to apply custom CSS styling to the user element, which is not directly present in the HTML. In the screenshot ...

Generating a UTC timestamp in TypeScript

I am currently facing an issue with my application where I need to ensure that it always uses UTC time, regardless of the system time. I have a method in place to create a date: public static createDate(date: Date = new Date()): Date { return new Dat ...