Skip to content

test(material/chips): prevent unintentional test success #22920

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

Merged
merged 1 commit into from
Jun 9, 2021

Conversation

jeripeierSBB
Copy link
Contributor

In 'MatChipInput' test, MatInputModule was not imported and therefore the matInput directive was not interpreted.
If importing MatInputModule into the testing module, the matInput directive gets applied and the test 'MatChipInput basic behavior should be aria-required if the list is required' would fail because of side effects by setting the aria-required attribute. Obviously, matInput does not remove the aria-required attribute, while the chips implementation is doing so (chips is interpreting false as null, while matInput leaves 'false' as-is).

In 'MatChipInput' test, `MatInputModule` was not imported and
therefore the `matInput` directive was not interpreted.
If importing `MatInputModule` into the testing module,
the `matInput` directive gets applied and
the test 'MatChipInput basic behavior should be aria-required
if the list is required' would fail because of side effects
by setting the `aria-required` attribute. Obviously,
`matInput` does not remove the `aria-required` attribute,
while the chips implementation is doing so
(chips is interpreting false as null, while `matInput`
leaves 'false' as-is).
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 8, 2021
@jeripeierSBB
Copy link
Contributor Author

The mentioned test case of chip-input.spec.ts

    it('should be aria-required if the list is required', () => {
      expect(inputNativeElement.hasAttribute('aria-required')).toBe(false);

      fixture.componentInstance.required = true;
      fixture.detectChanges();

      expect(inputNativeElement.getAttribute('aria-required')).toBe('true');
    });

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker merge safe target: patch This PR is targeted for the next patch release labels Jun 9, 2021
@andrewseguin andrewseguin merged commit 3cd1f52 into angular:master Jun 9, 2021
andrewseguin pushed a commit that referenced this pull request Jun 9, 2021
In 'MatChipInput' test, `MatInputModule` was not imported and
therefore the `matInput` directive was not interpreted.
If importing `MatInputModule` into the testing module,
the `matInput` directive gets applied and
the test 'MatChipInput basic behavior should be aria-required
if the list is required' would fail because of side effects
by setting the `aria-required` attribute. Obviously,
`matInput` does not remove the `aria-required` attribute,
while the chips implementation is doing so
(chips is interpreting false as null, while `matInput`
leaves 'false' as-is).

(cherry picked from commit 3cd1f52)
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 10, 2021
@jeripeierSBB jeripeierSBB deleted the chip-test branch January 5, 2022 11:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants