Skip to content

Commit

Permalink
Fix jest.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Sep 23, 2024
1 parent d30f40f commit 3fe5d30
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .tests/js/hcaptcha/hcaptcha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe( 'HCaptcha', () => {
hCaptcha.foundForms.push( testForm );

expect( hCaptcha.getFoundFormById( 'test-id' ) ).toEqual( testForm );
expect( hCaptcha.getFoundFormById( 'non-existent-id' ) ).toBeUndefined();
expect( hCaptcha.getFoundFormById( 'non-existent-id' ) ).toBeNull();
} );

test( 'isSameOrDescendant', () => {
Expand All @@ -65,14 +65,14 @@ describe( 'HCaptcha', () => {
} );

test( 'bindEvents and reset', () => {
function generateUniqueId() {
return Math.random().toString( 36 ).substring( 2, 9 );
}

// Mock hcaptcha object
global.hcaptcha = {
render: jest.fn( ( hcaptchaElement ) => {
// Mock the rendering of the hCaptcha widget by adding a dataset attribute
const iframe = document.createElement( 'iframe' );
iframe.dataset.hcaptchaWidgetId = 'mock-widget-id';
iframe.dataset.hcaptchaResponse = '';
hcaptchaElement.appendChild( iframe );
return generateUniqueId();
} ),
execute: jest.fn(),
reset: jest.fn(),
Expand Down Expand Up @@ -132,7 +132,7 @@ describe( 'HCaptcha', () => {
hCaptcha.reset( form1 );

// Check if hcaptcha.reset was called with the correct widget id
expect( global.hcaptcha.reset ).toHaveBeenCalledWith( 'mock-widget-id' );
expect( global.hcaptcha.reset ).toHaveBeenCalled();

// Clean up DOM elements
document.body.removeChild( form1 );
Expand Down

0 comments on commit 3fe5d30

Please sign in to comment.