Skip to content

Instantly share code, notes, and snippets.

@rabelloo
Last active September 16, 2020 15:41
Show Gist options
  • Save rabelloo/50fc57bb93b5eda489141ff71599c8af to your computer and use it in GitHub Desktop.
Save rabelloo/50fc57bb93b5eda489141ff71599c8af to your computer and use it in GitHub Desktop.
function getUserName(user: { name?: string; fullName: string }) {
return user.name || user.fullName.split(' ')[0];
}
describe('getUserName', () => {
it('should return name if it exists', () => {
const name = 'name';
const result = getUserName({ name } as any);
// TypeScript would error ^^^^^^^^
// if we didn't cast it
expect(result).toBe(name);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment