Best JavaScript code snippet using istanbul
battery-interface.js
Source:battery-interface.js
1(function() {2 setup("", {explicit_done: true});3 /**4 *5 * partial interface Navigator {6 * Promise<BatteryManager> getBattery ();7 * };8 *9 */10 test(function() {11 assert_idl_attribute(navigator, 'getBattery', 'navigator must have getBattery attribute');12 }, 'getBattery is present on navigator');13 navigator.getBattery().then(function (battery) {14 /**15 *16 * interface BatteryManager : EventTarget {17 * readonly attribute boolean charging;18 * readonly attribute unrestricted double chargingTime;19 * readonly attribute unrestricted double dischargingTime;20 * readonly attribute double level;21 * attribute EventHandler onchargingchange;22 * attribute EventHandler onchargingtimechange;23 * attribute EventHandler ondischargingtimechange;24 * attribute EventHandler onlevelchange;25 * };26 *27 */28 // interface BatteryManager : EventTarget {29 test(function() {30 assert_own_property(window, 'BatteryManager');31 }, 'window has an own property BatteryManager');32 test(function() {33 assert_true(battery instanceof EventTarget);34 }, 'battery inherits from EventTarget');35 // readonly attribute boolean charging;36 test(function() {37 assert_idl_attribute(battery, 'charging', 'battery must have charging attribute');38 }, 'charging attribute exists');39 test(function() {40 assert_readonly(battery, 'charging', 'charging must be readonly')41 }, 'charging attribute is readonly');42 // readonly attribute unrestricted double chargingTime;43 test(function() {44 assert_idl_attribute(battery, 'chargingTime', 'battery must have chargingTime attribute');45 }, 'chargingTime attribute exists');46 test(function() {47 assert_readonly(battery, 'chargingTime', 'chargingTime must be readonly')48 }, 'chargingTime attribute is readonly');49 // readonly attribute unrestricted double dischargingTime;50 test(function() {51 assert_idl_attribute(battery, 'dischargingTime', 'battery must have dischargingTime attribute');52 }, 'dischargingTime attribute exists');53 test(function() {54 assert_readonly(battery, 'dischargingTime', 'dischargingTime must be readonly')55 }, 'dischargingTime attribute is readonly');56 // readonly attribute double level;57 test(function() {58 assert_idl_attribute(battery, 'level', 'battery must have level attribute');59 }, 'level attribute exists');60 test(function() {61 assert_readonly(battery, 'level', 'level must be readonly')62 }, 'level attribute is readonly');63 // attribute EventHandler onchargingchange;64 test(function() {65 assert_idl_attribute(battery, 'onchargingchange', 'battery must have onchargingchange attribute');66 }, 'onchargingchange attribute exists');67 test(function() {68 assert_equals(battery.onchargingchange, null, 'onchargingchange must be null')69 }, 'onchargingchange is null');70 test(function() {71 var desc = 'onchargingchange did not accept callable object',72 func = function() {},73 desc = 'Expected to find onchargingchange attribute on battery object';74 assert_idl_attribute(battery, 'onchargingchange', desc);75 window.onchargingchange = func;76 assert_equals(window.onchargingchange, func, desc);77 }, 'onchargingchange is set to function');78 test(function() {79 var desc = 'onchargingchange did not treat noncallable as null';80 battery.onchargingchange = function() {};81 battery.onchargingchange = {};82 assert_equals(battery.onchargingchange, null, desc);83 }, 'onchargingchange: treat object as null');84 test(function() {85 var desc = 'onchargingchange did not treat noncallable as null';86 battery.onchargingchange = function() {};87 battery.onchargingchange = {88 call: 'test'89 };90 assert_equals(battery.onchargingchange, null, desc);91 }, 'onchargingchange: treat object with non-callable call property as null');92 test(function() {93 var desc = 'onchargingchange did not treat noncallable (string) as null';94 battery.onchargingchange = function() {};95 battery.onchargingchange = 'string';96 assert_equals(battery.onchargingchange, null, desc);97 }, 'onchargingchange: treat string as null');98 test(function() {99 var desc = 'onchargingchange did not treat noncallable (number) as null';100 battery.onchargingchange = function() {};101 battery.onchargingchange = 123;102 assert_equals(battery.onchargingchange, null, desc);103 }, 'onchargingchange: treat number as null');104 test(function() {105 var desc = 'onchargingchange did not treat noncallable (undefined) as null';106 battery.onchargingchange = function() {};107 battery.onchargingchange = undefined;108 assert_equals(battery.onchargingchange, null, desc);109 }, 'onchargingchange: treat undefined as null');110 test(function() {111 var desc = 'onchargingchange did not treat noncallable (array) as null';112 battery.onchargingchange = function() {};113 battery.onchargingchange = [];114 assert_equals(battery.onchargingchange, null, desc);115 }, 'onchargingchange: treat array as null');116 // attribute EventHandler onchargingtimechange;117 test(function() {118 assert_idl_attribute(battery, 'onchargingtimechange', 'battery must have onchargingtimechange attribute');119 }, 'onchargingtimechange attribute exists');120 test(function() {121 assert_equals(battery.onchargingtimechange, null, 'onchargingtimechange must be null')122 }, 'onchargingtimechange is null');123 test(function() {124 var desc = 'onchargingtimechange did not accept callable object',125 func = function() {},126 desc = 'Expected to find onchargingtimechange attribute on battery object';127 assert_idl_attribute(battery, 'onchargingtimechange', desc);128 window.onchargingtimechange = func;129 assert_equals(window.onchargingtimechange, func, desc);130 }, 'onchargingtimechange is set to function');131 test(function() {132 var desc = 'onchargingtimechange did not treat noncallable as null';133 battery.onchargingtimechange = function() {};134 battery.onchargingtimechange = {};135 assert_equals(battery.onchargingtimechange, null, desc);136 }, 'onchargingtimechange: treat object as null');137 test(function() {138 var desc = 'onchargingtimechange did not treat noncallable as null';139 battery.onchargingtimechange = function() {};140 battery.onchargingtimechange = {141 call: 'test'142 };143 assert_equals(battery.onchargingtimechange, null, desc);144 }, 'onchargingtimechange: treat object with non-callable call property as null');145 test(function() {146 var desc = 'onchargingtimechange did not treat noncallable (string) as null';147 battery.onchargingtimechange = function() {};148 battery.onchargingtimechange = 'string';149 assert_equals(battery.onchargingtimechange, null, desc);150 }, 'onchargingtimechange: treat string as null');151 test(function() {152 var desc = 'onchargingtimechange did not treat noncallable (number) as null';153 battery.onchargingtimechange = function() {};154 battery.onchargingtimechange = 123;155 assert_equals(battery.onchargingtimechange, null, desc);156 }, 'onchargingtimechange: treat number as null');157 test(function() {158 var desc = 'onchargingtimechange did not treat noncallable (undefined) as null';159 battery.onchargingtimechange = function() {};160 battery.onchargingtimechange = undefined;161 assert_equals(battery.onchargingtimechange, null, desc);162 }, 'onchargingtimechange: treat undefined as null');163 test(function() {164 var desc = 'onchargingtimechange did not treat noncallable (array) as null';165 battery.onchargingtimechange = function() {};166 battery.onchargingtimechange = [];167 assert_equals(battery.onchargingtimechange, null, desc);168 }, 'onchargingtimechange: treat array as null');169 // attribute EventHandler ondischargingtimechange;170 test(function() {171 assert_idl_attribute(battery, 'ondischargingtimechange', 'battery must have ondischargingtimechange attribute');172 }, 'ondischargingtimechange attribute exists');173 test(function() {174 assert_equals(battery.ondischargingtimechange, null, 'ondischargingtimechange must be null')175 }, 'ondischargingtimechange is null');176 test(function() {177 var desc = 'ondischargingtimechange did not accept callable object',178 func = function() {},179 desc = 'Expected to find ondischargingtimechange attribute on battery object';180 assert_idl_attribute(battery, 'ondischargingtimechange', desc);181 window.ondischargingtimechange = func;182 assert_equals(window.ondischargingtimechange, func, desc);183 }, 'ondischargingtimechange is set to function');184 test(function() {185 var desc = 'ondischargingtimechange did not treat noncallable as null';186 battery.ondischargingtimechange = function() {};187 battery.ondischargingtimechange = {};188 assert_equals(battery.ondischargingtimechange, null, desc);189 }, 'ondischargingtimechange: treat object as null');190 test(function() {191 var desc = 'ondischargingtimechange did not treat noncallable as null';192 battery.ondischargingtimechange = function() {};193 battery.ondischargingtimechange = {194 call: 'test'195 };196 assert_equals(battery.ondischargingtimechange, null, desc);197 }, 'ondischargingtimechange: treat object with non-callable call property as null');198 test(function() {199 var desc = 'ondischargingtimechange did not treat noncallable (string) as null';200 battery.ondischargingtimechange = function() {};201 battery.ondischargingtimechange = 'string';202 assert_equals(battery.ondischargingtimechange, null, desc);203 }, 'ondischargingtimechange: treat string as null');204 test(function() {205 var desc = 'ondischargingtimechange did not treat noncallable (number) as null';206 battery.ondischargingtimechange = function() {};207 battery.ondischargingtimechange = 123;208 assert_equals(battery.ondischargingtimechange, null, desc);209 }, 'ondischargingtimechange: treat number as null');210 test(function() {211 var desc = 'ondischargingtimechange did not treat noncallable (undefined) as null';212 battery.ondischargingtimechange = function() {};213 battery.ondischargingtimechange = undefined;214 assert_equals(battery.ondischargingtimechange, null, desc);215 }, 'ondischargingtimechange: treat undefined as null');216 test(function() {217 var desc = 'ondischargingtimechange did not treat noncallable (array) as null';218 battery.ondischargingtimechange = function() {};219 battery.ondischargingtimechange = [];220 assert_equals(battery.ondischargingtimechange, null, desc);221 }, 'ondischargingtimechange: treat array as null');222 // attribute EventHandler onlevelchange;223 test(function() {224 assert_idl_attribute(battery, 'onlevelchange', 'battery must have onlevelchange attribute');225 }, 'onlevelchange attribute exists');226 test(function() {227 assert_equals(battery.onlevelchange, null, 'onlevelchange must be null')228 }, 'onlevelchange is null');229 test(function() {230 var desc = 'onlevelchange did not accept callable object',231 func = function() {},232 desc = 'Expected to find onlevelchange attribute on battery object';233 assert_idl_attribute(battery, 'onlevelchange', desc);234 window.onlevelchange = func;235 assert_equals(window.onlevelchange, func, desc);236 }, 'onlevelchange is set to function');237 test(function() {238 var desc = 'onlevelchange did not treat noncallable as null';239 battery.onlevelchange = function() {};240 battery.onlevelchange = {};241 assert_equals(battery.onlevelchange, null, desc);242 }, 'onlevelchange: treat object as null');243 test(function() {244 var desc = 'onlevelchange did not treat noncallable as null';245 battery.onlevelchange = function() {};246 battery.onlevelchange = {247 call: 'test'248 };249 assert_equals(battery.onlevelchange, null, desc);250 }, 'onlevelchange: treat object with non-callable call property as null');251 test(function() {252 var desc = 'onlevelchange did not treat noncallable (string) as null';253 battery.onlevelchange = function() {};254 battery.onlevelchange = 'string';255 assert_equals(battery.onlevelchange, null, desc);256 }, 'onlevelchange: treat string as null');257 test(function() {258 var desc = 'onlevelchange did not treat noncallable (number) as null';259 battery.onlevelchange = function() {};260 battery.onlevelchange = 123;261 assert_equals(battery.onlevelchange, null, desc);262 }, 'onlevelchange: treat number as null');263 test(function() {264 var desc = 'onlevelchange did not treat noncallable (undefined) as null';265 battery.onlevelchange = function() {};266 battery.onlevelchange = undefined;267 assert_equals(battery.onlevelchange, null, desc);268 }, 'onlevelchange: treat undefined as null');269 test(function() {270 var desc = 'onlevelchange did not treat noncallable (array) as null';271 battery.onlevelchange = function() {};272 battery.onlevelchange = [];273 assert_equals(battery.onlevelchange, null, desc);274 }, 'onlevelchange: treat array as null');275 done();276 }, function () {});...
battery_unit.test.js
Source:battery_unit.test.js
1+137/*2 * Copyright (C) 2021 Huawei Device Co., Ltd.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15import app from '@system.app'16import Context from '@ohos.napi_context'17import batteryInfo from '@ohos.batteryInfo';18import brightness from '@ohos.brightness';19import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'20describe('appInfoTest', function () {21 console.log("*************Battery Unit Test Begin*************");22 23 /**24 * @tc.number battery_manager_js_010025 * @tc.name battery_soc_test26 * @tc.desc Battery acquisition kit27 */28 it('battery_soc_test', 0, function () {29 var batterySoc = batteryInfo.batterySOC;30 console.info('batterySoc = ' + batterySoc);31 expect(batterySoc >= -1 && batterySoc <= 100).assertTrue()32 })33 /**34 * @tc.number battery_manager_js_020035 * @tc.name charging_status_test36 * @tc.desc Battery charging kit37 */38 it('charging_status_test', 0, function () {39 var chargingStatus = batteryInfo.chargingStatus;40 console.info('chargingStatus = ' + chargingStatus);41 expect(chargingStatus >= 0 && chargingStatus <= 4).assertTrue()42 })43 /**44 * @tc.number battery_manager_js_030045 * @tc.name health_status_test46 * @tc.desc Get Battery Health Get KIT47 */48 it('health_status_test', 0, function () {49 var healthStatus = batteryInfo.healthStatus;50 console.info('healthStatus = ' + healthStatus);51 expect(healthStatus >= 0 && healthStatus <= 6).assertTrue()52 })53 /**54 * @tc.number battery_manager_js_040055 * @tc.name plugged_type_test56 * @tc.desc Obtaining the USB Connection Type KIT57 */58 it('plugged_type_test', 0, function () {59 var pluggedType = batteryInfo.pluggedType;60 console.info('pluggedType = ' + pluggedType);61 expect(pluggedType >= 0 && pluggedType <= 4).assertTrue()62 })63 /**64 * @tc.number battery_manager_js_050065 * @tc.name voltage_test66 * @tc.desc Obtaining the Voltage Interface KIT67 */68 it('voltage_test', 0, function () {69 var voltage = batteryInfo.voltage;70 console.info('voltage = ' + voltage);71 expect(voltage >= -1).assertTrue()72 })73 /**74 * @tc.number battery_manager_js_060075 * @tc.name technology_test76 * @tc.desc Obtaining the Battery Technology Interface KIT77 */78 it('technology_test', 0, function () {79 var technology = batteryInfo.technology;80 console.info('technology = ' + technology);81 expect(technology !== null).assertTrue()82 })83 /**84 * @tc.number battery_manager_js_070085 * @tc.name battery_temperature_test86 * @tc.desc BatteryTemperature values Interface Test87 */88 it('battery_temperature_test', 0, function () {89 var batteryTemperature = batteryInfo.batteryTemperature;90 console.info('batteryTemperature = ' + batteryTemperature);91 expect(batteryTemperature <= 700).assertTrue()92 })93 /**94 * @tc.number battery_manager_js_080095 * @tc.name enum_health_state_test_unknown96 * @tc.desc BatteryHealthState values Interface Test97 */98 it('enum_health_state_test_unknown', 0, function () {99 var batteryHealthState = batteryInfo.BatteryHealthState.UNKNOWN;100 console.info('batteryHealthState = ' + batteryHealthState);101 expect(batteryHealthState == 0).assertTrue()102 })103 /**104 * @tc.number battery_manager_js_0900105 * @tc.name enum_health_state_test_good106 * @tc.desc BatteryHealthState values Interface Test107 */108 it('enum_health_state_test_good', 0, function () {109 var batteryHealthState = batteryInfo.BatteryHealthState.GOOD;110 console.info('batteryHealthState = ' + batteryHealthState);111 expect(batteryHealthState == 1).assertTrue()112 })113 /**114 * @tc.number battery_manager_js_1000115 * @tc.name enum_health_state_test_overheat116 * @tc.desc BatteryHealthState values Interface Test117 */118 it('enum_health_state_test_overheat', 0, function () {119 var batteryHealthState = batteryInfo.BatteryHealthState.OVERHEAT;120 console.info('batteryHealthState = ' + batteryHealthState);121 expect(batteryHealthState == 2).assertTrue()122 })123 /**124 * @tc.number battery_manager_js_1100125 * @tc.name enum_health_state_test_overvoltage126 * @tc.desc BatteryHealthState values Interface Test127 */128 it('enum_health_state_test_overvoltage', 0, function () {129 var batteryHealthState = batteryInfo.BatteryHealthState.OVERVOLTAGE;130 console.info('batteryHealthState = ' + batteryHealthState);131 expect(batteryHealthState == 3).assertTrue()132 })133 /**134 * @tc.number battery_manager_js_1200135 * @tc.name enum_health_state_test_cold136 * @tc.desc BatteryHealthState values Interface Test137 */138 it('enum_health_state_test_cold', 0, function () {139 var batteryHealthState = batteryInfo.BatteryHealthState.COLD;140 console.info('batteryHealthState = ' + batteryHealthState);141 expect(batteryHealthState == 4).assertTrue()142 })143 /**144 * @tc.number battery_manager_js_1300145 * @tc.name enum_health_state_test_dead146 * @tc.desc BatteryHealthState values Interface Test147 */148 it('enum_health_state_test_dead', 0, function () {149 var batteryHealthState = batteryInfo.BatteryHealthState.DEAD;150 console.info('batteryHealthState = ' + batteryHealthState);151 expect(batteryHealthState == 5).assertTrue()152 })153 /**154 * @tc.number battery_manager_js_1400155 * @tc.name enum_charge_state_test_none156 * @tc.desc BatteryChargeState values Interface Test157 */158 it('enum_charge_state_test_none', 0, function () {159 var batteryChargeState = batteryInfo.BatteryChargeState.NONE;160 console.info('batteryChargeState = ' + batteryChargeState);161 expect(batteryChargeState == 0).assertTrue()162 })163 /**164 * @tc.number battery_manager_js_1500165 * @tc.name enum_charge_state_test_enable166 * @tc.desc BatteryChargeState values Interface Test167 */168 it('enum_charge_state_test_enable', 0, function () {169 var batteryChargeState = batteryInfo.BatteryChargeState.ENABLE;170 console.info('batteryChargeState = ' + batteryChargeState);171 expect(batteryChargeState == 1).assertTrue()172 })173 /**174 * @tc.number battery_manager_js_1600175 * @tc.name enum_charge_state_test_disable176 * @tc.desc BatteryChargeState values Interface Test177 */178 it('enum_charge_state_test_disable', 0, function () {179 var batteryChargeState = batteryInfo.BatteryChargeState.DISABLE;180 console.info('batteryChargeState = ' + batteryChargeState);181 expect(batteryChargeState == 2).assertTrue()182 })183 /**184 * @tc.number battery_manager_js_1700185 * @tc.name enum_charge_state_test_full186 * @tc.desc BatteryChargeState values Interface Test187 */188 it('enum_charge_state_test_full', 0, function () {189 var batteryChargeState = batteryInfo.BatteryChargeState.FULL;190 console.info('batteryChargeState = ' + batteryChargeState);191 expect(batteryChargeState == 3).assertTrue()192 })193 /**194 * @tc.number battery_manager_js_1800195 * @tc.name enum_plugged_type_test_none196 * @tc.desc BatteryPluggedType values Interface Test197 */198 it('enum_plugged_type_test_none', 0, function () {199 var batteryPluggedType = batteryInfo.BatteryPluggedType.NONE;200 console.info('batteryPluggedType = ' + batteryPluggedType);201 expect(batteryPluggedType == 0).assertTrue()202 })203 /**204 * @tc.number battery_manager_js_1900205 * @tc.name enum_plugged_type_test_ac206 * @tc.desc BatteryPluggedType values Interface Test207 */208 it('enum_plugged_type_test_ac', 0, function () {209 var batteryPluggedType = batteryInfo.BatteryPluggedType.AC;210 console.info('batteryPluggedType = ' + batteryPluggedType);211 expect(batteryPluggedType == 1).assertTrue()212 })213 /**214 * @tc.number battery_manager_js_2000215 * @tc.name enum_plugged_type_test_usb216 * @tc.desc BatteryPluggedType values Interface Test217 */218 it('enum_plugged_type_test_usb', 0, function () {219 var batteryPluggedType = batteryInfo.BatteryPluggedType.USB;220 console.info('batteryPluggedType = ' + batteryPluggedType);221 expect(batteryPluggedType == 2).assertTrue()222 })223 /**224 * @tc.number battery_manager_js_2100225 * @tc.name enum_plugged_type_test_wireless226 * @tc.desc BatteryPluggedType values Interface Test227 */228 it('enum_plugged_type_test_wireless', 0, function () {229 var batteryPluggedType = batteryInfo.BatteryPluggedType.WIRELESS;230 console.info('batteryPluggedType = ' + batteryPluggedType);231 expect(batteryPluggedType == 3).assertTrue()232 })233 /**234 * @tc.number battery_manager_js_2200235 * @tc.name brightness_test236 * @tc.desc Set Value Interface Test237 */238 it('brightness_test', 0, function () {239 brightness.setValue(10);240 brightness.setValue(0);241 brightness.setValue(255);242 expect(0 == 0).assertTrue();243 })244 /**245 * @tc.number battery_manager_js_2300246 * @tc.name is_battery_present_test247 * @tc.desc Battry Present Interface Test248 */249 it('is_battery_present_test', 0, function () {250 var isBatteryPresent = batteryInfo.isBatteryPresent;251 console.info('isBatteryPresent = ' + isBatteryPresent);252 if (isBatteryPresent) {253 expect(isBatteryPresent).assertTrue();254 }else{255 expect(isBatteryPresent).assertFalse(); 256 }257 })...
browser_Battery.js
Source:browser_Battery.js
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4var imported = Components.utils.import("resource://gre/modules/Battery.jsm", this);5Cu.import("resource://gre/modules/Services.jsm", this);6function test() {7 waitForExplicitFinish();8 is(imported.Debugging.fake, false, "Battery spoofing is initially false")9 // begin deprecated battery API testing10 for (let k of ["charging", "chargingTime", "dischargingTime", "level"]) {11 Assert.throws(() => Battery[k] = 10, "Setting battery " + k + "preference without spoofing enabled should throw");12 ok(Battery[k] == Services.appShell.hiddenDOMWindow.navigator.battery[k], "Battery "+ k + " is correctly set");13 }14 imported.Debugging.fake = true;15 Battery.charging = true;16 Battery.chargingTime = 100;17 Battery.level = 0.5;18 ok(Battery.charging, "Test for charging setter");19 is(Battery.chargingTime, 100, "Test for chargingTime setter");20 is(Battery.level, 0.5, "Test for level setter");21 Battery.charging = false;22 Battery.dischargingTime = 50;23 Battery.level = 0.7;24 ok(!Battery.charging, "Test for charging setter");25 is(Battery.dischargingTime, 50, "Test for dischargingTime setter");26 is(Battery.level, 0.7, "Test for level setter");27 imported.Debugging.fake = false;28 // end deprecated battery API testing29 GetBattery().then(function (battery) {30 for (let k of ["charging", "chargingTime", "dischargingTime", "level"]) {31 let backup = battery[k];32 battery[k] = "__magic__";33 is(battery[k], backup, "Setting battery " + k + "preference without spoofing enabled should fail");34 }35 imported.Debugging.fake = true;36 // reload again to get the fake one37 GetBattery().then(function (battery) {38 battery.charging = true;39 battery.chargingTime = 100;40 battery.level = 0.5;41 ok(battery.charging, "Test for charging setter");42 is(battery.chargingTime, 100, "Test for chargingTime setter");43 is(battery.level, 0.5, "Test for level setter");44 battery.charging = false;45 battery.dischargingTime = 50;46 battery.level = 0.7;47 ok(!battery.charging, "Test for charging setter");48 is(battery.dischargingTime, 50, "Test for dischargingTime setter");49 is(battery.level, 0.7, "Test for level setter");50 finish();51 });52 });...
Using AI Code Generation
1var battery = require('battery');2battery(function(err, data) {3 console.log(data);4});5var battery = require('battery');6battery(function(err, data) {7 console.log(data);8});9var battery = require('battery');10battery(function(err, data) {11 console.log(data);12});13var battery = require('battery');14battery(function(err, data) {15 console.log(data);16});17var battery = require('battery');18battery(function(err, data) {19 console.log(data);20});21var battery = require('battery');22battery(function(err, data) {23 console.log(data);24});25var battery = require('battery');26battery(function(err, data) {27 console.log(data);28});29var battery = require('battery');30battery(function(err, data) {31 console.log(data);32});33var battery = require('battery');34battery(function(err, data) {35 console.log(data);36});37var battery = require('battery');38battery(function(err, data) {39 console.log(data);40});41var battery = require('battery');42battery(function(err, data) {43 console.log(data);44});45var battery = require('battery');46battery(function(err, data) {47 console.log(data);48});49var battery = require('battery');50battery(function(err, data) {51 console.log(data);52});53var battery = require('battery');54battery(function(err, data) {
Using AI Code Generation
1var battery = require('battery');2battery(function(err, result) {3 console.log(result);4});5{6 "scripts": {7 },8 "dependencies": {9 },10 "devDependencies": {11 },12 "repository": {
Using AI Code Generation
1var assert = require('assert');2var test = require('selenium-webdriver/testing');3var webdriver = require('selenium-webdriver');4var By = webdriver.By;5var until = webdriver.until;6test.describe('Google Search', function() {7 var driver;8 test.before(function() {9 driver = new webdriver.Builder()10 .forBrowser('firefox')11 .build();12 });13 test.it('should append query to title', function() {14 driver.findElement(By.name('q')).sendKeys('webdriver');15 driver.findElement(By.name('btnG')).click();16 driver.wait(until.titleIs('webdriver - Google Search'), 1000);17 });18 test.after(function() {19 driver.quit();20 });21});22{23 "scripts": {24 },25 "devDependencies": {26 }27}
Using AI Code Generation
1var istanbul = require('browserify-istanbul');2var isparta = require('isparta');3var b = browserify({4 istanbul({ instrumenter: isparta })5});6b.bundle()7 .pipe(source('test.js'))8 .pipe(gulp.dest('./test'))9 .pipe(mocha({ reporter: 'spec' }))10 .pipe(istanbul.writeReports());11});12"scripts": {13}14"devDependencies": {15}
Using AI Code Generation
1var battery = require('battery');2var battery = new battery();3battery.on('error', function(err) {4 console.log('Error: ' + err);5});6battery.on('data', function(data) {7 console.log('Battery: ' + data);8});9battery.on('percent', function(percent) {10 console.log('Battery: ' + percent + '%');11});12{13 "scripts": {14 },15 "dependencies": {16 },17 "devDependencies": {18 }19}20var battery = require('battery');21var battery = new battery();22battery.on('error', function(err) {23 console.log('Error: ' + err);24});25battery.on('data', function(data) {26 console.log('Battery: ' + data);27});28battery.on('percent', function(percent) {29 console.log('Battery: ' + percent + '%');30});
Using AI Code Generation
1var battery = require('battery');2battery(function(err, result){3 console.log(result);4});5var battery = require('battery');6battery(function(err, result){7 console.log(result);8});9var express = require('express');10var request = require('supertest');11var assert = require('assert');12var app = express();13app.get('/', function(req, res) {14 res.send('Hello World');15});16describe('GET /', function() {17 it('respond with Hello World', function(done) {18 request(app)19 .get('/')20 .expect('Hello World')21 .end(function(err, res) {22 if (err) throw err;23 done();24 });25 });26});27 0 passing (5ms)28"devDependencies": {29 }
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!!