From c91cec513a67fac3941a8d49c89667658badf121 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sun, 21 Jul 2024 14:37:38 +0300 Subject: [PATCH] Fix nf jest. --- .tests/js/__mocks__/backboneMarionette.js | 2 +- .tests/js/__mocks__/backboneRadio.js | 4 +--- .tests/js/assets-js-files/ncaptcha-nf.test.js | 12 ++++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.tests/js/__mocks__/backboneMarionette.js b/.tests/js/__mocks__/backboneMarionette.js index 1dbdee81..336fa6fe 100644 --- a/.tests/js/__mocks__/backboneMarionette.js +++ b/.tests/js/__mocks__/backboneMarionette.js @@ -1,4 +1,3 @@ -// Mock Backbone // noinspection JSUnresolvedReference const Backbone = { @@ -40,4 +39,5 @@ const Marionette = { }; global.Backbone = Backbone; +global.nfRadio = Backbone.Radio; global.Marionette = Marionette; diff --git a/.tests/js/__mocks__/backboneRadio.js b/.tests/js/__mocks__/backboneRadio.js index 0448e91f..c21c24d8 100644 --- a/.tests/js/__mocks__/backboneRadio.js +++ b/.tests/js/__mocks__/backboneRadio.js @@ -1,7 +1,5 @@ // noinspection JSUnresolvedVariable -/* global Backbone */ - const submitChannel = { listenTo: jest.fn(), }; @@ -11,7 +9,7 @@ const fieldsChannel = { request: jest.fn(), }; -Backbone.Radio = { +nfRadio = { channel: jest.fn( ( channelName ) => { if ( channelName === 'submit' ) { return submitChannel; diff --git a/.tests/js/assets-js-files/ncaptcha-nf.test.js b/.tests/js/assets-js-files/ncaptcha-nf.test.js index 9c461a72..9105c697 100644 --- a/.tests/js/assets-js-files/ncaptcha-nf.test.js +++ b/.tests/js/assets-js-files/ncaptcha-nf.test.js @@ -1,6 +1,6 @@ // noinspection JSUnresolvedFunction,JSUnresolvedVariable -/* global Backbone */ +/* global nfRadio */ import $ from 'jquery'; @@ -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 ), @@ -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', () => { @@ -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'