Last active
September 16, 2020 15:41
-
-
Save rabelloo/50fc57bb93b5eda489141ff71599c8af to your computer and use it in GitHub Desktop.
This file contains 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
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