Skip to content

Commit

Permalink
Fix nf jest.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 21, 2024
1 parent 5f687da commit c91cec5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .tests/js/__mocks__/backboneMarionette.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Mock Backbone
// noinspection JSUnresolvedReference

const Backbone = {
Expand Down Expand Up @@ -40,4 +39,5 @@ const Marionette = {
};

global.Backbone = Backbone;
global.nfRadio = Backbone.Radio;
global.Marionette = Marionette;
4 changes: 1 addition & 3 deletions .tests/js/__mocks__/backboneRadio.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// noinspection JSUnresolvedVariable

/* global Backbone */

const submitChannel = {
listenTo: jest.fn(),
};
Expand All @@ -11,7 +9,7 @@ const fieldsChannel = {
request: jest.fn(),
};

Backbone.Radio = {
nfRadio = {
channel: jest.fn( ( channelName ) => {
if ( channelName === 'submit' ) {
return submitChannel;
Expand Down
12 changes: 6 additions & 6 deletions .tests/js/assets-js-files/ncaptcha-nf.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// noinspection JSUnresolvedFunction,JSUnresolvedVariable

/* global Backbone */
/* global nfRadio */

import $ from 'jquery';

Expand Down Expand Up @@ -28,13 +28,13 @@ describe( 'Ninja Forms hCaptcha', () => {
controller = window.hCaptchaFieldController;

// Reset the request mock function
Backbone.Radio.channel( 'fields' ).request.mockReset();
nfRadio.channel( 'fields' ).request.mockReset();
} );

test( 'initialize registers listeners', () => {
controller.initialize();
expect( Backbone.Radio.channel ).toHaveBeenCalledWith( 'submit' );
expect( Backbone.Radio.channel ).toHaveBeenCalledWith( 'fields' );
expect( nfRadio.channel ).toHaveBeenCalledWith( 'submit' );
expect( nfRadio.channel ).toHaveBeenCalledWith( 'fields' );

expect( controller.listenTo ).toHaveBeenCalledWith(
expect.any( Object ),
Expand All @@ -57,7 +57,7 @@ describe( 'Ninja Forms hCaptcha', () => {

controller.updateHcaptcha( model );

expect( Backbone.Radio.channel( 'fields' ).request ).not.toHaveBeenCalled();
expect( nfRadio.channel( 'fields' ).request ).not.toHaveBeenCalled();
} );

test( 'updateHcaptcha removes error if value is set', () => {
Expand All @@ -68,7 +68,7 @@ describe( 'Ninja Forms hCaptcha', () => {

controller.updateHcaptcha( model );

expect( Backbone.Radio.channel( 'fields' ).request ).toHaveBeenCalledWith(
expect( nfRadio.channel( 'fields' ).request ).toHaveBeenCalledWith(
'remove:error',
expect.anything(),
'required-error'
Expand Down

0 comments on commit c91cec5

Please sign in to comment.