@@ -48,6 +48,7 @@ describe('Model methods', () => {
4848 const post = await Post . first ( )
4949 expect ( post ) . toEqual ( postsResponse [ 0 ] )
5050 expect ( post ) . toBeInstanceOf ( Post )
51+ expect ( post . user ) . toBeInstanceOf ( User )
5152 } )
5253
5354 test ( '$first() returns first object in array as instance of such Model' , async ( ) => {
@@ -58,6 +59,7 @@ describe('Model methods', () => {
5859
5960 expect ( post ) . toEqual ( postsEmbedResponse . data [ 0 ] )
6061 expect ( post ) . toBeInstanceOf ( Post )
62+ expect ( post . user ) . toBeInstanceOf ( User )
6163 } )
6264
6365 test ( 'first() method returns a empty object when no items have found' , async ( ) => {
@@ -73,6 +75,7 @@ describe('Model methods', () => {
7375 const post = await Post . find ( 1 )
7476 expect ( post ) . toEqual ( postResponse )
7577 expect ( post ) . toBeInstanceOf ( Post )
78+ expect ( post . user ) . toBeInstanceOf ( User )
7679 } )
7780
7881 test ( '$find() handles request with "data" wrapper' , async ( ) => {
@@ -82,6 +85,7 @@ describe('Model methods', () => {
8285
8386 expect ( post ) . toEqual ( postEmbedResponse . data )
8487 expect ( post ) . toBeInstanceOf ( Post )
88+ expect ( post . user ) . toBeInstanceOf ( User )
8589 } )
8690
8791 test ( '$find() handles request without "data" wrapper' , async ( ) => {
@@ -91,6 +95,7 @@ describe('Model methods', () => {
9195
9296 expect ( post ) . toEqual ( postResponse )
9397 expect ( post ) . toBeInstanceOf ( Post )
98+ expect ( post . user ) . toBeInstanceOf ( User )
9499
95100 } )
96101
@@ -101,6 +106,7 @@ describe('Model methods', () => {
101106
102107 posts . forEach ( post => {
103108 expect ( post ) . toBeInstanceOf ( Post )
109+ expect ( post . user ) . toBeInstanceOf ( User )
104110 } ) ;
105111 } )
106112
@@ -109,11 +115,18 @@ describe('Model methods', () => {
109115 expect ( config . method ) . toEqual ( 'get' )
110116 expect ( config . url ) . toEqual ( 'http://localhost/posts/1/comments' )
111117
112- return [ 200 , { } ]
118+ return [ 200 , commentsResponse ]
113119 } )
114120
115121 const post = new Post ( { id : 1 } )
116- await post . comments ( ) . get ( )
122+ const comments = await post . comments ( ) . get ( )
123+
124+ comments . forEach ( comment => {
125+ expect ( comment ) . toBeInstanceOf ( Comment )
126+ comment . replies . forEach ( reply => {
127+ expect ( reply ) . toBeInstanceOf ( Comment )
128+ } )
129+ } )
117130 } )
118131
119132 test ( 'get() hits right resource (nested object, custom PK)' , async ( ) => {
@@ -127,10 +140,17 @@ describe('Model methods', () => {
127140 expect ( config . method ) . toEqual ( 'get' )
128141 expect ( config . url ) . toEqual ( `http://localhost/posts/${ post . someId } /comments` )
129142
130- return [ 200 , { } ]
143+ return [ 200 , commentsResponse ]
131144 } )
132145
133- post . comments ( ) . get ( )
146+ const comments = await post . comments ( ) . get ( )
147+
148+ comments . forEach ( comment => {
149+ expect ( comment ) . toBeInstanceOf ( Comment )
150+ comment . replies . forEach ( reply => {
151+ expect ( reply ) . toBeInstanceOf ( Comment )
152+ } )
153+ } )
134154 } )
135155
136156 test ( '$get() fetch style request with "data" wrapper' , async ( ) => {
@@ -162,26 +182,46 @@ describe('Model methods', () => {
162182 expect ( config . method ) . toEqual ( 'get' )
163183 expect ( config . url ) . toEqual ( `http://localhost/posts/${ post . someId } /comments` )
164184
165- return [ 200 , { } ]
185+ return [ 200 , commentsResponse ]
166186 } )
167187
168- post . comments ( ) . $get ( )
188+ const comments = await post . comments ( ) . $get ( )
189+
190+ comments . forEach ( comment => {
191+ expect ( comment ) . toBeInstanceOf ( Comment )
192+ comment . replies . forEach ( reply => {
193+ expect ( reply ) . toBeInstanceOf ( Comment )
194+ } )
195+ } )
169196 } )
170197
171198 test ( 'save() method makes a POST request when ID of object does not exists' , async ( ) => {
172199 let post
200+ const _postResponse = {
201+ id : 1 ,
202+ title : 'Cool!' ,
203+ text : 'Lorem Ipsum Dolor' ,
204+ user : {
205+ firstname : 'John' ,
206+ lastname : 'Doe' ,
207+ age : 25
208+ }
209+ }
173210
174211 axiosMock . onAny ( ) . reply ( ( config ) => {
175212 expect ( config . method ) . toEqual ( 'post' )
176213 expect ( config . data ) . toEqual ( JSON . stringify ( post ) )
177214 expect ( config . url ) . toEqual ( 'http://localhost/posts' )
178215
179- return [ 200 , { } ]
216+ return [ 200 , _postResponse ]
180217 } )
181218
182219 post = new Post ( { title : 'Cool!' } )
183- await post . save ( )
220+ post = await post . save ( )
184221
222+ expect ( post ) . toEqual ( _postResponse )
223+ expect ( post ) . toBeInstanceOf ( Post )
224+ expect ( post . user ) . toBeInstanceOf ( User )
185225 } )
186226
187227 test ( 'save() method makes a PUT request when ID of object exists' , async ( ) => {
0 commit comments