question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(mat-tab-nav-bar): Having mat-tab-nav-bar on the page breaks harnesses if browser is not visible

See original GitHub issue

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

I already had the problem with Angular 12, but then couldn’t find the reason.

Description

Having mat-tab-nav-bar on the page breaks harnesses if browser is not visible.

Reproduction

Creating a stackblitz for this problem didn’t work, I tried to make the problem locally reproducible as easily as possible:

Steps to reproduce:

  1. create a new Angular project and add Angular Material:
ng new tabs-test --routing=false --style=scss
cd tabs-test
ng add @angular/material
  1. add MatTabsModule to app.module.ts

  2. change app.component.html to:

<nav mat-tab-nav-bar>
  <a mat-tab-link>
      Test
  </a>
</nav>
  1. create file: app.component.harness.ts with following content:
import { ComponentHarness } from '@angular/cdk/testing';

export class AppComponentHarness extends ComponentHarness {
  static readonly hostSelector = 'app-root';
}
  1. change the content of app.component.spec.ts to:
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { TestBed } from '@angular/core/testing';
import { MatTabsModule } from '@angular/material/tabs';
import { BrowserModule } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { AppComponentHarness } from './app.component.harness';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [
        AppComponent,
      ],
      imports: [
        BrowserModule,
        NoopAnimationsModule,
        MatTabsModule
      ],
    }).compileComponents();
  });

  fit('should create the app', async () => {
    const fixture = TestBed.createComponent(AppComponent);
    const harness = await TestbedHarnessEnvironment.harnessForFixture(fixture, AppComponentHarness);
    expect(harness).toBeTruthy();
  });
});

  1. run tests
ng test

By default the browser will pop up and be visible and the test will execute without a problem.

  1. Click refresh on the browser and minimize it or make sure the browser is not visible by hiding it behind another window like vscode

now the test will fail with following error: Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

Expected Behavior

The tests will succeed even if the browser is not visible.

Actual Behavior

If the browser is not visible the test will fail with following error: Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

Environment

  • Angular: 13.0.1
  • CDK/Material: 13.0.1
  • Browser(s): Chrome 95.0.4638.69 (64-Bit)
  • Operating System: Windows 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ckorherrcommented, Nov 22, 2021

I removed my workaround and applied your changes, the tests work as expected. Yes it resolves the issue.

0reactions
angular-automatic-lock-bot[bot]commented, Apr 10, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MatTabNavBar InkBar not showing active tab when rendered ...
I believe the root of the issue is when the mat-tab-nav-bar is rendered before the data the fills the nav-bar is available. In...
Read more >
CSS Page-Break Not Working in all Browsers - Stack Overflow
I only want to print the .pageBreak classes, hiding the #leftNav and the rest of the #mainBody with CSS. The CSS: @ ...
Read more >
@angular/material | Yarn - Package Manager
Designing and Implementing a CDK combobox component; Continuing to focus on improving the accessibility of Angular Material components. About the team. The ...
Read more >
Tabs - Angular Material
Can be used for improved accessibility when the tab does not have focusable ... from outside of the Tabs component as it causes...
Read more >
UNPKG - @angular/material
OnPush,\n})\nexport class MatTabNav extends _MatTabNavBase {\n ... component used by the table to control what page of the data is\n * displayed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found