1
- import registry from "../../core/registry" ;
2
- import pattern from "./ajax" ;
3
1
import $ from "jquery" ;
2
+ import events from "../../core/events" ;
3
+ import pattern from "./ajax" ;
4
+ import registry from "../../core/registry" ;
4
5
import { jest } from "@jest/globals" ;
5
6
6
7
var $lab ;
@@ -47,13 +48,13 @@ describe("pat-ajax", function () {
47
48
} ) ;
48
49
49
50
it ( "triggers ajax request on submit" , function ( ) {
50
- $form . submit ( ) ;
51
+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
51
52
expect ( spy_ajax ) . toHaveBeenCalled ( ) ;
52
53
} ) ;
53
54
54
55
it ( "honors method='post'" , function ( ) {
55
56
$form . attr ( "method" , "post" ) ;
56
- $form . submit ( ) ;
57
+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
57
58
var ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
58
59
expect ( ajaxargs . url ) . toEqual ( "action.html" ) ;
59
60
expect ( ajaxargs . method ) . toEqual ( "POST" ) ;
@@ -73,7 +74,7 @@ describe("pat-ajax", function () {
73
74
} ) ;
74
75
75
76
it ( "does not include submit buttons if not clicked" , function ( ) {
76
- $form . submit ( ) ;
77
+ $form [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
77
78
var ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
78
79
expect ( ajaxargs . url ) . toEqual ( "action.html" ) ;
79
80
expect ( ajaxargs . data ) . toEqual ( "input1=value1" ) ;
@@ -99,7 +100,7 @@ describe("pat-ajax", function () {
99
100
document . body . innerHTML = `<form class="pat-ajax" action="somewhere.html"/>` ;
100
101
registry . scan ( document . body ) ;
101
102
jest . spyOn ( $ , "ajax" ) ;
102
- $ ( ".pat-ajax" ) . submit ( ) ;
103
+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
103
104
const ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
104
105
expect ( ajaxargs . url ) . toEqual ( "somewhere.html" ) ;
105
106
} ) ;
@@ -127,7 +128,7 @@ describe("pat-ajax", function () {
127
128
` ;
128
129
registry . scan ( document . body ) ;
129
130
jest . spyOn ( $ , "ajax" ) ;
130
- $ ( ".pat-ajax" ) . submit ( ) ;
131
+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
131
132
const ajaxargs = $ . ajax . mock . calls [ $ . ajax . mock . calls . length - 1 ] [ 0 ] ;
132
133
expect ( ajaxargs . url ) . toEqual ( "else.html" ) ;
133
134
} ) ;
@@ -214,7 +215,7 @@ describe("pat-ajax", function () {
214
215
data-pat-ajax="browser-cache: cache"
215
216
/>` ;
216
217
registry . scan ( document . body ) ;
217
- $ ( ".pat-ajax" ) . submit ( ) ; // need jquery submit here
218
+ $ ( ".pat-ajax" ) [ 0 ] . dispatchEvent ( events . submit_event ( ) ) ;
218
219
const ajaxargs = spy_ajax . mock . calls [ spy_ajax . mock . calls . length - 1 ] [ 0 ] ;
219
220
expect ( ajaxargs . cache ) . toBe ( false ) ;
220
221
spy_ajax . mockRestore ( ) ;
0 commit comments