Skip to content

Commit

Permalink
fix: do not throw on requestContentUpdate if card is not set (#8110)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Nov 8, 2024
1 parent 9bb11bf commit b5140ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/notification/src/vaadin-notification-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export const NotificationMixin = (superClass) =>
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
*/
requestContentUpdate() {
if (!this.renderer) {
if (!this.renderer || !this._card) {
return;
}

Expand Down
21 changes: 20 additions & 1 deletion packages/notification/test/renderer.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('renderer', () => {
});

afterEach(() => {
document.body.removeChild(notification);
notification.remove();
});

it('should not throw when the renderer is set before adding to DOM', () => {
Expand All @@ -123,5 +123,24 @@ describe('renderer', () => {
document.body.appendChild(notification);
}).to.not.throw(Error);
});

it('should not throw when requesting content update after adding', () => {
notification.renderer = (root) => {
root.textContent = 'Text';
};
document.body.appendChild(notification);
expect(() => {
notification.requestContentUpdate();
}).to.not.throw(Error);
});

it('should not throw when requesting content update without adding to DOM', () => {
notification.renderer = (root) => {
root.textContent = 'Text';
};
expect(() => {
notification.requestContentUpdate();
}).to.not.throw(Error);
});
});
});

0 comments on commit b5140ab

Please sign in to comment.