DEV Community

Arya
Arya

Posted on

Browser refresh on click of Home button using href

I have a question on writing angular testcases on browser refresh.
Angular is a single page application .there is no browser refresh after logging in. I am building a website with angular in the frontend but not entirely. You will see what i mean in the below example scenario

When I am in Contacts page of the application ,and I click on the logo ,it should navigate me to the homepage always.
I could have simply gone with router link, but there is a catch.
See when Iam in contacts page of the application, the contacts tab is selected in the left-nav-item. When i click on the logo to navigate to the home button, the selection should not be there anymore. means it should work like a browser refresh. For that ,Iam using href instead of router link


Logo

This will reload the page. See, what i mean when i said not fully angular .

Now my issue is with the testcases.I cant write element.click()

it("should navigate to home page on click of logo",() => {
const element = fixture.nativeElement.querySelector(".appName a") as HTMLElement;

spyOn(window.location, 'reload');
element.click();
expect(window.location.reload).toHaveBeenCalled();
});

here element.click() will reload the page and so the test cases also stop to return Not Found.

I need to trigger the click() here to check if the browser is refreshed.Any suggestion on how to achieve it?

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay