Last active
November 10, 2023 10:30
-
-
Save mbjelac/b111b38303ec17d40102dd1bb12bf984 to your computer and use it in GitHub Desktop.
API test (spying)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 👇 separate from other types of Jest tests | |
/** | |
* @group integration/api | |
*/ | |
// imports ... | |
it('admin creates user', async () => { | |
await loginAs(Role.ADMIN); // login helper (setup 1 dummy user for each role) | |
const user = { email: 'aNewEmail', roles: [Role.ADMIN] }; | |
await createUser(user); // call the API function | |
expect(await getLastMethodCall()) // gets the last method call from the backend's API test spy endpoint | |
.toEqual<MethodCall>( | |
{ | |
method: 'create-user', // the call was made to the method labelled 'create-user' | |
arguments: [user] // just one argument here, but can be more depending on the method signature | |
} | |
); | |
}); |
Originally published as part of this article.
We spy the backend method because it was labelled on the backend.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
@group
test separation powered by jest-runner-groups.