-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: component setter is overwritten when component properties are set (
- Loading branch information
1 parent
4b6e491
commit 0143973
Showing
3 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/example-app/app/examples/16-input-getter-setter.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,25 @@ | ||
import { render, screen } from '@testing-library/angular'; | ||
import { InputGetterSetter } from './16-input-getter-setter'; | ||
|
||
test('should run logic in the input setter and getter', async () => { | ||
await render(InputGetterSetter, { componentProperties: { value: 'Angular' } }); | ||
const valueControl = screen.getByTestId('value'); | ||
const getterValueControl = screen.getByTestId('value-getter'); | ||
|
||
expect(valueControl.textContent).toBe('I am value from setter Angular'); | ||
expect(getterValueControl.textContent).toBe('I am value from getter Angular'); | ||
}); | ||
|
||
test('should run logic in the input setter and getter while re-rendering', async () => { | ||
const component = await render(InputGetterSetter, { componentProperties: { value: 'Angular' } }); | ||
const valueControl = screen.getByTestId('value'); | ||
const getterValueControl = screen.getByTestId('value-getter'); | ||
|
||
expect(valueControl.textContent).toBe('I am value from setter Angular'); | ||
expect(getterValueControl.textContent).toBe('I am value from getter Angular'); | ||
|
||
await component.rerender({ value: 'React' }); | ||
|
||
expect(valueControl.textContent).toBe('I am value from setter React'); | ||
expect(getterValueControl.textContent).toBe('I am value from getter React'); | ||
}); |
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,22 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-fixture', | ||
template: ` | ||
<span data-testid="value">{{ derivedValue }}</span> | ||
<span data-testid="value-getter">{{ value }}</span> | ||
`, | ||
}) | ||
export class InputGetterSetter { | ||
@Input() set value(value: string) { | ||
this.originalValue = value; | ||
this.derivedValue = 'I am value from setter ' + value; | ||
} | ||
|
||
get value() { | ||
return 'I am value from getter ' + this.originalValue; | ||
} | ||
|
||
private originalValue: string; | ||
derivedValue: string; | ||
} |
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