refactor(common): change missing NgSwitch provider error message (#41704)
change error message of invalid NgSwitch use and add corner cases tests PR Close #41704
This commit is contained in:
committed by
Alex Rickabaugh
parent
2b939767fe
commit
640ec7828f
@@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Attribute, Component, Directive, TemplateRef, ViewChild} from '@angular/core';
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {Attribute, Component, Directive, TemplateRef, ViewChild,} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
{
|
||||
@@ -176,6 +176,24 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
detectChangesAndExpectText('when b1;when b2;');
|
||||
});
|
||||
|
||||
it('should throw error when ngSwitchCase is used outside of ngSwitch', waitForAsync(() => {
|
||||
const template = '<div [ngSwitch]="switchValue"></div>' +
|
||||
'<div *ngSwitchCase="\'a\'"></div>';
|
||||
|
||||
expect(() => createTestComponent(template))
|
||||
.toThrowError(
|
||||
'NG0305: An element with the "ngSwitchCase" attribute (matching the "NgSwitchCase" directive) must be located inside an element with the "ngSwitch" attribute (matching "NgSwitch" directive)');
|
||||
}));
|
||||
|
||||
it('should throw error when ngSwitchDefault is used outside of ngSwitch', waitForAsync(() => {
|
||||
const template = '<div [ngSwitch]="switchValue"></div>' +
|
||||
'<div *ngSwitchDefault></div>';
|
||||
|
||||
expect(() => createTestComponent(template))
|
||||
.toThrowError(
|
||||
'NG0305: An element with the "ngSwitchDefault" attribute (matching the "NgSwitchDefault" directive) must be located inside an element with the "ngSwitch" attribute (matching "NgSwitch" directive)');
|
||||
}));
|
||||
|
||||
it('should support nested NgSwitch on ng-container with ngTemplateOutlet', () => {
|
||||
fixture = TestBed.createComponent(ComplexComponent);
|
||||
detectChangesAndExpectText('Foo');
|
||||
|
||||
Reference in New Issue
Block a user