Skip to content

Commit d1fd88a

Browse files
committed
test(wtr): remove duplicate code
I had previously moved the code to a new file, but not removed the old code or updated references. Oops.
1 parent 8fb80db commit d1fd88a

File tree

6 files changed

+5
-49
lines changed

6 files changed

+5
-49
lines changed

packages/@lwc/integration-not-karma/helpers/matchers/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function windowErrorListener(callback) {
3636
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
3737
// only be caught with window.addEventListener('error')
3838
// - Note native lifecycle callbacks are all thrown asynchronously.
39-
function customElementCallbackReactionErrorListener(callback) {
39+
export function customElementCallbackReactionErrorListener(callback) {
4040
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
4141
? directErrorListener(callback)
4242
: windowErrorListener(callback);

packages/@lwc/integration-not-karma/helpers/utils.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,6 @@
22
* An as yet uncategorized mishmash of helpers, relics of Karma
33
*/
44

5-
// Listen for errors thrown directly by the callback
6-
function directErrorListener(callback) {
7-
try {
8-
callback();
9-
} catch (error) {
10-
return error;
11-
}
12-
}
13-
14-
// Listen for errors using window.addEventListener('error')
15-
function windowErrorListener(callback) {
16-
let error;
17-
function onError(event) {
18-
event.preventDefault(); // don't log the error
19-
error = event.error;
20-
}
21-
22-
// Prevent jasmine from handling the global error. There doesn't seem to be another
23-
// way to disable this behavior: https://github.com/jasmine/jasmine/pull/1860
24-
const originalOnError = window.onerror;
25-
window.onerror = null;
26-
window.addEventListener('error', onError);
27-
28-
try {
29-
callback();
30-
} finally {
31-
window.onerror = originalOnError;
32-
window.removeEventListener('error', onError);
33-
}
34-
return error;
35-
}
36-
37-
// For errors we expect to be thrown in the connectedCallback() phase
38-
// of a custom element, there are two possibilities:
39-
// 1) We're using non-native lifecycle callbacks, so the error is thrown synchronously
40-
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
41-
// only be caught with window.addEventListener('error')
42-
// - Note native lifecycle callbacks are all thrown asynchronously.
43-
export function customElementCallbackReactionErrorListener(callback) {
44-
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
45-
? directErrorListener(callback)
46-
: windowErrorListener(callback);
47-
}
48-
495
export function extractDataIds(root) {
506
const nodes = {};
517

packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/api/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ENABLE_ELEMENT_INTERNALS_AND_FACE,
88
IS_SYNTHETIC_SHADOW_LOADED,
99
} from '../../../../helpers/constants.js';
10-
import { customElementCallbackReactionErrorListener } from '../../../../helpers/utils.js';
10+
import { customElementCallbackReactionErrorListener } from '../../../../helpers/matchers/errors.js';
1111

1212
const testConnectedCallbackError = (elm, msg) => {
1313
const error = customElementCallbackReactionErrorListener(() => {

packages/@lwc/integration-not-karma/test/component/LightningElement.connectedCallback/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createElement } from 'lwc';
33
import Test from 'x/test';
44
import ConnectedCallbackThrow from 'x/connectedCallbackThrow';
55
import XSlottedParent from 'x/slottedParent';
6-
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
6+
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';
77

88
function testConnectSlot(name, fn) {
99
it(`should invoke the connectedCallback the root element is added in the DOM via ${name}`, () => {

packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import DisconnectedCallbackThrow from 'x/disconnectedCallbackThrow';
66
import DualTemplate from 'x/dualTemplate';
77
import ExplicitRender from 'x/explicitRender';
88
import { jasmine } from '../../../helpers/jasmine.js';
9-
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
9+
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';
1010

1111
function testDisconnectSlot(name, fn) {
1212
it(`should invoke the disconnectedCallback when root element is removed from the DOM via ${name}`, () => {

packages/@lwc/integration-not-karma/test/component/LightningElement.render/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createElement, registerTemplate } from 'lwc';
33
import DynamicTemplate, { template1, template2 } from 'x/dynamicTemplate';
44
import RenderThrow from 'x/renderThrow';
55
import RenderInvalid from 'x/renderInvalid';
6-
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
6+
import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js';
77

88
function testInvalidTemplate(type, template) {
99
it(`throws an error if returns ${type}`, () => {

0 commit comments

Comments
 (0)