Created
April 25, 2016 20:06
-
-
Save ilyachenko/70ef1954ada79fadd6808200f2b6326e 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
export default | |
function typeOf (obj) { | |
return Object.prototype.toString.call(obj).slice(8, -1); | |
} | |
// Unit tests | |
it('for Array', () => { | |
expect(typeOf([])).toBe('Array'); | |
}); | |
it('for Object', () => { | |
expect(typeOf({})).toBe('Object'); | |
}); | |
it('for Undefined', () => { | |
expect(typeOf(undefined)).toBe('Undefined'); | |
}); | |
it('for Null', () => { | |
expect(typeOf(null)).toBe('Null'); | |
}); | |
it('for RegExp', () => { | |
expect(typeOf(/asf/)).toBe('RegExp'); | |
}); | |
it('for Function', () => { | |
expect(typeOf(() => {})).toBe('Function'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment