@@ -8,7 +8,6 @@ describe('submit', () => {
8
8
const baseUrl = 'https://api.example.com' ;
9
9
const path = '/foo' ;
10
10
const url = new URL ( path , baseUrl ) . toString ( ) ;
11
- const responseBody = 'Success!' ;
12
11
13
12
beforeEach ( ( ) => {
14
13
if ( ! nock . isActive ( ) ) {
@@ -38,13 +37,12 @@ describe('submit', () => {
38
37
) } `;
39
38
40
39
it ( 'should make HTTP GET request when method is missing' , async ( ) => {
41
- const scope = nock ( baseUrl ) . get ( path ) . reply ( 200 , responseBody ) ;
40
+ const scope = nock ( baseUrl ) . get ( path ) . reply ( 204 ) ;
42
41
43
42
const response = await submit ( action ) ;
44
43
45
44
expect ( response . url ) . toBe ( url ) ;
46
- expect ( response . status ) . toBe ( 200 ) ;
47
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
45
+ expect ( response . status ) . toBe ( 204 ) ;
48
46
expect ( scope . isDone ( ) ) . toBe ( true ) ;
49
47
} ) ;
50
48
@@ -54,13 +52,12 @@ describe('submit', () => {
54
52
action . href = url ;
55
53
action . method = method ;
56
54
action . fields = [ nameField , emailField ] ;
57
- const scope = nock ( baseUrl ) . intercept ( `${ path } ?${ urlEncodedForm } ` , method ) . reply ( 200 , responseBody ) ;
55
+ const scope = nock ( baseUrl ) . intercept ( `${ path } ?${ urlEncodedForm } ` , method ) . reply ( 204 ) ;
58
56
59
57
const response = await submit ( action ) ;
60
58
61
59
expect ( response . url ) . toBe ( `${ url } ?${ urlEncodedForm } ` ) ;
62
- expect ( response . status ) . toBe ( 200 ) ;
63
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
60
+ expect ( response . status ) . toBe ( 204 ) ;
64
61
expect ( scope . isDone ( ) ) . toBe ( true ) ;
65
62
} ) ;
66
63
@@ -70,13 +67,12 @@ describe('submit', () => {
70
67
action . href = url ;
71
68
action . method = method ;
72
69
action . fields = [ nameField , emailField ] ;
73
- const scope = nock ( baseUrl ) . intercept ( path , method , urlEncodedForm ) . reply ( 200 , responseBody ) ;
70
+ const scope = nock ( baseUrl ) . intercept ( path , method , urlEncodedForm ) . reply ( 204 ) ;
74
71
75
72
const response = await submit ( action ) ;
76
73
77
74
expect ( response . url ) . toBe ( url ) ;
78
- expect ( response . status ) . toBe ( 200 ) ;
79
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
75
+ expect ( response . status ) . toBe ( 204 ) ;
80
76
expect ( scope . isDone ( ) ) . toBe ( true ) ;
81
77
} ) ;
82
78
@@ -96,40 +92,37 @@ describe('submit', () => {
96
92
const serializer : Serializer = ( ) => Promise . resolve ( { content, contentType } ) ;
97
93
const scope = nock ( baseUrl , { reqheaders : { 'Content-Type' : contentType } } )
98
94
. post ( path , content )
99
- . reply ( 200 , responseBody ) ;
95
+ . reply ( 204 ) ;
100
96
101
97
const response = await submit ( action , { serializer } ) ;
102
98
103
99
expect ( response . url ) . toBe ( url ) ;
104
- expect ( response . status ) . toBe ( 200 ) ;
105
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
100
+ expect ( response . status ) . toBe ( 204 ) ;
106
101
expect ( scope . isDone ( ) ) . toBe ( true ) ;
107
102
} ) ;
108
103
109
104
it ( 'should accept and send request options' , async ( ) => {
110
105
const apiKey = 'foo-bar-baz' ;
111
106
const headers = { 'Api-Key' : apiKey } ;
112
- const scope = nock ( baseUrl , { reqheaders : headers } ) . get ( path ) . reply ( 200 , responseBody ) ;
107
+ const scope = nock ( baseUrl , { reqheaders : headers } ) . get ( path ) . reply ( 204 ) ;
113
108
114
109
const response = await submit ( action , { requestInit : { headers } } ) ;
115
110
116
111
expect ( response . url ) . toBe ( url ) ;
117
- expect ( response . status ) . toBe ( 200 ) ;
118
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
112
+ expect ( response . status ) . toBe ( 204 ) ;
119
113
expect ( scope . isDone ( ) ) . toBe ( true ) ;
120
114
} ) ;
121
115
122
116
it ( 'should resolve relative URL' , async ( ) => {
123
117
const action = new Action ( ) ;
124
118
action . name = 'do-something' ;
125
119
action . href = path ;
126
- const scope = nock ( baseUrl ) . get ( path ) . reply ( 200 , responseBody ) ;
120
+ const scope = nock ( baseUrl ) . get ( path ) . reply ( 204 ) ;
127
121
128
122
const response = await submit ( action , { baseUrl } ) ;
129
123
130
124
expect ( response . url ) . toBe ( url ) ;
131
- expect ( response . status ) . toBe ( 200 ) ;
132
- await expect ( response . text ( ) ) . resolves . toBe ( responseBody ) ;
125
+ expect ( response . status ) . toBe ( 204 ) ;
133
126
expect ( scope . isDone ( ) ) . toBe ( true ) ;
134
127
} ) ;
135
128
} ) ;
0 commit comments