Page MenuHomeWickedGov Phorge

useInstrument.test.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

useInstrument.test.js

const useInstrument = require( '../../../modules/ext.checkUser.tempAccounts/useInstrument.js' );
describe( 'useInstrument', () => {
it( 'should record events', () => {
// Mock EventLogging infrastructure
const submitInteraction = jest.fn();
const newInstrument = jest.fn( () => ( {
submitInteraction
} ) );
mw.eventLog = { newInstrument };
const logEvent = useInstrument();
logEvent( 'session_end' );
logEvent( 'session_start', { sessionLength: 3600 } );
expect( newInstrument ).toHaveBeenCalledTimes( 1 );
expect( submitInteraction ).toHaveBeenCalledTimes( 2 );
expect( submitInteraction ).toHaveBeenNthCalledWith( 1, 'session_end', {} );
expect( submitInteraction ).toHaveBeenNthCalledWith( 2, 'session_start', {
// eslint-disable-next-line camelcase
action_context: JSON.stringify( { session_length: 3600 } )
} );
} );
it( 'should not try to record events if EventLogging is unavailable', () => {
// Simulate EventLogging being unavailable
mw.eventLog = undefined;
const logEvent = useInstrument();
expect( () => {
logEvent( 'session_end' );
} ).not.toThrow();
} );
} );

File Metadata

Mime Type
text/plain
Expires
Aug 16 2026, 13:18 (11 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d9/db/97ebeee62121c5ad9cb2a0301312
Default Alt Text
useInstrument.test.js (1 KB)

Event Timeline