Last active
April 18, 2020 22:35
capitalizeName - Version 2 (more robust)
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
import { capitalizeName } from "./capitalizeName"; | |
describe('capitalizeName', () => { | |
it('should capitalize the name in the object', () => { | |
const testObj = { name: 'Qarun', age: 25 }; | |
expect(capitalizeName(testObj)).toEqual({name: 'QARUN', age: 25}); | |
}); | |
it('should not fail if the name key is missing', () => { | |
const missingName = { age: 25 }; | |
expect(capitalizeName(missingName)).toEqual({name: '', age: 25}); | |
}); | |
it('should throw an error if the name key is not a string', () => { | |
const improperName = { name: 10, age: 25 }; | |
expect(() => { capitalizeName(improperName) }).toThrowError("'name' key in object must be a string."); | |
}); | |
it('should throw an error if the object is null or undefined', () => { | |
expect(() => { capitalizeName(undefined) }).toThrowError('object is null or undefined'); | |
expect(() => { capitalizeName(null) }).toThrowError('object is null or undefined'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment