Best JavaScript code snippet using wpt
idbobjectstore-add.test.ts
Source:idbobjectstore-add.test.ts
1import test from "ava";2import { BridgeIDBRequest } from "..";3import { IDBDatabase } from "../idbtypes";4import { createdb } from "./wptsupport";5// IDBObjectStore.add() - add with an inline key6test("WPT idbobjectstore_add.htm", async (t) => {7 await new Promise<void>((resolve, reject) => {8 var db: IDBDatabase | undefined;9 const record = { key: 1, property: "data" };10 var open_rq = createdb(t);11 open_rq.onupgradeneeded = function (e: any) {12 db = e.target.result;13 var objStore = db!.createObjectStore("store", { keyPath: "key" });14 objStore.add(record);15 };16 open_rq.onsuccess = function (e: any) {17 var rq = db!.transaction("store").objectStore("store").get(record.key);18 rq.onsuccess = function (e: any) {19 t.deepEqual(e.target.result.property, record.property);20 t.deepEqual(e.target.result.key, record.key);21 resolve();22 };23 };24 });25 t.pass();26});27// IDBObjectStore.add() - add with an out-of-line key28test("WPT idbobjectstore_add2.htm", async (t) => {29 await new Promise<void>((resolve, reject) => {30 var db: any;31 const key = 1;32 const record = { property: "data" };33 var open_rq = createdb(t);34 open_rq.onupgradeneeded = function (e: any) {35 db = e.target.result;36 var objStore = db.createObjectStore("store");37 objStore.add(record, key);38 };39 open_rq.onsuccess = function (e: any) {40 var rq = db.transaction("store").objectStore("store").get(key);41 rq.onsuccess = function (e: any) {42 t.deepEqual(e.target.result.property, record.property);43 resolve();44 };45 };46 });47 t.pass();48});49// IDBObjectStore.add() - record with same key already exists50test("WPT idbobjectstore_add3.htm", async (t) => {51 await new Promise<void>((resolve, reject) => {52 var db: any;53 const record = { key: 1, property: "data" };54 var open_rq = createdb(t);55 open_rq.onupgradeneeded = function (e: any) {56 db = e.target.result;57 var objStore = db.createObjectStore("store", { keyPath: "key" });58 objStore.add(record);59 var rq = objStore.add(record);60 rq.onsuccess = () => t.fail("success on adding duplicate record");61 rq.onerror = function (e: any) {62 t.deepEqual(e.target.error.name, "ConstraintError");63 t.deepEqual(rq.error.name, "ConstraintError");64 t.deepEqual(e.type, "error");65 e.preventDefault();66 e.stopPropagation();67 };68 };69 // Defer done, giving rq.onsuccess a chance to run70 open_rq.onsuccess = function (e: any) {71 resolve();72 };73 });74 t.pass();75});76// IDBObjectStore.add() - add where an index has unique:true specified77test("WPT idbobjectstore_add4.htm", async (t) => {78 await new Promise<void>((resolve, reject) => {79 let db: any;80 let record = { key: 1, property: "data" };81 var open_rq = createdb(t);82 open_rq.onupgradeneeded = function (e: any) {83 db = e.target.result;84 var objStore = db.createObjectStore("store", { autoIncrement: true });85 objStore.createIndex("i1", "property", { unique: true });86 objStore.add(record);87 var rq = objStore.add(record);88 rq.onsuccess = () => t.fail("success on adding duplicate indexed record");89 rq.onerror = function (e: any) {90 t.deepEqual(rq.error.name, "ConstraintError");91 t.deepEqual(e.target.error.name, "ConstraintError");92 t.deepEqual(e.type, "error");93 e.preventDefault();94 e.stopPropagation();95 };96 };97 // Defer done, giving a spurious rq.onsuccess a chance to run98 open_rq.onsuccess = function (e: any) {99 resolve();100 };101 });102 t.pass();103});104// IDBObjectStore.add() - object store's key path is an object attribute105test("WPT idbobjectstore_add5.htm", async (t) => {106 await new Promise<void>((resolve, reject) => {107 var db: any;108 const record = { test: { obj: { key: 1 } }, property: "data" };109 var open_rq = createdb(t);110 open_rq.onupgradeneeded = function (e: any) {111 db = e.target.result;112 var objStore = db.createObjectStore("store", { keyPath: "test.obj.key" });113 objStore.add(record);114 };115 open_rq.onsuccess = function (e: any) {116 var rq = db117 .transaction("store")118 .objectStore("store")119 .get(record.test.obj.key);120 rq.onsuccess = function (e: any) {121 t.deepEqual(e.target.result.property, record.property);122 resolve();123 };124 };125 });126 t.pass();127});128// IDBObjectStore.add() - autoIncrement and inline keys129test("WPT idbobjectstore_add6.htm", async (t) => {130 await new Promise<void>((resolve, reject) => {131 var db: any;132 const record = { property: "data" };133 const expected_keys = [1, 2, 3, 4];134 var open_rq = createdb(t);135 open_rq.onupgradeneeded = function (e: any) {136 db = e.target.result;137 var objStore = db.createObjectStore("store", {138 keyPath: "key",139 autoIncrement: true,140 });141 objStore.add(record);142 objStore.add(record);143 objStore.add(record);144 objStore.add(record);145 };146 open_rq.onsuccess = function (e: any) {147 var actual_keys: any[] = [],148 rq = db.transaction("store").objectStore("store").openCursor();149 rq.onsuccess = function (e: any) {150 var cursor = e.target.result;151 if (cursor) {152 actual_keys.push(cursor.value.key);153 cursor.continue();154 } else {155 t.deepEqual(actual_keys, expected_keys);156 resolve();157 }158 };159 };160 });161 t.pass();162});163// IDBObjectStore.add() - autoIncrement and out-of-line keys164test("WPT idbobjectstore_add7.htm", async (t) => {165 await new Promise<void>((resolve, reject) => {166 var db: any;167 const record = { property: "data" };168 const expected_keys = [1, 2, 3, 4];169 var open_rq = createdb(t);170 open_rq.onupgradeneeded = function (e: any) {171 db = e.target.result;172 var objStore = db.createObjectStore("store", { autoIncrement: true });173 objStore.add(record);174 objStore.add(record);175 objStore.add(record);176 objStore.add(record);177 };178 open_rq.onsuccess = function (e: any) {179 var actual_keys: any[] = [],180 rq = db.transaction("store").objectStore("store").openCursor();181 rq.onsuccess = function (e: any) {182 var cursor = e.target.result;183 if (cursor) {184 actual_keys.push(cursor.key);185 cursor.continue();186 } else {187 t.deepEqual(actual_keys, expected_keys);188 resolve();189 }190 };191 };192 });193 t.pass();194});195// IDBObjectStore.add() - object store has autoIncrement:true and the key path196// is an object attribute197test("WPT idbobjectstore_add8.htm", async (t) => {198 await new Promise<void>((resolve, reject) => {199 var db: any;200 const record = { property: "data" };201 const expected_keys = [1, 2, 3, 4];202 var open_rq = createdb(t);203 open_rq.onupgradeneeded = function (e: any) {204 db = e.target.result;205 var objStore = db.createObjectStore("store", {206 keyPath: "test.obj.key",207 autoIncrement: true,208 });209 objStore.add(record);210 objStore.add(record);211 objStore.add(record);212 objStore.add(record);213 };214 open_rq.onsuccess = function (e: any) {215 var actual_keys: any[] = [],216 rq = db.transaction("store").objectStore("store").openCursor();217 rq.onsuccess = function (e: any) {218 var cursor = e.target.result;219 if (cursor) {220 actual_keys.push(cursor.value.test.obj.key);221 cursor.continue();222 } else {223 t.deepEqual(actual_keys, expected_keys);224 resolve();225 }226 };227 };228 });229 t.pass();230});231// IDBObjectStore.add() - Attempt to add a record that does not meet the232// constraints of an object store's inline key requirements233test("WPT idbobjectstore_add9.htm", async (t) => {234 await new Promise<void>((resolve, reject) => {235 const record = { key: 1, property: "data" };236 var open_rq = createdb(t);237 open_rq.onupgradeneeded = function (e: any) {238 var rq,239 db = e.target.result,240 objStore = db.createObjectStore("store", { keyPath: "key" });241 t.throws(242 function () {243 rq = objStore.add(record, 1);244 },245 { name: "DataError" },246 );247 t.deepEqual(rq, undefined);248 resolve();249 };250 });251 t.pass();252});253// IDBObjectStore.add() - Attempt to call 'add' without an key parameter when the254// object store uses out-of-line keys.255test("WPT idbobjectstore_add10.htm", async (t) => {256 await new Promise<void>((resolve, reject) => {257 var db: any;258 const record = { property: "data" };259 var open_rq = createdb(t);260 open_rq.onupgradeneeded = function (e: any) {261 db = e.target.result;262 var rq,263 objStore = db.createObjectStore("store");264 t.throws(265 function () {266 rq = objStore.add(record);267 },268 { name: "DataError" },269 );270 t.deepEqual(rq, undefined);271 resolve();272 };273 });274 t.pass();275});276// IDBObjectStore.add() - Attempt to add a record where the record's key277// does not meet the constraints of a valid key278test("WPT idbobjectstore_add11.htm", async (t) => {279 await new Promise<void>((resolve, reject) => {280 var db: any;281 const record = { key: { value: 1 }, property: "data" };282 var open_rq = createdb(t);283 open_rq.onupgradeneeded = function (e: any) {284 db = e.target.result;285 var rq,286 objStore = db.createObjectStore("store", { keyPath: "key" });287 t.throws(288 function () {289 rq = objStore.add(record);290 },291 { name: "DataError" },292 );293 t.deepEqual(rq, undefined);294 resolve();295 };296 });297 t.pass();298});299// IDBObjectStore.add() - Attempt to add a record where the300// record's in-line key is not defined301test("WPT idbobjectstore_add12.htm", async (t) => {302 await new Promise<void>((resolve, reject) => {303 var db: any;304 const record = { property: "data" };305 var open_rq = createdb(t);306 open_rq.onupgradeneeded = function (e: any) {307 db = e.target.result;308 var rq,309 objStore = db.createObjectStore("store", { keyPath: "key" });310 t.throws(311 function () {312 rq = objStore.add(record);313 },314 { name: "DataError" },315 );316 t.deepEqual(rq, undefined);317 resolve();318 };319 });320 t.pass();321});322// IDBObjectStore.add() - Attempt to add a record where the out of line323// key provided does not meet the constraints of a valid key324test("WPT idbobjectstore_add13.htm", async (t) => {325 await new Promise<void>((resolve, reject) => {326 var db: any;327 const record = { property: "data" };328 var open_rq = createdb(t);329 open_rq.onupgradeneeded = function (e: any) {330 db = e.target.result;331 var rq,332 objStore = db.createObjectStore("store");333 t.throws(334 function () {335 rq = objStore.add(record, { value: 1 });336 },337 { name: "DataError" },338 );339 t.deepEqual(rq, undefined);340 resolve();341 };342 });343 t.pass();344});345// IDBObjectStore.add() - Add a record where a value346// being indexed does not meet the constraints of a valid key347test("WPT idbobjectstore_add14.htm", async (t) => {348 await new Promise<void>((resolve, reject) => {349 var db: any;350 const record = { key: 1, indexedProperty: { property: "data" } };351 var open_rq = createdb(t);352 open_rq.onupgradeneeded = function (e: any) {353 db = e.target.result;354 var rq,355 objStore = db.createObjectStore("store", { keyPath: "key" });356 objStore.createIndex("index", "indexedProperty");357 rq = objStore.add(record);358 t.assert(rq instanceof BridgeIDBRequest);359 rq.onsuccess = function () {360 resolve();361 };362 };363 });364 t.pass();365});366// IDBObjectStore.add() - If the transaction this IDBObjectStore belongs367// to has its mode set to readonly, throw ReadOnlyError368test("WPT idbobjectstore_add15.htm", async (t) => {369 await new Promise<void>((resolve, reject) => {370 var db: any;371 var open_rq = createdb(t);372 open_rq.onupgradeneeded = function (event: any) {373 db = event.target.result;374 db.createObjectStore("store", { keyPath: "pKey" });375 };376 open_rq.onsuccess = function (event: any) {377 var txn = db.transaction("store");378 var ostore = txn.objectStore("store");379 t.throws(380 function () {381 ostore.add({ pKey: "primaryKey_0" });382 },383 { name: "ReadOnlyError" },384 );385 resolve();386 };387 });388 t.pass();389});390// IDBObjectStore.add() - If the object store has been391// deleted, the implementation must throw a DOMException of type InvalidStateError392test("WPT idbobjectstore_add16.htm", async (t) => {393 await new Promise<void>((resolve, reject) => {394 var db: any;395 let ostore: any;396 var open_rq = createdb(t);397 open_rq.onupgradeneeded = function (event: any) {398 db = event.target.result;399 ostore = db.createObjectStore("store", { keyPath: "pKey" });400 db.deleteObjectStore("store");401 t.throws(402 function () {403 ostore.add({ pKey: "primaryKey_0" });404 },405 { name: "InvalidStateError" },406 );407 resolve();408 };409 });410 t.pass();...
idbobjectstore-put.test.ts
Source:idbobjectstore-put.test.ts
1import test from "ava";2import { BridgeIDBKeyRange, BridgeIDBRequest } from "..";3import { IDBDatabase } from "../idbtypes";4import { createdb } from "./wptsupport";5// IDBObjectStore.put() - put with an inline key6test.cb("WPT idbobjectstore_put.htm", (t) => {7 var db: any,8 record = { key: 1, property: "data" };9 var open_rq = createdb(t);10 open_rq.onupgradeneeded = function (e: any) {11 db = e.target.result;12 var objStore = db.createObjectStore("store", { keyPath: "key" });13 objStore.put(record);14 };15 open_rq.onsuccess = function (e: any) {16 var rq = db.transaction("store").objectStore("store").get(record.key);17 rq.onsuccess = function (e: any) {18 t.deepEqual(e.target.result.property, record.property);19 t.deepEqual(e.target.result.key, record.key);20 t.end();21 };22 };23});24// IDBObjectStore.put() - put with an out-of-line key25test.cb("WPT idbobjectstore_put2.htm", (t) => {26 var db: any,27 key = 1,28 record = { property: "data" };29 var open_rq = createdb(t);30 open_rq.onupgradeneeded = function (e: any) {31 db = e.target.result;32 var objStore = db.createObjectStore("store");33 objStore.put(record, key);34 };35 open_rq.onsuccess = function (e: any) {36 var rq = db.transaction("store").objectStore("store").get(key);37 rq.onsuccess = function (e: any) {38 t.deepEqual(e.target.result.property, record.property);39 t.end();40 };41 };42});43// IDBObjectStore.put() - put with an out-of-line key44test.cb("WPT idbobjectstore_put3.htm", (t) => {45 var db: any,46 success_event: any,47 record = { key: 1, property: "data" },48 record_put = { key: 1, property: "changed", more: ["stuff", 2] };49 var open_rq = createdb(t);50 open_rq.onupgradeneeded = function (e: any) {51 db = e.target.result;52 var objStore = db.createObjectStore("store", { keyPath: "key" });53 objStore.put(record);54 var rq = objStore.put(record_put);55 rq.onerror = () => t.fail("error on put");56 rq.onsuccess = function (e: any) {57 success_event = true;58 };59 };60 open_rq.onsuccess = function (e: any) {61 t.true(success_event);62 var rq = db.transaction("store").objectStore("store").get(1);63 rq.onsuccess = function (e: any) {64 var rec = e.target.result;65 t.deepEqual(rec.key, record_put.key);66 t.deepEqual(rec.property, record_put.property);67 t.deepEqual(rec.more, record_put.more);68 t.end();69 };70 };71});72// IDBObjectStore.put() - put where an index has unique:true specified73test.cb("WPT idbobjectstore_put4.htm", (t) => {74 var db: any,75 record = { key: 1, property: "data" };76 var open_rq = createdb(t);77 open_rq.onupgradeneeded = function (e: any) {78 db = e.target.result;79 var objStore = db.createObjectStore("store", { autoIncrement: true });80 objStore.createIndex("i1", "property", { unique: true });81 objStore.put(record);82 var rq = objStore.put(record);83 rq.onsuccess = () => t.fail("success on putting duplicate indexed record");84 rq.onerror = function (e: any) {85 t.deepEqual(rq.error.name, "ConstraintError");86 t.deepEqual(e.target.error.name, "ConstraintError");87 t.deepEqual(e.type, "error");88 e.preventDefault();89 e.stopPropagation();90 };91 };92 // Defer done, giving a spurious rq.onsuccess a chance to run93 open_rq.onsuccess = function (e: any) {94 t.end();95 };96});97// IDBObjectStore.put() - object store's key path is an object attribute98test.cb("WPT idbobjectstore_put5.htm", (t) => {99 var db: any,100 record = { test: { obj: { key: 1 } }, property: "data" };101 var open_rq = createdb(t);102 open_rq.onupgradeneeded = function (e: any) {103 db = e.target.result;104 var objStore = db.createObjectStore("store", { keyPath: "test.obj.key" });105 objStore.put(record);106 };107 open_rq.onsuccess = function (e: any) {108 var rq = db109 .transaction("store")110 .objectStore("store")111 .get(record.test.obj.key);112 rq.onsuccess = function (e: any) {113 t.deepEqual(e.target.result.property, record.property);114 t.end();115 };116 };117});118// IDBObjectStore.put() - autoIncrement and inline keys119test.cb("WPT idbobjectstore_put6.htm", (t) => {120 var db: any,121 record = { property: "data" },122 expected_keys = [1, 2, 3, 4];123 var open_rq = createdb(t);124 open_rq.onupgradeneeded = function (e: any) {125 db = e.target.result;126 var objStore = db.createObjectStore("store", {127 keyPath: "key",128 autoIncrement: true,129 });130 objStore.put(record);131 objStore.put(record);132 objStore.put(record);133 objStore.put(record);134 };135 open_rq.onsuccess = function (e: any) {136 var actual_keys: any[] = [],137 rq = db.transaction("store").objectStore("store").openCursor();138 rq.onsuccess = function (e: any) {139 var cursor = e.target.result;140 if (cursor) {141 actual_keys.push(cursor.value.key);142 cursor.continue();143 } else {144 t.deepEqual(actual_keys, expected_keys);145 t.end();146 }147 };148 };149});150// IDBObjectStore.put() - autoIncrement and out-of-line keys151test.cb("WPT idbobjectstore_put7.htm", (t) => {152 var db: any,153 record = { property: "data" },154 expected_keys = [1, 2, 3, 4];155 var open_rq = createdb(t);156 open_rq.onupgradeneeded = function (e: any) {157 db = e.target.result;158 var objStore = db.createObjectStore("store", { autoIncrement: true });159 objStore.put(record);160 objStore.put(record);161 objStore.put(record);162 objStore.put(record);163 };164 open_rq.onsuccess = function (e) {165 var actual_keys: any[] = [],166 rq = db.transaction("store").objectStore("store").openCursor();167 rq.onsuccess = function (e: any) {168 var cursor = e.target.result;169 if (cursor) {170 actual_keys.push(cursor.key);171 cursor.continue();172 } else {173 t.deepEqual(actual_keys, expected_keys);174 t.end();175 }176 };177 };178});179// IDBObjectStore.put() - object store has autoIncrement:true and the key path is an object attribute180test.cb("WPT idbobjectstore_put8.htm", (t) => {181 var db: any,182 record = { property: "data" },183 expected_keys = [1, 2, 3, 4];184 var open_rq = createdb(t);185 open_rq.onupgradeneeded = function (e: any) {186 db = e.target.result;187 var objStore = db.createObjectStore("store", {188 keyPath: "test.obj.key",189 autoIncrement: true,190 });191 objStore.put(record);192 objStore.put(record);193 objStore.put(record);194 objStore.put(record);195 };196 open_rq.onsuccess = function (e: any) {197 var actual_keys: any[] = [],198 rq = db.transaction("store").objectStore("store").openCursor();199 rq.onsuccess = function (e: any) {200 var cursor = e.target.result;201 if (cursor) {202 actual_keys.push(cursor.value.test.obj.key);203 cursor.continue();204 } else {205 t.deepEqual(actual_keys, expected_keys);206 t.end();207 }208 };209 };210});211//IDBObjectStore.put() - Attempt to put a record that does not meet the constraints of an object store's inline key requirements212test.cb("WPT idbobjectstore_put9.htm", (t) => {213 var record = { key: 1, property: "data" };214 var open_rq = createdb(t);215 open_rq.onupgradeneeded = function (e: any) {216 var rq,217 db = e.target.result,218 objStore = db.createObjectStore("store", { keyPath: "key" });219 t.throws(220 function () {221 rq = objStore.put(record, 1);222 },223 { name: "DataError" },224 );225 t.deepEqual(rq, undefined);226 t.end();227 };228});229//IDBObjectStore.put() - Attempt to call 'put' without an key parameter when the object store uses out-of-line keys230test.cb("WPT idbobjectstore_put10.htm", (t) => {231 var db: any,232 record = { property: "data" };233 var open_rq = createdb(t);234 open_rq.onupgradeneeded = function (e: any) {235 db = e.target.result;236 var rq,237 objStore = db.createObjectStore("store", { keyPath: "key" });238 t.throws(239 function () {240 rq = objStore.put(record);241 },242 { name: "DataError" },243 );244 t.deepEqual(rq, undefined);245 t.end();246 };247});248// IDBObjectStore.put() - Attempt to put a record where the record's key does not meet the constraints of a valid key249test.cb("WPT idbobjectstore_put11.htm", (t) => {250 var db: any,251 record = { key: { value: 1 }, property: "data" };252 var open_rq = createdb(t);253 open_rq.onupgradeneeded = function (e: any) {254 db = e.target.result;255 var rq,256 objStore = db.createObjectStore("store", { keyPath: "key" });257 t.throws(258 function () {259 rq = objStore.put(record);260 },261 { name: "DataError" },262 );263 t.deepEqual(rq, undefined);264 t.end();265 };266});267// IDBObjectStore.put() - Attempt to put a record where the record's in-line key is not defined268test.cb("WPT idbobjectstore_put12.htm", (t) => {269 var db: any,270 record = { property: "data" };271 var open_rq = createdb(t);272 open_rq.onupgradeneeded = function (e: any) {273 db = e.target.result;274 var rq,275 objStore = db.createObjectStore("store", { keyPath: "key" });276 t.throws(277 function () {278 rq = objStore.put(record);279 },280 { name: "DataError" },281 );282 t.deepEqual(rq, undefined);283 t.end();284 };285});286// IDBObjectStore.put() - Attempt to put a record where the out of line key provided does not meet the constraints of a valid key287test.cb("WPT idbobjectstore_put13.htm", (t) => {288 var db: any,289 record = { property: "data" };290 var open_rq = createdb(t);291 open_rq.onupgradeneeded = function (e: any) {292 db = e.target.result;293 var rq,294 objStore = db.createObjectStore("store");295 t.throws(296 function () {297 rq = objStore.put(record, { value: 1 });298 },299 {300 name: "DataError",301 },302 );303 t.deepEqual(rq, undefined);304 t.end();305 };306});307// IDBObjectStore.put() - Put a record where a value being indexed does not meet the constraints of a valid key308test.cb("WPT idbobjectstore_put14.htm", (t) => {309 var db: any,310 record = { key: 1, indexedProperty: { property: "data" } };311 var open_rq = createdb(t);312 open_rq.onupgradeneeded = function (e: any) {313 db = e.target.result;314 var rq,315 objStore = db.createObjectStore("store", { keyPath: "key" });316 objStore.createIndex("index", "indexedProperty");317 rq = objStore.put(record);318 t.true(rq instanceof BridgeIDBRequest);319 rq.onsuccess = function () {320 t.end();321 };322 };323});324// IDBObjectStore.put() - If the transaction this IDBObjectStore belongs to has its mode set to readonly, throw ReadOnlyError325test.cb("WPT idbobjectstore_put15.htm", (t) => {326 var db: any;327 var open_rq = createdb(t);328 open_rq.onupgradeneeded = function (event: any) {329 db = event.target.result;330 db.createObjectStore("store", { keyPath: "pKey" });331 };332 open_rq.onsuccess = function (event: any) {333 var txn = db.transaction("store");334 var ostore = txn.objectStore("store");335 t.throws(336 function () {337 ostore.put({ pKey: "primaryKey_0" });338 },339 {340 name: "ReadOnlyError",341 },342 );343 t.end();344 };345});346// IDBObjectStore.put() - If the object store has been deleted, the implementation must throw a DOMException of type InvalidStateError347test.cb("WPT idbobjectstore_put16.htm", (t) => {348 var db: any, ostore: any;349 var open_rq = createdb(t);350 open_rq.onupgradeneeded = function (event: any) {351 db = event.target.result;352 ostore = db.createObjectStore("store", { keyPath: "pKey" });353 db.deleteObjectStore("store");354 t.throws(355 function () {356 ostore.put({ pKey: "primaryKey_0" });357 },358 {359 name: "InvalidStateError",360 },361 );362 t.end();363 };...
idbobjectstore-get.test.ts
Source:idbobjectstore-get.test.ts
1import test from "ava";2import { BridgeIDBKeyRange, BridgeIDBRequest } from "..";3import { IDBDatabase } from "../idbtypes";4import { createdb } from "./wptsupport";5// IDBObjectStore.get() - key is a number6test.cb("WPT idbobjectstore_get.htm", (t) => {7 var db: any,8 record = { key: 3.14159265, property: "data" };9 var open_rq = createdb(t);10 open_rq.onupgradeneeded = function (e: any) {11 db = e.target.result;12 db.createObjectStore("store", { keyPath: "key" }).add(record);13 };14 open_rq.onsuccess = function (e: any) {15 var rq = db.transaction("store").objectStore("store").get(record.key);16 rq.onsuccess = function (e: any) {17 t.deepEqual(e.target.result.key, record.key);18 t.deepEqual(e.target.result.property, record.property);19 t.end();20 };21 };22});23// IDBObjectStore.get() - key is a string24test.cb("WPT idbobjectstore_get2.htm", (t) => {25 var db: any,26 record = { key: "this is a key that's a string", property: "data" };27 var open_rq = createdb(t);28 open_rq.onupgradeneeded = function (e: any) {29 db = e.target.result;30 db.createObjectStore("store", { keyPath: "key" }).add(record);31 };32 open_rq.onsuccess = function (e: any) {33 var rq = db.transaction("store").objectStore("store").get(record.key);34 rq.onsuccess = function (e: any) {35 t.deepEqual(e.target.result.key, record.key);36 t.deepEqual(e.target.result.property, record.property);37 t.end();38 };39 };40});41// IDBObjectStore.get() - key is a date42test.cb("WPT idbobjectstore_get3.htm", (t) => {43 var db: any;44 const record = { key: new Date(), property: "data" };45 var open_rq = createdb(t);46 open_rq.onupgradeneeded = function (e: any) {47 db = e.target.result;48 db.createObjectStore("store", { keyPath: "key" }).add(record);49 };50 open_rq.onsuccess = function (e: any) {51 var rq = db.transaction("store").objectStore("store").get(record.key);52 rq.onsuccess = function (e: any) {53 t.deepEqual(e.target.result.key.valueOf(), record.key.valueOf());54 t.deepEqual(e.target.result.property, record.property);55 t.end();56 };57 };58});59// IDBObjectStore.get() - attempt to retrieve a record that doesn't exist60test.cb("WPT idbobjectstore_get4.htm", (t) => {61 var db: any;62 var open_rq = createdb(t);63 open_rq.onupgradeneeded = function (e: any) {64 db = e.target.result;65 var rq = db.createObjectStore("store", { keyPath: "key" }).get(1);66 rq.onsuccess = function (e: any) {67 t.deepEqual(e.target.results, undefined);68 setTimeout(function () {69 t.end();70 }, 10);71 };72 };73 open_rq.onsuccess = function () {};74});75// IDBObjectStore.get() - returns the record with the first key in the range76test.cb("WPT idbobjectstore_get5.htm", (t) => {77 var db: any;78 var open_rq = createdb(t);79 open_rq.onupgradeneeded = function (e: any) {80 db = e.target.result;81 var os = db.createObjectStore("store");82 for (var i = 0; i < 10; i++) os.add("data" + i, i);83 };84 open_rq.onsuccess = function (e: any) {85 db86 .transaction("store")87 .objectStore("store")88 .get(BridgeIDBKeyRange.bound(3, 6)).onsuccess = function (e: any) {89 t.deepEqual(e.target.result, "data3", "get(3-6)");90 t.end();91 };92 };93});94// IDBObjectStore.get() - throw TransactionInactiveError on aborted transaction95test.cb("WPT idbobjectstore_get6.htm", (t) => {96 var db: any;97 var open_rq = createdb(t);98 open_rq.onupgradeneeded = function (e: any) {99 db = e.target.result;100 db.createObjectStore("store", { keyPath: "key" });101 };102 open_rq.onsuccess = function (e: any) {103 var store = db.transaction("store").objectStore("store");104 store.transaction.abort();105 t.throws(106 function () {107 store.get(1);108 },109 { name: "TransactionInactiveError" },110 "throw TransactionInactiveError on aborted transaction.",111 );112 t.end();113 };114});115// IDBObjectStore.get() - throw DataError when using invalid key116test.cb("WPT idbobjectstore_get7.htm", (t) => {117 var db: any;118 var open_rq = createdb(t);119 open_rq.onupgradeneeded = function (e: any) {120 db = e.target.result;121 db.createObjectStore("store", { keyPath: "key" });122 };123 open_rq.onsuccess = function (e: any) {124 var store = db.transaction("store").objectStore("store");125 t.throws(126 function () {127 store.get(null);128 },129 { name: "DataError" },130 "throw DataError when using invalid key.",131 );132 t.end();133 };...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) return console.error(err);24 console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15 console.log(data);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('./wpt.js');2wpt.open_rq('', function(rq) {3 console.log(res.statusCode);4 res.on('data', function(chunk) {5 console.log('BODY: ' + chunk);6 });7 });8});9var http = require('http');10var wpt = {11 open_rq: function(url, callback) {12 var rq = http.request(url, function(res) {13 callback(res);14 });15 return rq;16 }17};18module.exports = wpt;
Using AI Code Generation
1function open_rq() {2 return new Promise(resolve => {3 var request = new XMLHttpRequest();4 request.onload = function() {5 if (request.status >= 200 && request.status < 400) {6 var data = request.responseText;7 resolve(data);8 } else {9 console.log('error');10 }11 };12 request.onerror = function() {13 console.log('error');14 };15 request.send();16 });17}18function fetch_rq() {19 .then(function(response) {20 return response.text();21 })22 .then(function(data) {23 return data;24 });25}26async function fetch_rq_async() {27 const data = await response.text();28 return data;29}30async function fetch_rq_async() {31 const data = await response.text();32 return data;33}34async function fetch_rq_async() {35 const data = await response.text();36 return data;37}38async function fetch_rq_async() {39 const data = await response.text();40 return data;41}
Using AI Code Generation
1var rq = wpt.open_rq(url);2rq.send();3var header = rq.getResponseHeader("Content-Type");4rq.setRequestHeader("Content-Type", "text/xml");5var header = rq.getResponseHeader("Content-Type");6var allheaders = rq.getAllResponseHeaders();7var header = rq.getResponseHeader("Content-Type");8var allheaders = rq.getAllResponseHeaders();9var allheaders = rq.getAllResponseHeaders();10var header = rq.getResponseHeader("Content-Type");11var allheaders = rq.getAllResponseHeaders();12var header = rq.getResponseHeader("Content-Type");13var allheaders = rq.getAllResponseHeaders();14var header = rq.getResponseHeader("Content-Type");15var allheaders = rq.getAllResponseHeaders();16var header = rq.getResponseHeader("Content-Type");17var allheaders = rq.getAllResponseHeaders();18var header = rq.getResponseHeader("Content-Type");
Using AI Code Generation
1function open_rq() {2 var rq = new XMLHttpRequest();3 rq.send();4 return rq.responseText;5}6function open_rs() {7 var rs = new XMLHttpRequest();8 rs.send('Hello World');9 return rs.responseText;10}11function open_rs_with_content_type() {12 var rs = new XMLHttpRequest();13 rs.setRequestHeader('content-type', 'application/x-www-form-urlencoded');14 rs.send('Hello World');15 return rs.responseText;16}17function open_rs_with_content_type_and_charset() {18 var rs = new XMLHttpRequest();19 rs.setRequestHeader('content-type', 'application/x-www-form-urlencoded; charset=utf-8');20 rs.send('Hello World');21 return rs.responseText;22}23function open_rs_with_content_type_and_charset_and_extra() {24 var rs = new XMLHttpRequest();25 rs.setRequestHeader('content-type', 'application/x-www-form-urlencoded; charset=utf-8; extra=extra');26 rs.send('Hello World');27 return rs.responseText;28}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!