Skip to content

Commit e967569

Browse files
committed
chore: use vitest spy instead of custom hack
1 parent 225da98 commit e967569

File tree

1 file changed

+8
-10
lines changed
  • packages/@lwc/integration-not-karma/test/component/LightningElement.addEventListener

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createElement } from 'lwc';
33
import EventHandler from 'x/eventHandler';
44
import EventHandlerOptions from 'x/eventHandlerOptions';
55
import AdditionWhileDispatch from 'x/additionWhileDispatch';
6-
import { spyConsole } from '../../../helpers/console.js';
6+
import { spyOn } from '@vitest/spy';
77

88
it('should be able to attach an event listener on the host element', () => {
99
let thisValue;
@@ -39,12 +39,11 @@ it('should warn when passing a 3rd parameter to the event handler', () => {
3939

4040
describe('event handler is not a function', () => {
4141
let consoleSpy;
42-
beforeEach(() => {
43-
consoleSpy = spyConsole();
44-
});
45-
afterEach(() => {
46-
consoleSpy.reset();
42+
beforeAll(() => {
43+
consoleSpy = spyOn(console, 'error');
4744
});
45+
afterEach(() => consoleSpy.mockReset());
46+
afterAll(() => consoleSpy.mockRestore());
4847

4948
it('should log an error if event handler is not a function', () => {
5049
const elm = createElement('x-event-handler', { is: EventHandler });
@@ -54,11 +53,10 @@ describe('event handler is not a function', () => {
5453
}).toThrowCallbackReactionError(/Expected an EventListener but received undefined/);
5554

5655
if (process.env.NODE_ENV === 'production') {
57-
expect(consoleSpy.calls.error.length).toEqual(0);
56+
expect(consoleSpy).not.toHaveBeenCalled();
5857
} else {
59-
expect(consoleSpy.calls.error.length).toEqual(1);
60-
expect(consoleSpy.calls.error[0][0].message).toContain(
61-
'Invalid second argument for this.addEventListener()'
58+
expect(consoleSpy).toHaveBeenCalledExactlyOnceWith(
59+
expect.stringContaining('Invalid second argument for this.addEventListener()')
6260
);
6361
}
6462
});

0 commit comments

Comments
 (0)