Skip to content

Instantly share code, notes, and snippets.

@klippx
Created January 19, 2022 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klippx/1996f2a256b0cd06e6a6e8b78b590bb9 to your computer and use it in GitHub Desktop.
Save klippx/1996f2a256b0cd06e6a6e8b78b590bb9 to your computer and use it in GitHub Desktop.
it('can create a mock with specific body where order of keys does not matter', async () => {
const mock = mockClient(client)
.resource('Blog')
.method('post')
.status(204)
.with({
body: JSON.stringify({
title: 'title',
data: {
nestedItemOne: 1,
nestedItemTwo: 2,
nestingLevelTwo: {
deepNestedItemOne: 1,
deepNestedItemTwo: 2,
},
},
}),
})
.response({ ok: true })
.assertObject()
const response = await client.Blog.post({
body: JSON.stringify({
title: 'title',
data: {
nestedItemOne: 1,
nestedItemTwo: 2,
nestingLevelTwo: {
deepNestedItemOne: 1,
deepNestedItemTwo: 2,
},
},
}),
})
expect(response.data()).toEqual({ ok: true })
expect(mock.callsCount()).toEqual(1)
const response2 = await client.Blog.post({
body: JSON.stringify({
title: 'title',
data: {
nestedItemTwo: 2,
nestedItemOne: 1,
nestingLevelTwo: {
deepNestedItemTwo: 2,
deepNestedItemOne: 1,
},
},
}),
})
expect(response2.data()).toEqual({ ok: true })
expect(mock.callsCount()).toEqual(2)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment