-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(datepicker): make datepicker view child static (#5374)
Fix a bug related to an undefined reference error when writing a value to the datepicker before it's ngAfterContentInit hook. Closes #5373
- Loading branch information
1 parent
91bda67
commit fe7e489
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { Component, ViewChild, OnInit } from '@angular/core'; | ||
|
||
import { DatepickerModule, DatePickerComponent } from '.'; | ||
|
||
@Component({ | ||
selector: 'test-cmp', | ||
template: `<datepicker></datepicker>` | ||
}) | ||
class TestComponent implements OnInit { | ||
@ViewChild(DatePickerComponent, { static: true }) datepicker: DatePickerComponent; | ||
|
||
ngOnInit(): void { | ||
this.datepicker.writeValue(new Date()); | ||
} | ||
} | ||
|
||
type TestFixture = ComponentFixture<TestComponent>; | ||
|
||
describe('datepicker:', () => { | ||
let fixture: TestFixture; | ||
|
||
beforeEach( | ||
async(() => TestBed.configureTestingModule({ | ||
declarations: [TestComponent], | ||
imports: [ | ||
DatepickerModule.forRoot(), | ||
BrowserAnimationsModule | ||
] | ||
}).compileComponents()) | ||
); | ||
|
||
it('should not throw undefined reference error when initializing value before content init hook', | ||
() => { | ||
// tslint:disable-next-line: no-floating-promises | ||
expect(() => { | ||
fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
}).not.toThrowError(/^.*undefined.*$/gm); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters