Skip to content

Instantly share code, notes, and snippets.

@ilyachenko
Created April 25, 2016 20:06
Show Gist options
  • Save ilyachenko/70ef1954ada79fadd6808200f2b6326e to your computer and use it in GitHub Desktop.
Save ilyachenko/70ef1954ada79fadd6808200f2b6326e to your computer and use it in GitHub Desktop.
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