Closed
Description
Steps to reproduce
- Create a new Angular 12 project
- Install testing library
- Add a new test that renders a template with componentProperties
- Call "rerender" with an updated property value
const { rerender, getByText } = await render(`<div>Hello {{ name}}</div>`, {
componentProperties: {
name: 'Sarah',
},
});
getByText('Hello Sarah');
rerender({ name: 'Mark' }); // Throws the error
getByText('Hello Mark');});
Expected behavior
The template should be updated with the new value
Actual behavior
The following error is thrown:
TypeError: Cannot redefine property: name
Cause
The function setComponentProperties
which is called during initial render and during rerender uses Object.defineProperty
. As configurable
is false by default (see MDN) this cannot be called twice and throws the error above on rerender.
The function should set configurable: true
.
Demo
https://github.com/rothsandro/ng-tlib-template-rerender/blob/main/src/app/rerender-template.spec.ts
Metadata
Metadata
Assignees
Labels
No labels