github.com/derat/nup@v0.0.0-20230418113745-15592ba7c620/test/web/unit/example.test.js (about) 1 // Copyright 2021 Daniel Erat. 2 // All rights reserved. 3 4 import { error, expectEq, fatal, suite, test } from './test.js'; 5 6 // This suite contains example tests, some of which intentionally fail to 7 // exercise the error-handling code in test.js. web_test.go inspects the errors 8 // from these tests. 9 suite('example', () => { 10 test('sync', () => { 11 expectEq(true, true); 12 expectEq(2, 2); 13 expectEq('foo', 'foo'); 14 expectEq([], []); 15 expectEq([4, 'foo'], [4, 'foo']); 16 expectEq({}, {}); 17 expectEq({ a: 2 }, { a: 2 }); 18 }); 19 test('syncErrors', () => { 20 expectEq(true, false); 21 expectEq(true, 1); 22 expectEq(1, 2); 23 expectEq(null, false); 24 expectEq(null, undefined); 25 expectEq('foo', 'bar', 'Value'); 26 expectEq([4, 'foo'], [4, 'bar']); 27 expectEq({ a: 2 }, { b: 2 }); 28 }); 29 test('syncFatal', () => { 30 fatal('Intentional'); 31 }); 32 test('syncException', () => { 33 throw new Error('Intentional'); 34 }); 35 36 test('async', async () => { 37 await new Promise((resolve, reject) => { 38 window.setTimeout(() => { 39 console.log('Timeout fired'); 40 resolve(); 41 }, 100); 42 }); 43 }); 44 test('asyncEarlyFatal', async () => { 45 fatal('Intentional'); 46 }); 47 test('asyncEarlyException', async () => { 48 throw new Error('Intentional'); 49 }); 50 test('asyncEarlyReject', async () => { 51 return Promise.reject('Intentional'); 52 }); 53 test('asyncTimeoutFatal', async () => { 54 await new Promise((resolve, reject) => fatal('Intentional')); 55 }); 56 test('asyncTimeoutException', async () => { 57 await new Promise((resolve, reject) => { 58 throw new Error('Intentional'); 59 }); 60 }); 61 test('asyncTimeoutReject', async () => { 62 await Promise.reject('Intentional'); 63 }); 64 65 test('done', (done) => { 66 window.setTimeout(() => { 67 console.log('Timeout fired'); 68 done(); 69 }, 100); 70 }); 71 test('doneEarlyFatal', (done) => { 72 fatal('Intentional'); 73 }); 74 test('doneEarlyException', (done) => { 75 throw new Error('Intentional'); 76 }); 77 test('doneTimeoutFatal', (done) => { 78 window.setTimeout(() => fatal('Intentional')); 79 }); 80 test('doneTimeoutException', (done) => 81 window.setTimeout(() => { 82 throw new Error('Intentional'); 83 })); 84 test('doneTimeoutReject', (done) => 85 window.setTimeout(() => { 86 Promise.reject('Intentional'); 87 })); 88 });