@@ -3,7 +3,7 @@ import { createElement } from 'lwc';
33import EventHandler from 'x/eventHandler' ;
44import EventHandlerOptions from 'x/eventHandlerOptions' ;
55import AdditionWhileDispatch from 'x/additionWhileDispatch' ;
6- import { spyConsole } from '../../../helpers/console.js ' ;
6+ import { spyOn } from '@vitest/spy ' ;
77
88it ( '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
4040describe ( '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 ( / E x p e c t e d a n E v e n t L i s t e n e r b u t r e c e i v e d u n d e f i n e d / ) ;
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