File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ export default class Model extends StaticModel {
138
138
}
139
139
140
140
isValidId ( id ) {
141
- return id !== undefined && id !== 0 && id !== ''
141
+ return id !== undefined && id !== 0 && id !== '' && id !== null
142
142
}
143
143
144
144
endpoint ( ) {
Original file line number Diff line number Diff line change @@ -320,6 +320,22 @@ describe('Model methods', () => {
320
320
comment . save ( )
321
321
} )
322
322
323
+ test ( 'save() method makes a POST request when ID of object is null' , async ( ) => {
324
+ let post
325
+
326
+ axiosMock . onAny ( ) . reply ( ( config ) => {
327
+ expect ( config . method ) . toEqual ( 'post' )
328
+ expect ( config . data ) . toEqual ( JSON . stringify ( post ) )
329
+ expect ( config . url ) . toEqual ( 'http://localhost/posts' )
330
+
331
+ return [ 200 , { } ]
332
+ } )
333
+
334
+ post = new Post ( { id : null , title : 'Cool!' } )
335
+ await post . save ( )
336
+
337
+ } )
338
+
323
339
test ( 'a request from delete() method hits the right resource' , async ( ) => {
324
340
325
341
axiosMock . onAny ( ) . reply ( ( config ) => {
You can’t perform that action at this time.
0 commit comments