UNPKG

pretty-var-export

Version:

Export any value to valid and equivalent JavaScript code

43 lines (40 loc) 1.24 kB
import colors from '../../colors/colors'; import indent from '../../indent/indent'; import MapHandler from './MapHandler'; describe('MapHandler.test()', () => { it('should recognize empty maps', () => { const subject = new Map(); expect(MapHandler.test(subject)).toBe(true); }); it('should recognize non-empty maps', () => { const subject = new Map([ ['a', 1], ['b', 2], ['c', 3], ]); expect(MapHandler.test(subject)).toBe(true); }); it('should not confuse with Objects', () => { const subject = {}; expect(MapHandler.test(subject)).toBe(false); }); }); describe('MapHandler.format()', () => { const walk = v => (typeof v === 'string' ? `'${v}'` : v); it('should output simple map', () => { const map = new Map([ ['a', 1], ['b', 2], ['c', 3], ]); const result = MapHandler.format(map, 0, false, indent, walk); const formatted = indent.toSpaces(colors.unstyle(result)); expect(formatted).toBe("new Map([ ['a', 1], ['b', 2], ['c', 3] ])"); }); it('should handle empty maps', () => { const map = new Map(); const result = MapHandler.format(map, 0, false, indent, walk); const formatted = indent.toSpaces(colors.unstyle(result)); expect(formatted).toBe('new Map([ ])'); }); });