idbkeyrange_incorrect.any.js (2188B)
1 // META: title=IDBKeyRange Tests - Incorrect 2 // META: global=window,worker 3 // META: script=resources/support.js 4 5 // Spec: https://w3c.github.io/IndexedDB/#keyrange 6 7 'use strict'; 8 9 // TypeError: bound requires more than 0 arguments 10 test(() => { 11 assert_throws_js(TypeError, () => { 12 IDBKeyRange.bound(); 13 }); 14 }, 'IDBKeyRange.bound() - bound requires more than 0 arguments.'); 15 16 // Null parameters 17 test(() => { 18 assert_throws_dom('DataError', () => { 19 IDBKeyRange.bound(null, null); 20 }); 21 }, 'IDBKeyRange.bound(null, null) - null parameters are incorrect.'); 22 23 // Null parameter 24 test(() => { 25 assert_throws_dom('DataError', () => { 26 IDBKeyRange.bound(1, null); 27 }); 28 assert_throws_dom('DataError', () => { 29 IDBKeyRange.bound(null, 1); 30 }); 31 }, 'IDBKeyRange.bound(1, null / null, 1) - null parameter is incorrect.'); 32 33 // bound incorrect 34 test(() => { 35 const lowerBad = Math.floor(Math.random() * 31) + 5; 36 const upper = lowerBad - 1; 37 assert_throws_dom('DataError', () => { 38 IDBKeyRange.bound(lowerBad, upper); 39 }); 40 assert_throws_dom('DataError', () => { 41 IDBKeyRange.bound('b', 'a'); 42 }); 43 }, "IDBKeyRange.bound(lower, upper / lower > upper) - lower' is greater than 'upper'."); 44 45 test(() => { 46 assert_throws_dom('DataError', () => { 47 IDBKeyRange.bound('a', 1); 48 }); 49 assert_throws_dom('DataError', () => { 50 IDBKeyRange.bound(new Date(), 1); 51 }); 52 assert_throws_dom('DataError', () => { 53 IDBKeyRange.bound([1, 2], 1); 54 }); 55 }, "IDBKeyRange.bound(DOMString/Date/Array, 1) - A DOMString, Date and Array are greater than a float."); 56 57 // ReferenceError: the variable is not defined 58 test(() => { 59 const goodVariable = 1; 60 assert_throws_js(ReferenceError, () => { 61 IDBKeyRange.bound(noExistingVariable, 1); 62 }); 63 assert_throws_js( 64 ReferenceError, 65 () => { 66 IDBKeyRange.bound(goodVariable, noExistingVariable); 67 }); 68 }, 'IDBKeyRange.bound(noExistingVariable, 1 / goodVariable, noExistingVariable) -\ 69 noExistingVariable is not defined.'); 70 71 // Valid type key error 72 test(() => { 73 assert_throws_dom('DataError', () => { 74 IDBKeyRange.bound(true, 1); 75 }); 76 }, 'IDBKeyRange.bound(true, 1) - boolean is not a valid key type.');