Skip to content

Commit

Permalink
fix: detect nodes added by replaceChild
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Mar 27, 2021
1 parent 178a7b6 commit 45844af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/to-be-announced.ts
Expand Up @@ -174,6 +174,7 @@ export function register(
interceptMethod(Element.prototype, 'removeAttribute', onRemoveAttribute),
interceptMethod(Node.prototype, 'appendChild', onNodeMount),
interceptMethod(Node.prototype, 'insertBefore', onNodeMount),
interceptMethod(Node.prototype, 'replaceChild', onNodeMount),
interceptSetter(Node.prototype, 'textContent', onTextContentChange),
interceptSetter(Node.prototype, 'nodeValue', onNodeValueChange)
);
Expand Down
12 changes: 12 additions & 0 deletions test/to-be-announced.dom.test.ts
Expand Up @@ -150,5 +150,17 @@ ASSERTIVE_CASES.forEach(({ name, value }) => {

expect('Hello world').toBeAnnounced();
});

test('should announce when content is added with `replaceChild`', async () => {
const parent = document.createElement('div');
const oldChild = document.createElement('div');
parent.appendChild(oldChild);
appendToRoot(parent);

element.textContent = 'Hello world';
parent.replaceChild(element, oldChild);

expect('Hello world').toBeAnnounced();
});
});
});

0 comments on commit 45844af

Please sign in to comment.