Skip to content

Rerender with template throws "Cannot redefine property" #222

Closed
@rothsandro

Description

@rothsandro

Steps to reproduce

  1. Create a new Angular 12 project
  2. Install testing library
  3. Add a new test that renders a template with componentProperties
  4. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions