@@ -35,7 +35,7 @@ describe('Unit | Mixin | ajax request', function() {
35
35
36
36
describe ( 'options method' , function ( ) {
37
37
it ( 'sets raw data' , function ( ) {
38
- const service = new AjaxRequest ( ) ;
38
+ const service = AjaxRequest . create ( ) ;
39
39
const url = '/test' ;
40
40
const type = 'GET' ;
41
41
const ajaxOptions = service . options ( url , {
@@ -56,7 +56,7 @@ describe('Unit | Mixin | ajax request', function() {
56
56
} ) ;
57
57
58
58
it ( 'sets options correctly' , function ( ) {
59
- const service = new AjaxRequest ( ) ;
59
+ const service = AjaxRequest . create ( ) ;
60
60
const url = '/test' ;
61
61
const type = 'POST' ;
62
62
const data = JSON . stringify ( { key : 'value' } ) ;
@@ -77,7 +77,7 @@ describe('Unit | Mixin | ajax request', function() {
77
77
} ) ;
78
78
79
79
it ( 'does not modify the options object argument' , function ( ) {
80
- const service = new AjaxRequest ( ) ;
80
+ const service = AjaxRequest . create ( ) ;
81
81
const url = 'test' ;
82
82
const data = JSON . stringify ( { key : 'value' } ) ;
83
83
const baseOptions = { type : 'POST' , data } ;
@@ -86,7 +86,7 @@ describe('Unit | Mixin | ajax request', function() {
86
86
} ) ;
87
87
88
88
it ( 'does not override contentType when defined' , function ( ) {
89
- const service = new AjaxRequest ( ) ;
89
+ const service = AjaxRequest . create ( ) ;
90
90
const url = '/test' ;
91
91
const type = 'POST' ;
92
92
const data = JSON . stringify ( { key : 'value' } ) ;
@@ -107,7 +107,7 @@ describe('Unit | Mixin | ajax request', function() {
107
107
} ) ;
108
108
109
109
it ( 'can handle empty data' , function ( ) {
110
- const service = new AjaxRequest ( ) ;
110
+ const service = AjaxRequest . create ( ) ;
111
111
const url = '/test' ;
112
112
const type = 'POST' ;
113
113
const ajaxOptions = service . options ( url , { type } ) ;
@@ -293,7 +293,7 @@ describe('Unit | Mixin | ajax request', function() {
293
293
} ) ;
294
294
295
295
it ( 'can be set on a per-request basis' , function ( ) {
296
- const service = new AjaxRequest ( ) ;
296
+ const service = AjaxRequest . create ( ) ;
297
297
298
298
expect ( service . options ( 'users/me' , { namespace : '/api' } ) . url ) . to . equal (
299
299
'/api/users/me'
@@ -317,7 +317,7 @@ describe('Unit | Mixin | ajax request', function() {
317
317
318
318
describe ( 'type' , function ( ) {
319
319
it ( 'defaults to GET' , function ( ) {
320
- const service = new AjaxRequest ( ) ;
320
+ const service = AjaxRequest . create ( ) ;
321
321
const url = 'test' ;
322
322
const ajaxOptions = service . options ( url ) ;
323
323
@@ -341,7 +341,7 @@ describe('Unit | Mixin | ajax request', function() {
341
341
} ) ;
342
342
343
343
it ( 'request() promise label is correct' , function ( ) {
344
- const service = new AjaxRequest ( ) ;
344
+ const service = AjaxRequest . create ( ) ;
345
345
const url = '/posts' ;
346
346
const data = {
347
347
type : 'POST' ,
@@ -366,7 +366,7 @@ describe('Unit | Mixin | ajax request', function() {
366
366
} ) ;
367
367
368
368
it ( 'post() promise label is correct' , function ( ) {
369
- const service = new AjaxRequest ( ) ;
369
+ const service = AjaxRequest . create ( ) ;
370
370
const url = '/posts' ;
371
371
const title = 'Title' ;
372
372
const description = 'Some description.' ;
@@ -392,7 +392,7 @@ describe('Unit | Mixin | ajax request', function() {
392
392
} ) ;
393
393
394
394
it ( 'put() promise label is correct' , function ( ) {
395
- const service = new AjaxRequest ( ) ;
395
+ const service = AjaxRequest . create ( ) ;
396
396
const url = '/posts/1' ;
397
397
const title = 'Title' ;
398
398
const description = 'Some description.' ;
@@ -420,7 +420,7 @@ describe('Unit | Mixin | ajax request', function() {
420
420
} ) ;
421
421
422
422
it ( 'patch() promise label is correct' , function ( ) {
423
- const service = new AjaxRequest ( ) ;
423
+ const service = AjaxRequest . create ( ) ;
424
424
const url = '/posts/1' ;
425
425
const description = 'Some description.' ;
426
426
const options = {
@@ -446,7 +446,7 @@ describe('Unit | Mixin | ajax request', function() {
446
446
} ) ;
447
447
448
448
it ( 'del() promise label is correct' , function ( ) {
449
- const service = new AjaxRequest ( ) ;
449
+ const service = AjaxRequest . create ( ) ;
450
450
const url = '/posts/1' ;
451
451
const serverResponse = [
452
452
200 ,
@@ -465,7 +465,7 @@ describe('Unit | Mixin | ajax request', function() {
465
465
} ) ;
466
466
467
467
it ( 'delete() promise label is correct' , function ( ) {
468
- const service = new AjaxRequest ( ) ;
468
+ const service = AjaxRequest . create ( ) ;
469
469
const url = '/posts/1' ;
470
470
const serverResponse = [
471
471
200 ,
@@ -498,7 +498,7 @@ describe('Unit | Mixin | ajax request', function() {
498
498
} ) ;
499
499
this . server . post ( url , ( ) => serverResponse ) ;
500
500
501
- const service = new AjaxRequest ( ) ;
501
+ const service = AjaxRequest . create ( ) ;
502
502
const handleResponse = td . function ( 'handle response' ) ;
503
503
const expectedArguments = [
504
504
anything ( ) ,
@@ -528,7 +528,7 @@ describe('Unit | Mixin | ajax request', function() {
528
528
} ) ;
529
529
530
530
it ( 'overrides host property in request config' , function ( ) {
531
- const service = new AjaxRequest ( ) ;
531
+ const service = AjaxRequest . create ( ) ;
532
532
const host = 'https://discuss.emberjs.com' ;
533
533
const url = 'http://myurl.com/users/me' ;
534
534
const ajaxOptions = service . options ( url , { host } ) ;
@@ -700,7 +700,7 @@ describe('Unit | Mixin | ajax request', function() {
700
700
] ;
701
701
this . server . get ( '/posts' , ( ) => response ) ;
702
702
703
- const service = new AjaxRequest ( ) ;
703
+ const service = AjaxRequest . create ( ) ;
704
704
return service
705
705
. request ( '/posts' )
706
706
. then ( function ( ) {
@@ -722,7 +722,7 @@ describe('Unit | Mixin | ajax request', function() {
722
722
] ;
723
723
this . server . get ( '/posts' , ( ) => response ) ;
724
724
725
- const service = new AjaxRequest ( ) ;
725
+ const service = AjaxRequest . create ( ) ;
726
726
return service
727
727
. request ( '/posts' )
728
728
. then ( function ( ) {
@@ -737,7 +737,7 @@ describe('Unit | Mixin | ajax request', function() {
737
737
} ) ;
738
738
739
739
it ( 'it throws an error when the user tries to use `.get` to make a request' , function ( ) {
740
- const service = new AjaxRequest ( ) ;
740
+ const service = AjaxRequest . create ( ) ;
741
741
service . set ( 'someProperty' , 'foo' ) ;
742
742
743
743
expect ( service . get ( 'someProperty' ) ) . to . equal ( 'foo' ) ;
@@ -944,14 +944,14 @@ describe('Unit | Mixin | ajax request', function() {
944
944
} ) ;
945
945
946
946
it ( 'correctly handles a host provided on the request options' , function ( ) {
947
- const req = new AjaxRequest ( ) ;
947
+ const req = AjaxRequest . create ( ) ;
948
948
expect ( req . _buildURL ( '/baz' , { host : 'http://foo.com' } ) ) . to . equal (
949
949
'http://foo.com/baz'
950
950
) ;
951
951
} ) ;
952
952
953
953
it ( 'correctly handles no namespace or host' , function ( ) {
954
- const req = new AjaxRequest ( ) ;
954
+ const req = AjaxRequest . create ( ) ;
955
955
expect ( req . _buildURL ( '/baz' ) ) . to . equal ( '/baz' ) ;
956
956
expect ( req . _buildURL ( 'baz' ) ) . to . equal ( 'baz' ) ;
957
957
} ) ;
@@ -1039,7 +1039,7 @@ describe('Unit | Mixin | ajax request', function() {
1039
1039
} ) ;
1040
1040
1041
1041
it ( "it doesn't reassign payloads which evaluate falsey" , function ( ) {
1042
- const service = new AjaxRequest ( ) ;
1042
+ const service = AjaxRequest . create ( ) ;
1043
1043
1044
1044
const payloadWithFalseyString = service . handleResponse ( 200 , { } , '' ) ;
1045
1045
expect ( payloadWithFalseyString ) . to . be . empty ;
@@ -1063,7 +1063,7 @@ describe('Unit | Mixin | ajax request', function() {
1063
1063
return [ 200 , { } , `${ req . queryParams . callback } ({ "foo": "bar" })` ] ;
1064
1064
} ) ;
1065
1065
1066
- const ajax = new AjaxRequest ( ) ;
1066
+ const ajax = AjaxRequest . create ( ) ;
1067
1067
return ajax
1068
1068
. request ( '/jsonp' , {
1069
1069
dataType : 'jsonp'
@@ -1077,7 +1077,7 @@ describe('Unit | Mixin | ajax request', function() {
1077
1077
describe ( 'error handlers' , function ( ) {
1078
1078
it ( 'handles a TimeoutError correctly' , function ( ) {
1079
1079
this . server . get ( '/posts' , jsonFactory ( 200 ) , 2 ) ;
1080
- const service = new AjaxRequest ( ) ;
1080
+ const service = AjaxRequest . create ( ) ;
1081
1081
return service
1082
1082
. request ( '/posts' , { timeout : 1 } )
1083
1083
. then ( function ( ) {
@@ -1098,7 +1098,7 @@ describe('Unit | Mixin | ajax request', function() {
1098
1098
errors : [ { id : 1 , message : 'error description' } ]
1099
1099
} )
1100
1100
) ;
1101
- const service = new AjaxRequest ( ) ;
1101
+ const service = AjaxRequest . create ( ) ;
1102
1102
return service
1103
1103
. request ( '/posts' )
1104
1104
. then ( function ( ) {
@@ -1143,7 +1143,7 @@ describe('Unit | Mixin | ajax request', function() {
1143
1143
} ) ;
1144
1144
1145
1145
it ( 'can wait on an AJAX GET request' , function ( ) {
1146
- const service = new AjaxRequest ( ) ;
1146
+ const service = AjaxRequest . create ( ) ;
1147
1147
service . request ( '/test' ) ;
1148
1148
1149
1149
return wait ( ) . then ( ( ) => {
@@ -1152,7 +1152,7 @@ describe('Unit | Mixin | ajax request', function() {
1152
1152
} ) ;
1153
1153
1154
1154
it ( 'can wait on an AJAX POST request' , function ( ) {
1155
- const service = new AjaxRequest ( ) ;
1155
+ const service = AjaxRequest . create ( ) ;
1156
1156
service . post ( '/test' ) ;
1157
1157
1158
1158
return wait ( ) . then ( ( ) => {
@@ -1167,7 +1167,7 @@ describe('Unit | Mixin | ajax request', function() {
1167
1167
return [ 200 , { } , `${ req . queryParams . callback } ({ "foo": "bar" })` ] ;
1168
1168
} ) ;
1169
1169
1170
- const ajax = new AjaxRequest ( ) ;
1170
+ const ajax = AjaxRequest . create ( ) ;
1171
1171
ajax
1172
1172
. request ( '/jsonp' , { dataType : 'jsonp' } )
1173
1173
. then ( val => ( response = val ) ) ;
@@ -1183,7 +1183,7 @@ describe('Unit | Mixin | ajax request', function() {
1183
1183
} ) ;
1184
1184
1185
1185
it ( 'attaches the XHR for the request to the promise object' , function ( ) {
1186
- const ajax = new AjaxRequest ( ) ;
1186
+ const ajax = AjaxRequest . create ( ) ;
1187
1187
const promise = ajax . request ( '/foo' ) ;
1188
1188
1189
1189
expect ( promise . xhr ) . to . be . ok ;
@@ -1192,7 +1192,7 @@ describe('Unit | Mixin | ajax request', function() {
1192
1192
// Note: the `.catch` handler _must_ be set up before the request is aborted
1193
1193
// Without that, the rejection will be treated as un-handled
1194
1194
it ( 'can be used to abort the request' , function ( ) {
1195
- const ajax = new AjaxRequest ( ) ;
1195
+ const ajax = AjaxRequest . create ( ) ;
1196
1196
const promise = ajax
1197
1197
. request ( '/foo' )
1198
1198
. then ( ( ) => {
@@ -1210,28 +1210,28 @@ describe('Unit | Mixin | ajax request', function() {
1210
1210
1211
1211
describe ( 'passing the XHR to child promises' , function ( ) {
1212
1212
it ( 'keeps the XHR property through child promises (then)' , function ( ) {
1213
- const ajax = new AjaxRequest ( ) ;
1213
+ const ajax = AjaxRequest . create ( ) ;
1214
1214
const promise = ajax . request ( '/foo' ) . then ( response => response ) ;
1215
1215
1216
1216
expect ( promise . xhr ) . to . be . ok ;
1217
1217
} ) ;
1218
1218
1219
1219
it ( 'keeps the XHR property through child promises (catch)' , function ( ) {
1220
- const ajax = new AjaxRequest ( ) ;
1220
+ const ajax = AjaxRequest . create ( ) ;
1221
1221
const promise = ajax . request ( '/foo' ) . catch ( response => response ) ;
1222
1222
1223
1223
expect ( promise . xhr ) . to . be . ok ;
1224
1224
} ) ;
1225
1225
1226
1226
it ( 'keeps the XHR property through child promises (finally)' , function ( ) {
1227
- const ajax = new AjaxRequest ( ) ;
1227
+ const ajax = AjaxRequest . create ( ) ;
1228
1228
const promise = ajax . request ( '/foo' ) . finally ( response => response ) ;
1229
1229
1230
1230
expect ( promise . xhr ) . to . be . ok ;
1231
1231
} ) ;
1232
1232
1233
1233
it ( 'keeps the XHR property through child promises (multiple)' , function ( ) {
1234
- const ajax = new AjaxRequest ( ) ;
1234
+ const ajax = AjaxRequest . create ( ) ;
1235
1235
const promise = ajax
1236
1236
. request ( '/foo' )
1237
1237
. then ( response => response )
0 commit comments