MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 39 lines 1.1 kB view raw
1import { test, testThrows, summary } from './helpers.js'; 2 3console.log('Throw Expression Tests\n'); 4 5const must = value => value || throw new Error('missing'); 6test('throw expression in arrow skip', must('ok'), 'ok'); 7testThrows('throw expression in arrow throws', () => must('')); 8 9function fallback(value) { 10 return value ?? throw new Error('nullish'); 11} 12 13test('throw expression in nullish skip', fallback('value'), 'value'); 14testThrows('throw expression in nullish throws', () => fallback(null)); 15 16function choose(value) { 17 return value ? value : throw new Error('bad'); 18} 19 20test('throw expression in conditional skip', choose(7), 7); 21testThrows('throw expression in conditional throws', () => choose(0)); 22 23function defaultParam(value = throw new Error('default')) { 24 return value; 25} 26 27test('throw expression in parameter initializer skip', defaultParam(3), 3); 28testThrows('throw expression in parameter initializer throws', () => defaultParam()); 29 30let caught; 31try { 32 const value = false || throw 'sentinel'; 33 void value; 34} catch (e) { 35 caught = e; 36} 37test('throw expression throws raw value', caught, 'sentinel'); 38 39summary();