FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function shallowClone(value) { throw new Error('Not implemented'); }
import shallowClone from './file'; describe('shallowClone', () => { test('clones arrays shallowly', () => { const arr = [1, { x: 2 }]; const copy = shallowClone(arr); expect(copy).toEqual(arr); expect(copy === arr).toBe(false); expect(copy[1]).toBe(arr[1]); }); test('clones objects shallowly', () => { const obj = { a: 1, b: { c: 2 } }; const copy = shallowClone(obj); expect(copy).toEqual(obj); expect(copy === obj).toBe(false); expect(copy.b).toBe(obj.b); }); test('throws for non-object/array', () => { expect(() => shallowClone(42)).toThrow(TypeError); expect(() => shallowClone('x')).toThrow(TypeError); }); });
▶ Run tests
Results
Console
Run tests to see results.