angular / angular/components

bug(Autocomplete): unit test using MatAutocompleteHarness fails when karma browser is in the foreground

Open
#22,428 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: material/autocomplete area: material/testing needs investigation P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

Reproduction

Steps to reproduce:

  1. In the console: npm run test
  2. Make sure NOT to bring the opened Chrome window showing Jasmine tests into the visibility
    If it opens in front, quickly click on some other window to bring the Chrome window to the background
  3. Observe: test succeeds
  4. make a small change in test (change spec name) to trigger test re-run
  5. Observe: test still succeeds
  6. Bring the Chrome window showing Jasmine tests into the visibility
  7. Observe: test fail

Recording:
https://user-images.githubusercontent.com/2098175/113951456-76f5b680-97c8-11eb-9893-5cca66ac1a8c.mp4

Expected Behavior

Unit test should pass.
Specifically, autocompleteHarness.getOptions() should return 3 options instead of 0

Actual Behavior

Unit test only passes while the Jasmine Chrome window is in the background

Environment
  • Angular: 11.2.8
  • CDK/Material: 11.2.7
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Tested on:
    • Windows
    • Mac
Notes

I have created a StackBlitz repository with basically the same code, but can't reproduce the issue there:
https://stackblitz.com/edit/harness-issue-2m77t5?file=src/app/autocomplete-harness-example.spec.ts

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and run npm run test, then reproduce the difference between a background and foreground Chrome window. Investigate the autocompleteHarness.getOptions() result, which should contain 3 options in both cases. Done means the unit test passes consistently when the Jasmine Chrome window is visible or in the background.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.