Skip to content

Instantly share code, notes, and snippets.

@HonzaMac
Created December 28, 2021 20:08
Show Gist options
  • Save HonzaMac/4dfa6c70761e516a4c413c182bc6a23e to your computer and use it in GitHub Desktop.
Save HonzaMac/4dfa6c70761e516a4c413c182bc6a23e to your computer and use it in GitHub Desktop.
optimized test case in part of Given
import { updateUser } from "./userService"
import { createUser } from "../tests/helpers/createUser"
describe('UserService - updateUser', () => {
it('should update department', () => {
// GIVEN
const user = createUser()
const updateData = {
department: 'IT Support',
}
// WHEN
const currentUser = updateUser(user, updateData)
// THEN
expect(currentUser).toStrictEqual({
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a',
username: 'john',
email: '[email protected]',
country: 'France',
department: 'IT Support',
divisionName: 'IT',
})
})
})
import { User } from "../../src/userService"
export const createUser = (data: Partial<User> = {}) => ({
id: 'e2f5a82a-3f2e-4b6d-b4d2-086afaa08f8a',
username: 'john',
email: '[email protected]',
country: 'France',
department: 'IT Services',
divisionName: 'IT',
...data,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment