FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function myInstanceOf(obj, Constructor) { throw new Error('Not implemented'); }
import myInstanceOf from './file'; describe('myInstanceOf', () => { test('returns true when Constructor.prototype is in the prototype chain', () => { function Person() {} const p = new Person(); expect(myInstanceOf(p, Person)).toBe(true); }); test('works for arrays', () => { expect(myInstanceOf([], Array)).toBe(true); expect(myInstanceOf({}, Array)).toBe(false); }); test('works for functions', () => { function f() {} expect(myInstanceOf(f, Function)).toBe(true); }); test('returns false for primitives and null/undefined', () => { expect(myInstanceOf(1, Number)).toBe(false); expect(myInstanceOf('a', String)).toBe(false); expect(myInstanceOf(true, Boolean)).toBe(false); expect(myInstanceOf(null, Object)).toBe(false); expect(myInstanceOf(undefined, Object)).toBe(false); }); test('handles Object.create(null) correctly (null prototype chain)', () => { const o = Object.create(null); expect(myInstanceOf(o, Object)).toBe(false); }); test('throws if Constructor is not a function', () => { try { myInstanceOf({}, 123); expect(true).toBe(false); } catch (e) { expect(!!e).toBe(true); expect(e.name).toBe('TypeError'); } }); });
▶ Run tests
Results
Console
Run tests to see results.