Skip to content

Commit

Permalink
test(integration-karma): simplify value evaluation throws tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-rk9 committed Mar 6, 2025
1 parent e5a2cda commit 523ac07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
10 changes: 3 additions & 7 deletions packages/@lwc/integration-karma/test/lwc-on/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('lwc:on', () => {

describe('object passed to lwc:on has property whose value evaluation throws', () => {
let element;
let testFn;
let button;

let caughtError;

Expand All @@ -438,28 +438,24 @@ describe('lwc:on', () => {
function setup(handlerType) {
element = createElement('x-value-evaluation-throws', { is: ValueEvaluationThrows });
element.handlerType = handlerType;
document.body.appendChild(element);
button = element.shadowRoot.querySelector('button');
}

it('getter that throws passed as handler', () => {
setup('getter that throws');
document.body.appendChild(element);

expect(caughtError.message).toBe('Uncaught Error: some error');

const button = element.shadowRoot.querySelector('button');
expect(button).toBeNull();
});

it('LightningElement instance is passed as argument to lwc:on', () => {
setup('LightningElement instance');
testFn = jasmine.createSpy('test function');
element.testFn = testFn;
document.body.appendChild(element);

expect(caughtError.error instanceof TypeError).toBe(true);
expect(caughtError.message).toBe('Uncaught TypeError: Illegal constructor');

const button = element.shadowRoot.querySelector('button');
expect(button).toBeNull();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { LightningElement, api } from 'lwc';

let testFn;

export default class ValueNotFunction extends LightningElement {
@api handlerType;

@api
get testFn() {
return testFn;
}
set testFn(val) {
testFn = val;
}

get eventHandlers() {
switch (this.handlerType) {
case 'getter that throws':
Expand All @@ -22,11 +12,7 @@ export default class ValueNotFunction extends LightningElement {
},
};
case 'LightningElement instance':
return new (class extends LightningElement {
render() {
testFn();
}
})();
return new (class extends LightningElement {})();
default:
return {};
}
Expand Down

0 comments on commit 523ac07

Please sign in to comment.