Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ng-core): Fix a timing issue when combining
nasModel
and `Wrapp…
…edControlSuperclass` so that it properly receives its initial value
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
projects/integration/src/app/wrapped-control/wrapped-control.component.spec.ts
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,30 @@ | ||
import { Component } from '@angular/core'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { RootStore } from '@s-libs/app-state'; | ||
import { NasModelModule } from '@s-libs/ng-app-state'; | ||
import { ComponentContext } from '@s-libs/ng-dev'; | ||
import { WrappedControlComponent } from './wrapped-control.component'; | ||
|
||
describe('WrappedControlComponent', () => { | ||
// There is some kind of tricky timing issue when using NasModel and WrappedControlSuperclass that required moving a subscription from `ngOnInit()` to `constructor()` to fix. | ||
it('catches the first incoming value from a nasModel', () => { | ||
@Component({ | ||
template: ` | ||
<s-wrapped-control [nasModel]="store('value')"></s-wrapped-control> | ||
`, | ||
}) | ||
class WrapperComponent { | ||
store = new RootStore({ value: 'initial value' }); | ||
} | ||
|
||
const ctx = new ComponentContext(WrapperComponent, { | ||
declarations: [WrappedControlComponent], | ||
imports: [FormsModule, NasModelModule, ReactiveFormsModule], | ||
}); | ||
ctx.run(() => { | ||
const el: HTMLElement = ctx.fixture.nativeElement; | ||
const input = el.querySelector('input')!; | ||
expect(input.value).toBe('initial value'); | ||
}); | ||
}); | ||
}); |
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