Skip to content

Commit bfe7cd1

Browse files
committed
test: Added tests for wrappedBy and nowrap
1 parent 1e34b61 commit bfe7cd1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/model.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,34 @@ describe('Model methods', () => {
334334
})
335335
})
336336

337+
test('nowrap().get() returns the full response with the "data" wrapper even though the wrap method is set', async () => {
338+
// Set the wrap method to 'data'
339+
Post.prototype['wrap'] = () => {
340+
return 'data'
341+
}
342+
343+
axiosMock.onGet('http://localhost/posts').reply(200, postsEmbedResponse)
344+
345+
const posts = await Post.nowrap().get()
346+
347+
expect(posts).toEqual(postsEmbedResponse)
348+
expect(posts.data[0]).toEqual(postsEmbedResponse.data[0])
349+
})
350+
351+
test('wrappedBy().get() returns the full response with the "data" wrapper even though the wrap method is set to `test`', async () => {
352+
// Set the wrap method to 'data'
353+
Post.prototype['wrap'] = () => {
354+
return 'test'
355+
}
356+
357+
axiosMock.onGet('http://localhost/posts').reply(200, postsEmbedResponse)
358+
359+
const posts = await Post.wrappedBy('data').get()
360+
361+
expect(posts).toEqual(postsEmbedResponse.data)
362+
expect(posts[0]).toEqual(postsEmbedResponse.data[0])
363+
})
364+
337365
test('save() method makes a POST request when ID of object does not exists', async () => {
338366
let post
339367
const _postResponse = {

0 commit comments

Comments
 (0)