@@ -115,6 +115,38 @@ describe('Model methods', () => {
115
115
} )
116
116
} )
117
117
118
+ test ( "find() method returns a object as instance of such Model with empty relationships" , async ( ) => {
119
+ const _postResponse = postResponse ;
120
+ _postResponse . user = null ;
121
+ _postResponse . relationships . tags = [ ] ;
122
+
123
+ axiosMock . onGet ( "http://localhost/posts/1" ) . reply ( 200 , _postResponse ) ;
124
+
125
+ const post = await Post . find ( 1 ) ;
126
+
127
+ expect ( post ) . toEqual ( postResponse ) ;
128
+ expect ( post ) . toBeInstanceOf ( Post ) ;
129
+ expect ( post . user ) . toStrictEqual ( null ) ;
130
+ expect ( post . relationships . tags ) . toStrictEqual ( [ ] ) ;
131
+ } ) ;
132
+
133
+ test ( "find() method returns a object as instance of such Model with some empty relationships" , async ( ) => {
134
+ const _postResponse = postResponse ;
135
+ _postResponse . user = null ;
136
+
137
+ axiosMock . onGet ( "http://localhost/posts/1" ) . reply ( 200 , _postResponse ) ;
138
+
139
+ const post = await Post . find ( 1 ) ;
140
+
141
+ expect ( post ) . toEqual ( postResponse ) ;
142
+ expect ( post ) . toBeInstanceOf ( Post ) ;
143
+ expect ( post . user ) . toStrictEqual ( null ) ;
144
+
145
+ post . relationships . tags . forEach ( ( tag ) => {
146
+ expect ( tag ) . toBeInstanceOf ( Tag ) ;
147
+ } ) ;
148
+ } ) ;
149
+
118
150
test ( 'get() method returns a array of objects as instance of suchModel' , async ( ) => {
119
151
axiosMock . onGet ( 'http://localhost/posts' ) . reply ( 200 , postsResponse )
120
152
0 commit comments