-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathlifecycle-remove-disconnected.spec.js
More file actions
36 lines (31 loc) · 1.2 KB
/
lifecycle-remove-disconnected.spec.js
File metadata and controls
36 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { createElement } from 'lwc';
import Parent from 'x/parent';
import { jasmineSpyOn as spyOn } from '../../../helpers/jasmine.js';
describe('vdom removes component while it is already disconnected', () => {
let spy;
beforeEach(() => {
spy = spyOn(console, 'warn');
});
afterEach(() => {
if (
!lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE ||
process.env.NODE_ENV === 'production'
) {
expect(spy).not.toHaveBeenCalled();
} else {
// expected since the engine calls appendChild to a disconnected DOM node
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.calls.mostRecent().args[0]).toMatch(
/fired a `connectedCallback` and rendered, but was not connected to the DOM/
);
}
});
it('repro "must have been connected" error W-14037619', async () => {
const elm = createElement('x-parent', { is: Parent });
document.body.appendChild(elm);
elm.showChild = true;
document.body.removeChild(elm);
await Promise.resolve();
elm.showChild = false; // trigger removal while parent is disconnected
});
});