1- import registry from "../../core/registry" ;
2- import pattern from "./ajax" ;
31import $ from "jquery" ;
2+ import events from "../../core/events" ;
3+ import pattern from "./ajax" ;
4+ import registry from "../../core/registry" ;
45import { jest } from "@jest/globals" ;
56
67var $lab ;
@@ -47,13 +48,13 @@ describe("pat-ajax", function () {
4748 } ) ;
4849
4950 it ( "triggers ajax request on submit" , function ( ) {
50- $form . submit ( ) ;
51+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
5152 expect ( spy_ajax ) . toHaveBeenCalled ( ) ;
5253 } ) ;
5354
5455 it ( "honors method='post'" , function ( ) {
5556 $form . attr ( "method" , "post" ) ;
56- $form . submit ( ) ;
57+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
5758 var ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
5859 expect ( ajaxargs . url ) . toEqual ( "action.html" ) ;
5960 expect ( ajaxargs . method ) . toEqual ( "POST" ) ;
@@ -73,7 +74,7 @@ describe("pat-ajax", function () {
7374 } ) ;
7475
7576 it ( "does not include submit buttons if not clicked" , function ( ) {
76- $form . submit ( ) ;
77+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
7778 var ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
7879 expect ( ajaxargs . url ) . toEqual ( "action.html" ) ;
7980 expect ( ajaxargs . data ) . toEqual ( "input1=value1" ) ;
@@ -99,7 +100,7 @@ describe("pat-ajax", function () {
99100 document . body . innerHTML = `<form class="pat-ajax" action="somewhere.html"/>` ;
100101 registry . scan ( document . body ) ;
101102 jest . spyOn ( $ , "ajax" ) ;
102- $ ( ".pat-ajax" ) . submit ( ) ;
103+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
103104 const ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
104105 expect ( ajaxargs . url ) . toEqual ( "somewhere.html" ) ;
105106 } ) ;
@@ -127,7 +128,7 @@ describe("pat-ajax", function () {
127128 ` ;
128129 registry . scan ( document . body ) ;
129130 jest . spyOn ( $ , "ajax" ) ;
130- $ ( ".pat-ajax" ) . submit ( ) ;
131+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
131132 const ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
132133 expect ( ajaxargs . url ) . toEqual ( "else.html" ) ;
133134 } ) ;
@@ -214,7 +215,7 @@ describe("pat-ajax", function () {
214215 data-pat-ajax="browser-cache: cache"
215216 />` ;
216217 registry . scan ( document . body ) ;
217- $ ( ".pat-ajax" ) . submit ( ) ; // need jquery submit here
218+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
218219 const ajaxargs = spy_ajax . mock . calls [ spy_ajax . mock . calls . length - 1 ] [ 0 ] ;
219220 expect ( ajaxargs . cache ) . toBe ( false ) ;
220221 spy_ajax . mockRestore ( ) ;
0 commit comments