How to use callback method in testing-library-react-hooks

Best JavaScript code snippet using testing-library-react-hooks

FileLoaderPluginTest.js

Source:FileLoaderPluginTest.js Github

copy

Full Screen

1/*2 * Copyright 2009 Google Inc.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not5 * use this file except in compliance with the License. You may obtain a copy of6 * the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13 * License for the specific language governing permissions and limitations under14 * the License.15 */16var FileLoaderPluginCallbackTests = ConditionalTestCase(17 'FileLoaderPluginCallbackTests',18 function() {19 return !jstestdriver.jQuery.browser.opera;20});21FileLoaderPluginCallbackTests.prototype.createScriptLoader = function(win, dom) {22 return new jstestdriver.plugins.ScriptLoader(win, dom, {23 updateLatestTestCase: function() {},24 removeTestCaseForFilename: function() {}25 }, jstestdriver.now);26};27FileLoaderPluginCallbackTests.prototype.testFileOnLoadJs = function() {28 var mockDOM = new jstestdriver.MockDOM();29 var head = mockDOM.createElement('head');30 var scriptLoader = this.createScriptLoader({}, mockDOM);31 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);32 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,33 stylesheetLoader,34 jstestdriver.now);35 var file = new jstestdriver.FileSource('file.js', 12);36 var callbackCalled = false;37 var callbackFileResult = null;38 var callback = function(fileResult) {39 callbackCalled = true;40 callbackFileResult = fileResult;41 };42 fileLoaderPlugin.loadSource(file, callback);43 assertEquals(1, head.childNodes.length);44 var script = head.childNodes[0];45 script.onload();46 assertEquals('script', script.nodeName);47 assertEquals('text/javascript', script.type);48 assertEquals('file.js', script.src);49 assertTrue(callbackCalled);50 assertNotNull(callbackFileResult);51 assertTrue(callbackFileResult.success);52 assertEquals('', callbackFileResult.message);53 assertNotNull(callbackFileResult.file);54 assertEquals('file.js', callbackFileResult.file.fileSrc);55 assertEquals(12, callbackFileResult.file.timestamp);56};57FileLoaderPluginCallbackTests.prototype.testFileOnLoadJsError = function() {58 var mockDOM = new jstestdriver.MockDOM();59 var head = mockDOM.createElement('head');60 var scriptLoader = this.createScriptLoader({}, mockDOM);61 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);62 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,63 stylesheetLoader);64 var file = new jstestdriver.FileSource('file.js', 42);65 var callbackCalled = false;66 var callbackFileResult = null;67 var callback = function(fileResult) {68 callbackCalled = true;69 callbackFileResult = fileResult;70 };71 fileLoaderPlugin.loadSource(file, callback);72 assertEquals(1, head.childNodes.length);73 var script = head.childNodes[0];74 script.onerror('msg', 'url', 42);75 script.onload();76 assertEquals('script', script.nodeName);77 assertEquals('text/javascript', script.type);78 assertEquals('file.js', script.src);79 assertTrue(callbackCalled);80 assertNotNull(callbackFileResult);81 assertFalse(callbackFileResult.success);82 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);83 assertNotNull(callbackFileResult.file);84 assertEquals('file.js', callbackFileResult.file.fileSrc);85 assertEquals(42, callbackFileResult.file.timestamp);86};87FileLoaderPluginCallbackTests.prototype.testFileOnLoadJsWindowError = function() {88 var mockDOM = new jstestdriver.MockDOM();89 var head = mockDOM.createElement('head');90 var win = {};91 var scriptLoader = this.createScriptLoader(win, mockDOM);92 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);93 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,94 stylesheetLoader);95 var file = new jstestdriver.FileSource('file.js', 42);96 var callbackCalled = false;97 var callbackFileResult = null;98 var callback = function(fileResult) {99 callbackCalled = true;100 callbackFileResult = fileResult;101 };102 fileLoaderPlugin.loadSource(file, callback);103 assertNotNull(win.onerror);104 assertEquals(1, head.childNodes.length);105 var script = head.childNodes[0];106 win.onerror('msg', 'url', 42);107 script.onload();108 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);109 assertEquals('script', script.nodeName);110 assertEquals('text/javascript', script.type);111 assertEquals('file.js', script.src);112 assertTrue(callbackCalled);113 assertNotNull(callbackFileResult);114 assertFalse(callbackFileResult.success);115 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);116 assertNotNull(callbackFileResult.file);117 assertEquals('file.js', callbackFileResult.file.fileSrc);118 assertEquals(42, callbackFileResult.file.timestamp);119};120FileLoaderPluginCallbackTests.prototype.testFileOnLoadCss = function() {121 var mockDOM = new jstestdriver.MockDOM();122 var head = mockDOM.createElement('head');123 var scriptLoader = this.createScriptLoader({}, mockDOM);124 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);125 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,126 stylesheetLoader);127 var file = new jstestdriver.FileSource('file.css', 24);128 var callbackCalled = false;129 var callbackFileResult = null;130 var callback = function(fileResult) {131 callbackCalled = true;132 callbackFileResult = fileResult;133 };134 fileLoaderPlugin.loadSource(file, callback);135 assertEquals(1, head.childNodes.length);136 var link = head.childNodes[0];137 link.onload();138 assertEquals('link', link.nodeName);139 assertEquals('text/css', link.type);140 assertEquals('stylesheet', link.rel);141 assertEquals('file.css', link.href);142 assertTrue(callbackCalled);143 assertNotNull(callbackFileResult);144 assertTrue(callbackFileResult.success);145 assertEquals('', callbackFileResult.message);146 assertNotNull(callbackFileResult.file);147 assertEquals('file.css', callbackFileResult.file.fileSrc);148 assertEquals(24, callbackFileResult.file.timestamp);149};150FileLoaderPluginCallbackTests.prototype.testFileOnLoadCssError = function() {151 var mockDOM = new jstestdriver.MockDOM();152 var head = mockDOM.createElement('head');153 var scriptLoader = this.createScriptLoader({}, mockDOM);154 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);155 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,156 stylesheetLoader);157 var file = new jstestdriver.FileSource('file.css', 84);158 var callbackCalled = false;159 var callbackFileResult = null;160 var callback = function(fileResult) {161 callbackCalled = true;162 callbackFileResult = fileResult;163 };164 fileLoaderPlugin.loadSource(file, callback);165 assertEquals(1, head.childNodes.length);166 var link = head.childNodes[0];167 link.onerror('it sucks', 'url', 90);168 link.onload();169 assertEquals('link', link.nodeName);170 assertEquals('text/css', link.type);171 assertEquals('stylesheet', link.rel);172 assertEquals('file.css', link.href);173 assertTrue(callbackCalled);174 assertNotNull(callbackFileResult);175 assertFalse(callbackFileResult.success);176 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);177 assertNotNull(callbackFileResult.file);178 assertEquals('file.css', callbackFileResult.file.fileSrc);179 assertEquals(84, callbackFileResult.file.timestamp);180};181FileLoaderPluginCallbackTests.prototype.testFileOnLoadCssWindowError = function() {182 var mockDOM = new jstestdriver.MockDOM();183 var head = mockDOM.createElement('head');184 var win = {};185 var scriptLoader = this.createScriptLoader(win, mockDOM);186 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);187 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,188 stylesheetLoader);189 var file = new jstestdriver.FileSource('file.css', 84);190 var callbackCalled = false;191 var callbackFileResult = null;192 var callback = function(fileResult) {193 callbackCalled = true;194 callbackFileResult = fileResult;195 };196 fileLoaderPlugin.loadSource(file, callback);197 assertNotNull(win.onerror);198 assertEquals(1, head.childNodes.length);199 var link = head.childNodes[0];200 win.onerror('it sucks', 'url', 90);201 link.onload();202 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);203 assertEquals('link', link.nodeName);204 assertEquals('text/css', link.type);205 assertEquals('stylesheet', link.rel);206 assertEquals('file.css', link.href);207 assertTrue(callbackCalled);208 assertNotNull(callbackFileResult);209 assertFalse(callbackFileResult.success);210 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);211 assertNotNull(callbackFileResult.file);212 assertEquals('file.css', callbackFileResult.file.fileSrc);213 assertEquals(84, callbackFileResult.file.timestamp);214};215var FileLoaderPluginTest = TestCase('FileLoaderPluginTest');216FileLoaderPluginTest.prototype.createScriptLoader = function(win, dom) {217 return new jstestdriver.plugins.ScriptLoader(win, dom, {218 updateLatestTestCase: function() {},219 removeTestCaseForFilename: function() {}220 }, jstestdriver.now);221};222FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJs = function() {223 var mockDOM = new jstestdriver.MockDOM();224 var head = mockDOM.createElement('head');225 var scriptLoader = this.createScriptLoader({}, mockDOM);226 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);227 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);228 var file = new jstestdriver.FileSource('file.js', 12);229 var callbackCalled = false;230 var callbackFileResult = null;231 var callback = function(fileResult) {232 callbackCalled = true;233 callbackFileResult = fileResult;234 };235 fileLoaderPlugin.loadSource(file, callback);236 assertEquals(1, head.childNodes.length);237 var script = head.childNodes[0];238 script.readyState = 'loaded';239 script.onreadystatechange();240 assertEquals('script', script.nodeName);241 assertEquals('text/javascript', script.type);242 assertEquals('file.js', script.src);243 assertTrue(callbackCalled);244 assertNotNull(callbackFileResult);245 assertTrue(callbackFileResult.success);246 assertEquals('', callbackFileResult.message);247 assertNotNull(callbackFileResult.file);248 assertEquals('file.js', callbackFileResult.file.fileSrc);249 assertEquals(12, callbackFileResult.file.timestamp);250};251FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJsError = function() {252 var mockDOM = new jstestdriver.MockDOM();253 var head = mockDOM.createElement('head');254 var scriptLoader = this.createScriptLoader({}, mockDOM);255 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);256 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);257 var file = new jstestdriver.FileSource('file.js', 42);258 var callbackCalled = false;259 var callbackFileResult = null;260 var callback = function(fileResult) {261 callbackCalled = true;262 callbackFileResult = fileResult;263 };264 fileLoaderPlugin.loadSource(file, callback);265 assertEquals(1, head.childNodes.length);266 var script = head.childNodes[0];267 script.onerror('msg', 'url', 42);268 script.readyState = 'loaded';269 script.onreadystatechange();270 assertEquals('script', script.nodeName);271 assertEquals('text/javascript', script.type);272 assertEquals('file.js', script.src);273 assertTrue(callbackCalled);274 assertNotNull(callbackFileResult);275 assertFalse(callbackFileResult.success);276 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);277 assertNotNull(callbackFileResult.file);278 assertEquals('file.js', callbackFileResult.file.fileSrc);279 assertEquals(42, callbackFileResult.file.timestamp);280};281FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJsWindowError = function() {282 var mockDOM = new jstestdriver.MockDOM();283 var head = mockDOM.createElement('head');284 var win = {};285 var scriptLoader = this.createScriptLoader(win, mockDOM);286 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);287 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);288 var file = new jstestdriver.FileSource('file.js', 42);289 var callbackCalled = false;290 var callbackFileResult = null;291 var callback = function(fileResult) {292 callbackCalled = true;293 callbackFileResult = fileResult;294 };295 fileLoaderPlugin.loadSource(file, callback);296 assertNotNull(win.onerror);297 assertEquals(1, head.childNodes.length);298 var script = head.childNodes[0];299 win.onerror('msg', 'url', 42);300 script.readyState = 'loaded';301 script.onreadystatechange();302 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);303 assertEquals('script', script.nodeName);304 assertEquals('text/javascript', script.type);305 assertEquals('file.js', script.src);306 assertTrue(callbackCalled);307 assertNotNull(callbackFileResult);308 assertFalse(callbackFileResult.success);309 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);310 assertNotNull(callbackFileResult.file);311 assertEquals('file.js', callbackFileResult.file.fileSrc);312 assertEquals(42, callbackFileResult.file.timestamp);313};314FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCss = function() {315 var mockDOM = new jstestdriver.MockDOM();316 var head = mockDOM.createElement('head');317 var scriptLoader = this.createScriptLoader({}, mockDOM);318 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);319 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);320 var file = new jstestdriver.FileSource('file.css', 24);321 var callbackCalled = false;322 var callbackFileResult = null;323 var callback = function(fileResult) {324 callbackCalled = true;325 callbackFileResult = fileResult;326 };327 fileLoaderPlugin.loadSource(file, callback);328 assertEquals(1, head.childNodes.length);329 var link = head.childNodes[0];330 link.readyState = 'loaded';331 link.onreadystatechange();332 assertEquals('link', link.nodeName);333 assertEquals('text/css', link.type);334 assertEquals('stylesheet', link.rel);335 assertEquals('file.css', link.href);336 assertTrue(callbackCalled);337 assertNotNull(callbackFileResult);338 assertTrue(callbackFileResult.success);339 assertEquals('', callbackFileResult.message);340 assertNotNull(callbackFileResult.file);341 assertEquals('file.css', callbackFileResult.file.fileSrc);342 assertEquals(24, callbackFileResult.file.timestamp);343};344FileLoaderPluginTest.prototype.testFileLoadCssOnLoadHack = function() {345 var mockDOM = new jstestdriver.MockDOM();346 var head = mockDOM.createElement('head');347 var scriptLoader = this.createScriptLoader({}, mockDOM);348 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, true);349 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);350 var file = new jstestdriver.FileSource('file.css', 24);351 var callbackCalled = 0;352 var callbackFileResult = null;353 var callback = function(fileResult) {354 callbackCalled++;355 callbackFileResult = fileResult;356 };357 fileLoaderPlugin.loadSource(file, callback);358 assertEquals(1, head.childNodes.length);359 var link = head.childNodes[0];360 assertEquals('link', link.nodeName);361 assertEquals('text/css', link.type);362 assertEquals('stylesheet', link.rel);363 assertEquals('file.css', link.href);364 assertEquals(1, callbackCalled);365 assertNotNull(callbackFileResult);366 assertTrue(callbackFileResult.success);367 assertEquals('', callbackFileResult.message);368 assertNotNull(callbackFileResult.file);369 assertEquals('file.css', callbackFileResult.file.fileSrc);370 assertEquals(24, callbackFileResult.file.timestamp);371};372FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCssError = function() {373 var mockDOM = new jstestdriver.MockDOM();374 var head = mockDOM.createElement('head');375 var scriptLoader = this.createScriptLoader({}, mockDOM);376 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);377 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);378 var file = new jstestdriver.FileSource('file.css', 84);379 var callbackCalled = false;380 var callbackFileResult = null;381 var callback = function(fileResult) {382 callbackCalled = true;383 callbackFileResult = fileResult;384 };385 fileLoaderPlugin.loadSource(file, callback);386 assertEquals(1, head.childNodes.length);387 var link = head.childNodes[0];388 link.onerror('it sucks', 'url', 90);389 link.readyState = 'loaded';390 link.onreadystatechange();391 assertEquals('link', link.nodeName);392 assertEquals('text/css', link.type);393 assertEquals('stylesheet', link.rel);394 assertEquals('file.css', link.href);395 assertTrue(callbackCalled);396 assertNotNull(callbackFileResult);397 assertFalse(callbackFileResult.success);398 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);399 assertNotNull(callbackFileResult.file);400 assertEquals('file.css', callbackFileResult.file.fileSrc);401 assertEquals(84, callbackFileResult.file.timestamp);402};403FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCssWindowError = function() {404 var mockDOM = new jstestdriver.MockDOM();405 var head = mockDOM.createElement('head');406 var win = {};407 var scriptLoader = this.createScriptLoader(win, mockDOM);408 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);409 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);410 var file = new jstestdriver.FileSource('file.css', 84);411 var callbackCalled = false;412 var callbackFileResult = null;413 var callback = function(fileResult) {414 callbackCalled = true;415 callbackFileResult = fileResult;416 };417 fileLoaderPlugin.loadSource(file, callback);418 assertNotNull(win.onerror);419 assertEquals(1, head.childNodes.length);420 var link = head.childNodes[0];421 win.onerror('it sucks', 'url', 90);422 link.readyState = 'loaded';423 link.onreadystatechange();424 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);425 assertEquals('link', link.nodeName);426 assertEquals('text/css', link.type);427 assertEquals('stylesheet', link.rel);428 assertEquals('file.css', link.href);429 assertTrue(callbackCalled);430 assertNotNull(callbackFileResult);431 assertFalse(callbackFileResult.success);432 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);433 assertNotNull(callbackFileResult.file);434 assertEquals('file.css', callbackFileResult.file.fileSrc);435 assertEquals(84, callbackFileResult.file.timestamp);...

Full Screen

Full Screen

local-notification-core.js

Source:local-notification-core.js Github

copy

Full Screen

1/*2 * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.3 *4 * @APPPLANT_LICENSE_HEADER_START@5 *6 * This file contains Original Code and/or Modifications of Original Code7 * as defined in and that are subject to the Apache License8 * Version 2.0 (the 'License'). You may not use this file except in9 * compliance with the License. Please obtain a copy of the License at10 * http://opensource.org/licenses/Apache-2.0/ and read it before using this11 * file.12 *13 * The Original Code and all software distributed under the License are14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.18 * Please see the License for the specific language governing rights and19 * limitations under the License.20 *21 * @APPPLANT_LICENSE_HEADER_END@22 */23var exec = require('cordova/exec');24/********25 * CORE *26 ********/27/**28 * Returns the default settings.29 *30 * @return {Object}31 */32exports.getDefaults = function () {33 return this._defaults;34};35/**36 * Overwrite default settings.37 *38 * @param {Object} defaults39 */40exports.setDefaults = function (newDefaults) {41 var defaults = this.getDefaults();42 for (var key in defaults) {43 if (newDefaults.hasOwnProperty(key)) {44 defaults[key] = newDefaults[key];45 }46 }47};48/**49 * Schedule a new local notification.50 *51 * @param {Object} msgs52 * The notification properties53 * @param {Function} callback54 * A function to be called after the notification has been canceled55 * @param {Object?} scope56 * The scope for the callback function57 * @param {Object?} args58 * skipPermission:true schedules the notifications immediatly without59 * registering or checking for permission60 */61exports.schedule = function (msgs, callback, scope, args) {62 var fn = function(granted) {63 if (!granted) return;64 var notifications = Array.isArray(msgs) ? msgs : [msgs];65 for (var i = 0; i < notifications.length; i++) {66 var notification = notifications[i];67 this.mergeWithDefaults(notification);68 this.convertProperties(notification);69 }70 this.exec('schedule', notifications, callback, scope);71 };72 if (args && args.skipPermission) {73 fn.call(this, true);74 } else {75 this.registerPermission(fn, this);76 }77};78/**79 * Update existing notifications specified by IDs in options.80 *81 * @param {Object} notifications82 * The notification properties to update83 * @param {Function} callback84 * A function to be called after the notification has been updated85 * @param {Object?} scope86 * The scope for the callback function87 * @param {Object?} args88 * skipPermission:true schedules the notifications immediatly without89 * registering or checking for permission90 */91exports.update = function (msgs, callback, scope, args) {92 var fn = function(granted) {93 if (!granted) return;94 var notifications = Array.isArray(msgs) ? msgs : [msgs];95 for (var i = 0; i < notifications.length; i++) {96 var notification = notifications[i];97 this.convertProperties(notification);98 }99 this.exec('update', notifications, callback, scope);100 };101 if (args && args.skipPermission) {102 fn.call(this, true);103 } else {104 this.registerPermission(fn, this);105 }106};107/**108 * Clear the specified notification.109 *110 * @param {String} id111 * The ID of the notification112 * @param {Function} callback113 * A function to be called after the notification has been cleared114 * @param {Object?} scope115 * The scope for the callback function116 */117exports.clear = function (ids, callback, scope) {118 ids = Array.isArray(ids) ? ids : [ids];119 ids = this.convertIds(ids);120 this.exec('clear', ids, callback, scope);121};122/**123 * Clear all previously sheduled notifications.124 *125 * @param {Function} callback126 * A function to be called after all notifications have been cleared127 * @param {Object?} scope128 * The scope for the callback function129 */130exports.clearAll = function (callback, scope) {131 this.exec('clearAll', null, callback, scope);132};133/**134 * Cancel the specified notifications.135 *136 * @param {String[]} ids137 * The IDs of the notifications138 * @param {Function} callback139 * A function to be called after the notifications has been canceled140 * @param {Object?} scope141 * The scope for the callback function142 */143exports.cancel = function (ids, callback, scope) {144 ids = Array.isArray(ids) ? ids : [ids];145 ids = this.convertIds(ids);146 this.exec('cancel', ids, callback, scope);147};148/**149 * Remove all previously registered notifications.150 *151 * @param {Function} callback152 * A function to be called after all notifications have been canceled153 * @param {Object?} scope154 * The scope for the callback function155 */156exports.cancelAll = function (callback, scope) {157 this.exec('cancelAll', null, callback, scope);158};159/**160 * Check if a notification with an ID is present.161 *162 * @param {String} id163 * The ID of the notification164 * @param {Function} callback165 * A callback function to be called with the list166 * @param {Object?} scope167 * The scope for the callback function168 */169exports.isPresent = function (id, callback, scope) {170 this.exec('isPresent', id || 0, callback, scope);171};172/**173 * Check if a notification with an ID is scheduled.174 *175 * @param {String} id176 * The ID of the notification177 * @param {Function} callback178 * A callback function to be called with the list179 * @param {Object?} scope180 * The scope for the callback function181 */182exports.isScheduled = function (id, callback, scope) {183 this.exec('isScheduled', id || 0, callback, scope);184};185/**186 * Check if a notification with an ID was triggered.187 *188 * @param {String} id189 * The ID of the notification190 * @param {Function} callback191 * A callback function to be called with the list192 * @param {Object?} scope193 * The scope for the callback function194 */195exports.isTriggered = function (id, callback, scope) {196 this.exec('isTriggered', id || 0, callback, scope);197};198/**199 * List all local notification IDs.200 *201 * @param {Function} callback202 * A callback function to be called with the list203 * @param {Object?} scope204 * The scope for the callback function205 */206exports.getAllIds = function (callback, scope) {207 this.exec('getAllIds', null, callback, scope);208};209/**210 * Alias for `getAllIds`.211 */212exports.getIds = function () {213 this.getAllIds.apply(this, arguments);214};215/**216 * List all scheduled notification IDs.217 *218 * @param {Function} callback219 * A callback function to be called with the list220 * @param {Object?} scope221 * The scope for the callback function222 */223exports.getScheduledIds = function (callback, scope) {224 this.exec('getScheduledIds', null, callback, scope);225};226/**227 * List all triggered notification IDs.228 *229 * @param {Function} callback230 * A callback function to be called with the list231 * @param {Object?} scope232 * The scope for the callback function233 */234exports.getTriggeredIds = function (callback, scope) {235 this.exec('getTriggeredIds', null, callback, scope);236};237/**238 * Property list for given local notifications.239 * If called without IDs, all notification will be returned.240 *241 * @param {Number[]?} ids242 * Set of notification IDs243 * @param {Function} callback244 * A callback function to be called with the list245 * @param {Object?} scope246 * The scope for the callback function247 */248exports.get = function () {249 var args = Array.apply(null, arguments);250 if (typeof args[0] == 'function') {251 args.unshift([]);252 }253 var ids = args[0],254 callback = args[1],255 scope = args[2];256 if (!Array.isArray(ids)) {257 this.exec('getSingle', Number(ids), callback, scope);258 return;259 }260 ids = this.convertIds(ids);261 this.exec('getAll', ids, callback, scope);262};263/**264 * Property list for all local notifications.265 *266 * @param {Function} callback267 * A callback function to be called with the list268 * @param {Object?} scope269 * The scope for the callback function270 */271exports.getAll = function (callback, scope) {272 this.exec('getAll', null, callback, scope);273};274/**275 * Property list for given scheduled notifications.276 * If called without IDs, all notification will be returned.277 *278 * @param {Number[]?} ids279 * Set of notification IDs280 * @param {Function} callback281 * A callback function to be called with the list282 * @param {Object?} scope283 * The scope for the callback function284 */285exports.getScheduled = function () {286 var args = Array.apply(null, arguments);287 if (typeof args[0] == 'function') {288 args.unshift([]);289 }290 var ids = args[0],291 callback = args[1],292 scope = args[2];293 if (!Array.isArray(ids)) {294 ids = [ids];295 }296 if (!Array.isArray(ids)) {297 this.exec('getSingleScheduled', Number(ids), callback, scope);298 return;299 }300 ids = this.convertIds(ids);301 this.exec('getScheduled', ids, callback, scope);302};303/**304 * Property list for all scheduled notifications.305 *306 * @param {Function} callback307 * A callback function to be called with the list308 * @param {Object?} scope309 * The scope for the callback function310 */311exports.getAllScheduled = function (callback, scope) {312 this.exec('getScheduled', null, callback, scope);313};314/**315 * Property list for given triggered notifications.316 * If called without IDs, all notification will be returned.317 *318 * @param {Number[]?} ids319 * Set of notification IDs320 * @param {Function} callback321 * A callback function to be called with the list322 * @param {Object?} scope323 * The scope for the callback function324 */325exports.getTriggered = function () {326 var args = Array.apply(null, arguments);327 if (typeof args[0] == 'function') {328 args.unshift([]);329 }330 var ids = args[0],331 callback = args[1],332 scope = args[2];333 if (!Array.isArray(ids)) {334 ids = [ids];335 }336 if (!Array.isArray(ids)) {337 this.exec('getSingleTriggered', Number(ids), callback, scope);338 return;339 }340 ids = this.convertIds(ids);341 this.exec('getTriggered', ids, callback, scope);342};343/**344 * Property list for all triggered notifications.345 *346 * @param {Function} callback347 * A callback function to be called with the list348 * @param {Object?} scope349 * The scope for the callback function350 */351exports.getAllTriggered = function (callback, scope) {352 this.exec('getTriggered', null, callback, scope);353};354/**355 * Informs if the app has the permission to show notifications.356 *357 * @param {Function} callback358 * The function to be exec as the callback359 * @param {Object?} scope360 * The callback function's scope361 */362exports.hasPermission = function (callback, scope) {363 var fn = this.createCallbackFn(callback, scope);364 if (device.platform != 'iOS') {365 fn(true);366 return;367 }368 exec(fn, null, 'LocalNotification', 'hasPermission', []);369};370/**371 * Register permission to show notifications if not already granted.372 *373 * @param {Function} callback374 * The function to be exec as the callback375 * @param {Object?} scope376 * The callback function's scope377 */378exports.registerPermission = function (callback, scope) {379 if (this._registered) {380 return this.hasPermission(callback, scope);381 } else {382 this._registered = true;383 }384 var fn = this.createCallbackFn(callback, scope);385 if (device.platform != 'iOS') {386 fn(true);387 return;388 }389 exec(fn, null, 'LocalNotification', 'registerPermission', []);390};391/**********392 * EVENTS *393 **********/394/**395 * Register callback for given event.396 *397 * @param {String} event398 * The event's name399 * @param {Function} callback400 * The function to be exec as callback401 * @param {Object?} scope402 * The callback function's scope403 */404exports.on = function (event, callback, scope) {405 if (typeof callback !== "function")406 return;407 if (!this._listener[event]) {408 this._listener[event] = [];409 }410 var item = [callback, scope || window];411 this._listener[event].push(item);412};413/**414 * Unregister callback for given event.415 *416 * @param {String} event417 * The event's name418 * @param {Function} callback419 * The function to be exec as callback420 */421exports.un = function (event, callback) {422 var listener = this._listener[event];423 if (!listener)424 return;425 for (var i = 0; i < listener.length; i++) {426 var fn = listener[i][0];427 if (fn == callback) {428 listener.splice(i, 1);429 break;430 }431 }...

Full Screen

Full Screen

Element.anim.js

Source:Element.anim.js Github

copy

Full Screen

1xdescribe("Ext.Element.anim", function() {2 var el,3 todoIt = Ext.isSafari4 ? xit : it;4 5 beforeEach(function() {6 el = Ext.getBody().createChild({7 id: 'testElement'8 });9 });10 11 afterEach(function() {12 el.destroy();13 });14 15 describe("callbacks", function() {16 var callback, called, scope, actualScope;17 18 beforeEach(function() {19 called = false;20 scope = {};21 callback = jasmine.createSpy('callback').andCallFake(function() {22 called = true;23 actualScope = this;24 });25 });26 27 afterEach(function() {28 actualScope = undefined;29 });30 describe("slideIn()", function() {31 beforeEach(function() {32 el.slideIn('t', {33 duration: 10,34 callback: callback,35 scope: scope36 });37 });38 39 todoIt("should run callback", function() {40 waitsFor(function() { return called; }, 1000, 'Callback to fire');41 42 runs(function() {43 expect(called).toBeTruthy();44 });45 });46 47 todoIt("should run callback in correct scope", function() {48 waitsFor(function() { return called; }, 1000, 'Callback to fire');49 50 runs(function() {51 expect(actualScope).toBe(scope);52 });53 });54 });55 56 describe("slideOut()", function() {57 beforeEach(function() {58 el.slideOut('t', {59 duration: 10,60 callback: callback,61 scope: scope62 });63 });64 65 todoIt("should run callback", function() {66 waitsFor(function() { return called; }, 1000, 'Callback to fire');67 68 runs(function() {69 expect(called).toBeTruthy();70 });71 });72 73 todoIt("should run callback in correct scope", function() {74 waitsFor(function() { return called; }, 1000, 'Callback to fire');75 76 runs(function() {77 expect(actualScope).toBe(scope);78 });79 });80 });81 82 describe("puff()", function() {83 beforeEach(function() {84 el.slideIn('t', {85 duration: 10,86 callback: callback,87 scope: scope88 });89 });90 91 todoIt("should run callback", function() {92 waitsFor(function() { return called; }, 1000, 'Callback to fire');93 94 runs(function() {95 expect(called).toBeTruthy();96 });97 });98 99 todoIt("should run callback in correct scope", function() {100 waitsFor(function() { return called; }, 1000, 'Callback to fire');101 102 runs(function() {103 expect(actualScope).toBe(scope);104 });105 });106 });107 108 describe("switchOff()", function() {109 beforeEach(function() {110 el.switchOff({111 duration: 10,112 callback: callback,113 scope: scope114 });115 });116 117 todoIt("should run callback", function() {118 waitsFor(function() { return called; }, 1000, 'Callback to fire');119 120 runs(function() {121 expect(called).toBeTruthy();122 });123 });124 125 todoIt("should run callback in correct scope", function() {126 waitsFor(function() { return called; }, 1000, 'Callback to fire');127 128 runs(function() {129 expect(actualScope).toBe(scope);130 });131 });132 });133 describe("frame()", function() {134 beforeEach(function() {135 el.frame('#ff0000', 1, {136 duration: 10,137 callback: callback,138 scope: scope139 });140 });141 142 todoIt("should run callback", function() {143 waitsFor(function() { return called; }, 1000, 'Callback to fire');144 145 runs(function() {146 expect(called).toBeTruthy();147 });148 });149 150 todoIt("should run callback in correct scope", function() {151 waitsFor(function() { return called; }, 1000, 'Callback to fire');152 153 runs(function() {154 expect(actualScope).toBe(scope);155 });156 });157 });158 159 describe("ghost()", function() {160 beforeEach(function() {161 el.ghost('b', {162 duration: 10,163 callback: callback,164 scope: scope165 });166 });167 168 todoIt("should run callback", function() {169 waitsFor(function() { return called; }, 1000, 'Callback to fire');170 171 runs(function() {172 expect(called).toBeTruthy();173 });174 });175 176 todoIt("should run callback in correct scope", function() {177 waitsFor(function() { return called; }, 1000, 'Callback to fire');178 179 runs(function() {180 expect(actualScope).toBe(scope);181 });182 });183 });184 185 describe("highlight()", function() {186 beforeEach(function() {187 el.highlight('#0000ff', {188 duration: 10,189 callback: callback,190 scope: scope191 });192 });193 194 todoIt("should run callback", function() {195 waitsFor(function() { return called; }, 1000, 'Callback to fire');196 197 runs(function() {198 expect(called).toBeTruthy();199 });200 });201 202 todoIt("should run callback in correct scope", function() {203 waitsFor(function() { return called; }, 1000, 'Callback to fire');204 205 runs(function() {206 expect(actualScope).toBe(scope);207 });208 });209 });210 211 describe("fadeIn()", function() {212 beforeEach(function() {213 el.fadeIn({214 duration: 10,215 callback: callback,216 scope: scope217 });218 });219 220 todoIt("should run callback", function() {221 waitsFor(function() { return called; }, 1000, 'Callback to fire');222 223 runs(function() {224 expect(called).toBeTruthy();225 });226 });227 228 todoIt("should run callback in correct scope", function() {229 waitsFor(function() { return called; }, 1000, 'Callback to fire');230 231 runs(function() {232 expect(actualScope).toBe(scope);233 });234 });235 });236 237 describe("fadeOut()", function() {238 beforeEach(function() {239 el.fadeOut({240 duration: 10,241 callback: callback,242 scope: scope243 });244 });245 246 todoIt("should run callback", function() {247 waitsFor(function() { return called; }, 1000, 'Callback to fire');248 249 runs(function() {250 expect(called).toBeTruthy();251 });252 });253 254 todoIt("should run callback in correct scope", function() {255 waitsFor(function() { return called; }, 1000, 'Callback to fire');256 257 runs(function() {258 expect(actualScope).toBe(scope);259 });260 });261 });262 263 describe("scale()", function() {264 beforeEach(function() {265 el.scale(100, 100, {266 duration: 10,267 callback: callback,268 scope: scope269 });270 });271 272 todoIt("should run callback", function() {273 waitsFor(function() { return called; }, 1000, 'Callback to fire');274 275 runs(function() {276 expect(called).toBeTruthy();277 });278 });279 280 todoIt("should run callback in correct scope", function() {281 waitsFor(function() { return called; }, 1000, 'Callback to fire');282 283 runs(function() {284 expect(actualScope).toBe(scope);285 });286 });287 });288 289 describe("shift()", function() {290 beforeEach(function() {291 el.shift({292 x: 200,293 y: 200,294 duration: 10,295 callback: callback,296 scope: scope297 });298 });299 300 todoIt("should run callback", function() {301 waitsFor(function() { return called; }, 1000, 'Callback to fire');302 303 runs(function() {304 expect(called).toBeTruthy();305 });306 });307 308 todoIt("should run callback in correct scope", function() {309 waitsFor(function() { return called; }, 1000, 'Callback to fire');310 311 runs(function() {312 expect(actualScope).toBe(scope);313 });314 });315 });316 });...

Full Screen

Full Screen

local-notification.js

Source:local-notification.js Github

copy

Full Screen

1/*2 * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.3 *4 * @APPPLANT_LICENSE_HEADER_START@5 *6 * This file contains Original Code and/or Modifications of Original Code7 * as defined in and that are subject to the Apache License8 * Version 2.0 (the 'License'). You may not use this file except in9 * compliance with the License. Please obtain a copy of the License at10 * http://opensource.org/licenses/Apache-2.0/ and read it before using this11 * file.12 *13 * The Original Code and all software distributed under the License are14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.18 * Please see the License for the specific language governing rights and19 * limitations under the License.20 *21 * @APPPLANT_LICENSE_HEADER_END@22 */23/*************24 * INTERFACE *25 *************/26/**27 * Returns the default settings.28 *29 * @return {Object}30 */31exports.getDefaults = function () {32 return this.core.getDefaults();33};34/**35 * Overwrite default settings.36 *37 * @param {Object} defaults38 */39exports.setDefaults = function (defaults) {40 this.core.setDefaults(defaults);41};42/**43 * Schedule a new local notification.44 *45 * @param {Object} notifications46 * The notification properties47 * @param {Function} callback48 * A function to be called after the notification has been canceled49 * @param {Object?} scope50 * The scope for the callback function51 * @param {Object?} args52 * skipPermission:true schedules the notifications immediatly without53 * registering or checking for permission54 */55exports.schedule = function (notifications, callback, scope, args) {56 this.core.schedule(notifications, callback, scope, args);57};58/**59 * Update existing notifications specified by IDs in options.60 *61 * @param {Object} notifications62 * The notification properties to update63 * @param {Function} callback64 * A function to be called after the notification has been updated65 * @param {Object?} scope66 * The scope for the callback function67 * @param {Object?} args68 * skipPermission:true schedules the notifications immediatly without69 * registering or checking for permission70 */71exports.update = function (notifications, callback, scope, args) {72 this.core.update(notifications, callback, scope, args);73};74/**75 * Clear the specified notification.76 *77 * @param {String} id78 * The ID of the notification79 * @param {Function} callback80 * A function to be called after the notification has been cleared81 * @param {Object?} scope82 * The scope for the callback function83 */84exports.clear = function (ids, callback, scope) {85 this.core.clear(ids, callback, scope);86};87/**88 * Clear all previously sheduled notifications.89 *90 * @param {Function} callback91 * A function to be called after all notifications have been cleared92 * @param {Object?} scope93 * The scope for the callback function94 */95exports.clearAll = function (callback, scope) {96 this.core.clearAll(callback, scope);97};98/**99 * Cancel the specified notifications.100 *101 * @param {String[]} ids102 * The IDs of the notifications103 * @param {Function} callback104 * A function to be called after the notifications has been canceled105 * @param {Object?} scope106 * The scope for the callback function107 */108exports.cancel = function (ids, callback, scope) {109 this.core.cancel(ids, callback, scope);110};111/**112 * Remove all previously registered notifications.113 *114 * @param {Function} callback115 * A function to be called after all notifications have been canceled116 * @param {Object?} scope117 * The scope for the callback function118 */119exports.cancelAll = function (callback, scope) {120 this.core.cancelAll(callback, scope);121};122/**123 * Check if a notification with an ID is present.124 *125 * @param {String} id126 * The ID of the notification127 * @param {Function} callback128 * A callback function to be called with the list129 * @param {Object?} scope130 * The scope for the callback function131 */132exports.isPresent = function (id, callback, scope) {133 this.core.isPresent(id, callback, scope);134};135/**136 * Check if a notification with an ID is scheduled.137 *138 * @param {String} id139 * The ID of the notification140 * @param {Function} callback141 * A callback function to be called with the list142 * @param {Object?} scope143 * The scope for the callback function144 */145exports.isScheduled = function (id, callback, scope) {146 this.core.isScheduled(id, callback, scope);147};148/**149 * Check if a notification with an ID was triggered.150 *151 * @param {String} id152 * The ID of the notification153 * @param {Function} callback154 * A callback function to be called with the list155 * @param {Object?} scope156 * The scope for the callback function157 */158exports.isTriggered = function (id, callback, scope) {159 this.core.isTriggered(id, callback, scope);160};161/**162 * List all local notification IDs.163 *164 * @param {Function} callback165 * A callback function to be called with the list166 * @param {Object?} scope167 * The scope for the callback function168 */169exports.getAllIds = function (callback, scope) {170 this.core.getAllIds(callback, scope);171};172/**173 * Alias for `getAllIds`.174 */175exports.getIds = function () {176 this.getAllIds.apply(this, arguments);177};178/**179 * List all scheduled notification IDs.180 *181 * @param {Function} callback182 * A callback function to be called with the list183 * @param {Object?} scope184 * The scope for the callback function185 */186exports.getScheduledIds = function (callback, scope) {187 this.core.getScheduledIds(callback, scope);188};189/**190 * List all triggered notification IDs.191 *192 * @param {Function} callback193 * A callback function to be called with the list194 * @param {Object?} scope195 * The scope for the callback function196 */197exports.getTriggeredIds = function (callback, scope) {198 this.core.getTriggeredIds(callback, scope);199};200/**201 * Property list for given local notifications.202 * If called without IDs, all notification will be returned.203 *204 * @param {Number[]?} ids205 * Set of notification IDs206 * @param {Function} callback207 * A callback function to be called with the list208 * @param {Object?} scope209 * The scope for the callback function210 */211exports.get = function () {212 this.core.get.apply(this.core, arguments);213};214/**215 * Property list for all local notifications.216 *217 * @param {Function} callback218 * A callback function to be called with the list219 * @param {Object?} scope220 * The scope for the callback function221 */222exports.getAll = function (callback, scope) {223 this.core.getAll(callback, scope);224};225/**226 * Property list for given scheduled notifications.227 * If called without IDs, all notification will be returned.228 *229 * @param {Number[]?} ids230 * Set of notification IDs231 * @param {Function} callback232 * A callback function to be called with the list233 * @param {Object?} scope234 * The scope for the callback function235 */236exports.getScheduled = function () {237 this.core.getScheduled.apply(this.core, arguments);238};239/**240 * Property list for all scheduled notifications.241 *242 * @param {Function} callback243 * A callback function to be called with the list244 * @param {Object?} scope245 * The scope for the callback function246 */247exports.getAllScheduled = function (callback, scope) {248 this.core.getAllScheduled(callback, scope);249};250/**251 * Property list for given triggered notifications.252 * If called without IDs, all notification will be returned.253 *254 * @param {Number[]?} ids255 * Set of notification IDs256 * @param {Function} callback257 * A callback function to be called with the list258 * @param {Object?} scope259 * The scope for the callback function260 */261exports.getTriggered = function () {262 this.core.getTriggered.apply(this.core, arguments);263};264/**265 * Property list for all triggered notifications.266 *267 * @param {Function} callback268 * A callback function to be called with the list269 * @param {Object?} scope270 * The scope for the callback function271 */272exports.getAllTriggered = function (callback, scope) {273 this.core.getAllTriggered(callback, scope);274};275/**276 * Informs if the app has the permission to show notifications.277 *278 * @param {Function} callback279 * The function to be exec as the callback280 * @param {Object?} scope281 * The callback function's scope282 */283exports.hasPermission = function (callback, scope) {284 this.core.hasPermission(callback, scope);285};286/**287 * Register permission to show notifications if not already granted.288 *289 * @param {Function} callback290 * The function to be exec as the callback291 * @param {Object?} scope292 * The callback function's scope293 */294exports.registerPermission = function (callback, scope) {295 this.core.registerPermission(callback, scope);296};297/****************298 * DEPRECATIONS *299 ****************/300/**301 * Schedule a new local notification.302 */303exports.add = function () {304 console.warn('Depreated: Please use `notification.local.schedule` instead.');305 this.schedule.apply(this, arguments);306};307/**308 * Register permission to show notifications309 * if not already granted.310 */311exports.promptForPermission = function () {312 console.warn('Depreated: Please use `notification.local.registerPermission` instead.');313 this.registerPermission.apply(this, arguments);314};315/**********316 * EVENTS *317 **********/318/**319 * Register callback for given event.320 *321 * @param {String} event322 * The event's name323 * @param {Function} callback324 * The function to be exec as callback325 * @param {Object?} scope326 * The callback function's scope327 */328exports.on = function (event, callback, scope) {329 this.core.on(event, callback, scope);330};331/**332 * Unregister callback for given event.333 *334 * @param {String} event335 * The event's name336 * @param {Function} callback337 * The function to be exec as callback338 */339exports.un = function (event, callback) {340 this.core.un(event, callback, scope);...

Full Screen

Full Screen

step.service.js

Source:step.service.js Github

copy

Full Screen

...31 function getVerificationCode(postData,callback){32 $http.post(webservices.verifytutormobile, postData)33 .success(function (result) {34 if (result.status === 200) {35 callback(true);36 } else {37 callback(false);38 }39 })40 .error(function () {41 callback(false);42 });43 44 }45 46 function saveSteps(postData,callback){47 $http.post(webservices.saveSteps,postData)48 .success(function (result) {49 if (result.status === 200) {50 callback(true);51 } else {52 callback(false);53 }54 })55 .error(function () {56 callback(false);57 });58 59 }60 61 function savePassport(postData, callback) {62 $http.post(webservices.updatetutordetail, postData)63 .success(function (result) {64 if (result.status === 200) {65 callback(true);66 } else {67 callback(false);68 }69 })70 .error(function () {71 callback(false);72 });7374 }75 76 function checkVerificationCode(postData, callback) {77 $http.post(webservices.updatetutormobile, postData)78 .success(function (result) {79 if (result.status === 200) {80 callback(true);81 } else {82 callback(false);83 }84 })85 .error(function () {86 callback(false);87 });88 }89 90 function resendVerificationCode(postData, callback) {91 $http.post(webservices.resendverificationcode, postData)92 .success(function (result) {93 if (result.status === 200) {94 callback(true);95 } else {96 callback(false);97 }98 })99 .error(function () {100 callback(false);101 });102 }103 104 /*105 * @desc updates refund policy for tutor.106 */107 function saveRefundPolicy(postData, callback) {108 $http.post(webservices.updatetutordetail, postData)109 .success(function (result) {110 if (result.status === 200) {111 callback(true);112 } else {113 callback(false);114 }115 })116 .error(function () {117 callback(false);118 });119 }120121 /*122 * @desc updates payout frequency for tutor.123 */124 function savePayoutFrequency(postData, callback) {125 $http.post(webservices.updatetutordetail, postData)126 .success(function (result) {127 if (result.status === 200) {128 callback(true);129 } else {130 callback(false);131 }132 })133 .error(function () {134 callback(false);135 });136 }137 138 /*139 * @desc - get locations data140 */141 function getLocationsData(callback) {142 $http.get(webservices.getlocationsdata)143 .success(function (result) {144 if (result.status === 200) {145 callback(result.data);146 } else {147 callback(false);148 }149 })150 .error(function () {151 callback(false);152 });153 }154155 /*156 * @desc - get subjects data157 */158 function getSubjectsData(callback) {159 $http.get(webservices.getsubjectsdata)160 .success(function (result) {161 if (result.status === 200) {162 callback(result.data);163 } else {164 callback(result.msg);165 }166 })167 .error(function () {168 callback(false);169 });170 }171172 function getBanksData(callback) {173 $http.get(webservices.getbanksdata)174 .success(function (result) {175 if (result.status === 200) {176 callback(result.data);177 } else {178 callback(result.msg);179 }180 })181 .error(function () {182 callback(false);183 });184 }185186 function removeAcademic(postData,callback){187 $http.post(webservices.removeAcademics, postData)188 .success(function (result) {189 if (result.status === 200) {190 callback(true);191 } else {192 callback(false);193 }194 })195 .error(function () {196 callback(false);197 });198199 }200201202 function removeOtherDocs(postData, callback) {203 $http.post(webservices.removeOtherDocs, postData)204 .success(function (result) {205 if (result.status === 200) {206 callback(true);207 } else {208 callback(false);209 }210 })211 .error(function () {212 callback(false);213 });214 }215216 function removeSupportDocs(postData, callback) {217 $http.post(webservices.removeSupportDocs, postData)218 .success(function (result) {219 if (result.status === 200) {220 callback(true);221 } else {222 callback(false);223 }224 })225 .error(function () {226 callback(false);227 });228 }229230 function saveSubjects(postData, callback) {231 $http.post(webservices.updatetutorsubjects, postData)232 .success(function (result) {233 if (result.status === 200) {234 callback(true);235 } else {236 callback(false);237 }238 })239 .error(function () {240 callback(false);241 });242 }243244 function getInstitutionsData(callback) {245 $http.get(webservices.getinstitutionsdata)246 .success(function (result) {247 if (result.status === 200) {248 callback(result.data);249 } else {250 callback(result.msg);251 }252 })253 .error(function () {254 callback(false);255 });256 } 257 } ...

Full Screen

Full Screen

CallbackPoolTest.js

Source:CallbackPoolTest.js Github

copy

Full Screen

...21 */22callbackPoolTest.prototype.testCallbackCalledBeforePoolIsActive = function() {23 var complete = false;24 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {25 callback();26 }, {}, function(errors) {27 complete = true;28 });29 var callbackA = pool.add(function() {});30 assertFalse(pool.active_);31 callbackA();32 assertFalse(pool.active_);33 assertFalse(complete);34};35/**36 * Tests #activate(), added to fix Issue 140.37 * @bug 14038 */39callbackPoolTest.prototype.testActivate = function() {40 var complete = false;41 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {42 callback();43 }, {}, function(errors) {44 complete = true;45 });46 var poolWasActive = false;47 var callbackA = pool.add(function() {poolWasActive = pool.active_;});48 assertFalse(pool.active_);49 pool.activate();50 assertTrue(pool.active_);51 callbackA();52 assertTrue(poolWasActive);53 assertFalse(pool.active_);54 assertTrue(complete);55};56callbackPoolTest.prototype.testAdd = function() {57 var complete = false;58 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {59 callback();60 }, {}, function(errors) {61 assertEquals(0, errors.length);62 complete = true;63 });64 assertEquals(0, pool.count());65 var callbackA = pool.add(function() {});66 assertEquals(1, pool.count());67 assertFalse(complete);68 var callbackB = pool.add(function() {});69 assertEquals(2, pool.count());70 assertFalse(complete);71 pool.activate();72 callbackA();73 assertEquals(1, pool.count());74 assertFalse(complete);75 callbackB();76 assertEquals(0, pool.count());77 assertTrue(complete);78};79callbackPoolTest.prototype.testScopeIsNotWindow = function() {80 var complete = false;81 var testCase = {};82 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {83 callback();84 }, testCase, function(errors) {85 assertEquals(0, errors.length);86 complete = true;87 });88 assertEquals(0, pool.count());89 var callbackAScope;90 var callbackA = pool.add(function() {callbackAScope = this;});91 assertEquals(1, pool.count());92 assertFalse(complete);93 pool.activate();94 callbackA();95 assertEquals(0, pool.count());96 assertTrue(complete);97 assertFalse('window === callbackAScope', window === callbackAScope);98 assertTrue('testCase === callbackAScope', testCase === callbackAScope);99};100callbackPoolTest.prototype.testAddWithArguments = function() {101 var complete = false;102 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {103 callback();104 }, {}, function(errors) {105 assertEquals(0, errors.length);106 complete = true;107 });108 assertEquals(0, pool.count());109 var capturedOne;110 var capturedTwo;111 var callbackA = pool.add(function(one, two) {112 capturedOne = one;113 capturedTwo = two;114 });115 assertEquals(1, pool.count());116 assertFalse(complete);117 var capturedThree;118 var callbackB = pool.add(function(three) {119 capturedThree = three;120 });121 assertEquals(2, pool.count());122 assertFalse(complete);123 assertUndefined(capturedOne);124 assertUndefined(capturedTwo);125 assertUndefined(capturedThree);126 pool.activate();127 callbackA(1, 2);128 assertEquals(1, pool.count());129 assertEquals(1, capturedOne);130 assertEquals(2, capturedTwo);131 assertFalse(complete);132 callbackB(3);133 assertEquals(0, pool.count());134 assertEquals(3, capturedThree);135 assertTrue(complete);136};137callbackPoolTest.prototype.testAddRepeated = function() {138 var complete = false;139 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {140 callback();141 }, {}, function(errors) {142 assertEquals(0, errors.length);143 complete = true;144 });145 assertEquals(0, pool.count());146 var callbackA = pool.add(function() {}, 2);147 assertEquals(2, pool.count());148 assertFalse(complete);149 pool.activate();150 callbackA();151 assertEquals(1, pool.count());152 assertFalse(complete);153 callbackA();154 assertEquals(0, pool.count());155 assertTrue(complete);156};157callbackPoolTest.prototype.testAddNested = function() {158 var complete = false;159 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {160 callback();161 }, {}, function(errors) {162 assertEquals(0, errors.length);163 complete = true;164 });165 assertEquals(0, pool.count());166 var callbackA = pool.add(function() {return pool.add(function() {});});167 assertEquals(1, pool.count());168 assertFalse(complete);169 pool.activate();170 var callbackB = callbackA();171 assertEquals(1, pool.count());172 assertFalse(complete);173 callbackB();174 assertEquals(0, pool.count());175 assertTrue(complete);176};177callbackPoolTest.prototype.testAddWithErrors = function() {178 var complete = false;179 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {180 callback();181 }, {}, function(errors) {182 assertEquals(1, errors.length);183 complete = true;184 });185 assertEquals(0, pool.count());186 var callbackA = pool.add(function() {throw 'error';});187 assertEquals(1, pool.count());188 assertFalse(complete);189 pool.activate();190 try {191 callbackA();192 } catch (expected) {}193 assertEquals(0, pool.count());194 assertTrue(complete);195};196callbackPoolTest.prototype.testAddWithTimeout = function() {197 var complete = false;198 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {199 callback();200 }, {}, function(errors) {201 assertEquals(1, errors.length);202 assertTrue('Error should contain step description.',203 errors[0].message.indexOf('Step 1.') > -1)204 complete = true;205 }, 'Step 1.', false /* pauseForHuman */, function() {206 // Force callbacks to expire immediately when armed207 return new jstestdriver.plugins.async.TestSafeCallbackBuilder(function(callback) {208 callback();209 })210 });211 assertEquals(0, pool.count());212 var callbackA = pool.add(function() {});213 assertEquals(0, pool.count());214 assertFalse(complete);215 pool.activate();216 assertEquals(0, pool.count());217 assertTrue(complete);218};219callbackPoolTest.prototype.testAddWithTimeoutDisabledForDebugging = function() {220 var complete = false;221 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {222 callback();223 }, {}, function(errors) {224 assertEquals(0, errors.length);225 complete = true;226 }, '', true /* pauseForHuman */, function() {227 // Force callbacks to expire immediately when armed228 return new jstestdriver.plugins.async.TestSafeCallbackBuilder(function(callback) {229 callback();230 })231 });232 assertEquals(0, pool.count());233 var callbackA = pool.add(function() {});234 assertEquals(1, pool.count());235 assertFalse(complete);236 pool.activate();237 assertEquals(1, pool.count());238 assertFalse(complete);239 callbackA();240 assertEquals(0, pool.count());241 assertTrue(complete);242};243callbackPoolTest.prototype.testAddErrback = function() {244 var complete = false;245 var pool = new jstestdriver.plugins.async.CallbackPool(function(callback) {246 callback();247 }, {}, function(errors) {248 assertEquals(1, errors.length);249 complete = true;250 });251 assertEquals(0, pool.count());252 var errback = pool.addErrback('oops');253 assertEquals(0, pool.count());254 assertFalse(complete);255 errback();256 pool.activate();257 assertEquals(0, pool.count());258 assertTrue(complete);...

Full Screen

Full Screen

extenders.js

Source:extenders.js Github

copy

Full Screen

1module.exports = function(s,config){2 ////// USER //////3 s.onSocketAuthenticationExtensions = []4 s.onSocketAuthentication = function(callback){5 s.onSocketAuthenticationExtensions.push(callback)6 }7 //8 s.onUserLogExtensions = []9 s.onUserLog = function(callback){10 s.onUserLogExtensions.push(callback)11 }12 //13 s.loadGroupExtensions = []14 s.loadGroupExtender = function(callback){15 s.loadGroupExtensions.push(callback)16 }17 //18 s.loadGroupAppExtensions = []19 s.loadGroupAppExtender = function(callback){20 s.loadGroupAppExtensions.push(callback)21 }22 //23 s.unloadGroupAppExtensions = []24 s.unloadGroupAppExtender = function(callback){25 s.unloadGroupAppExtensions.push(callback)26 }27 //28 s.cloudDisksLoaded = []29 s.cloudDisksLoader = function(storageType){30 s.cloudDisksLoaded.push(storageType)31 }32 //33 s.onAccountSaveExtensions = []34 s.onAccountSave = function(callback){35 s.onAccountSaveExtensions.push(callback)36 }37 //38 s.beforeAccountSaveExtensions = []39 s.beforeAccountSave = function(callback){40 s.beforeAccountSaveExtensions.push(callback)41 }42 //43 s.onTwoFactorAuthCodeNotificationExtensions = []44 s.onTwoFactorAuthCodeNotification = function(callback){45 s.onTwoFactorAuthCodeNotificationExtensions.push(callback)46 }47 //48 s.onStalePurgeLockExtensions = []49 s.onStalePurgeLock = function(callback){50 s.onStalePurgeLockExtensions.push(callback)51 }52 //53 s.cloudDiskUseStartupExtensions = {}54 s.cloudDiskUseOnGetVideoDataExtensions = {}55 ////// EVENTS //////56 s.onEventTriggerExtensions = []57 s.onEventTrigger = function(callback){58 s.onEventTriggerExtensions.push(callback)59 }60 s.onEventTriggerBeforeFilterExtensions = []61 s.onEventTriggerBeforeFilter = function(callback){62 s.onEventTriggerBeforeFilterExtensions.push(callback)63 }64 s.onFilterEventExtensions = []65 s.onFilterEvent = function(callback){66 s.onFilterEventExtensions.push(callback)67 }68 ////// MONITOR //////69 s.onMonitorInitExtensions = []70 s.onMonitorInit = function(callback){71 s.onMonitorInitExtensions.push(callback)72 }73 //74 s.onMonitorStartExtensions = []75 s.onMonitorStart = function(callback){76 s.onMonitorStartExtensions.push(callback)77 }78 //79 s.onMonitorStopExtensions = []80 s.onMonitorStop = function(callback){81 s.onMonitorStopExtensions.push(callback)82 }83 //84 s.onMonitorSaveExtensions = []85 s.onMonitorSave = function(callback){86 s.onMonitorSaveExtensions.push(callback)87 }88 //89 s.onMonitorUnexpectedExitExtensions = []90 s.onMonitorUnexpectedExit = function(callback){91 s.onMonitorUnexpectedExitExtensions.push(callback)92 }93 //94 s.onDetectorNoTriggerTimeoutExtensions = []95 s.onDetectorNoTriggerTimeout = function(callback){96 s.onDetectorNoTriggerTimeoutExtensions.push(callback)97 }98 //99 s.onFfmpegCameraStringCreationExtensions = []100 s.onFfmpegCameraStringCreation = function(callback){101 s.onFfmpegCameraStringCreationExtensions.push(callback)102 }103 //104 s.onMonitorPingFailedExtensions = []105 s.onMonitorPingFailed = function(callback){106 s.onMonitorPingFailedExtensions.push(callback)107 }108 //109 s.onMonitorDiedExtensions = []110 s.onMonitorDied = function(callback){111 s.onMonitorDiedExtensions.push(callback)112 }113 ///////// SYSTEM ////////114 s.onProcessReadyExtensions = []115 s.onProcessReady = function(callback){116 s.onProcessReadyExtensions.push(callback)117 }118 //119 s.onProcessExitExtensions = []120 s.onProcessExit = function(callback){121 s.onProcessExitExtensions.push(callback)122 }123 //124 s.onBeforeDatabaseLoadExtensions = []125 s.onBeforeDatabaseLoad = function(callback){126 s.onBeforeDatabaseLoadExtensions.push(callback)127 }128 //129 s.onFFmpegLoadedExtensions = []130 s.onFFmpegLoaded = function(callback){131 s.onFFmpegLoadedExtensions.push(callback)132 }133 //134 s.beforeMonitorsLoadedOnStartupExtensions = []135 s.beforeMonitorsLoadedOnStartup = function(callback){136 s.beforeMonitorsLoadedOnStartupExtensions.push(callback)137 }138 //139 s.onWebSocketConnectionExtensions = []140 s.onWebSocketConnection = function(callback){141 s.onWebSocketConnectionExtensions.push(callback)142 }143 //144 s.onWebSocketDisconnectionExtensions = []145 s.onWebSocketDisconnection = function(callback){146 s.onWebSocketDisconnectionExtensions.push(callback)147 }148 //149 s.onWebsocketMessageSendExtensions = []150 s.onWebsocketMessageSend = function(callback){151 s.onWebsocketMessageSendExtensions.push(callback)152 }153 //154 s.onGetCpuUsageExtensions = []155 s.onGetCpuUsage = function(callback){156 s.onGetCpuUsageExtensions.push(callback)157 }158 //159 s.onGetRamUsageExtensions = []160 s.onGetRamUsage = function(callback){161 s.onGetRamUsageExtensions.push(callback)162 }163 //164 s.onSubscriptionCheckExtensions = []165 s.onSubscriptionCheck = function(callback){166 s.onSubscriptionCheckExtensions.push(callback)167 }168 //169 /////// VIDEOS ////////170 s.insertCompletedVideoExtensions = []171 s.insertCompletedVideoExtender = function(callback){172 s.insertCompletedVideoExtensions.push(callback)173 }174 s.onBeforeInsertCompletedVideoExtensions = []175 s.onBeforeInsertCompletedVideo = function(callback){176 s.onBeforeInsertCompletedVideoExtensions.push(callback)177 }178 /////// TIMELAPSE ////////179 s.onInsertTimelapseFrameExtensions = []180 s.onInsertTimelapseFrame = function(callback){181 s.onInsertTimelapseFrameExtensions.push(callback)182 }...

Full Screen

Full Screen

exec.js

Source:exec.js Github

copy

Full Screen

1/*2 *3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 *20*/21/*jslint sloppy:true, plusplus:true*/22/*global require, module, console */23var cordova = require('cordova');24var execProxy = require('cordova/exec/proxy');25/**26 * Execute a cordova command. It is up to the native side whether this action27 * is synchronous or asynchronous. The native side can return:28 * Synchronous: PluginResult object as a JSON string29 * Asynchronous: Empty string ""30 * If async, the native side will cordova.callbackSuccess or cordova.callbackError,31 * depending upon the result of the action.32 *33 * @param {Function} success The success callback34 * @param {Function} fail The fail callback35 * @param {String} service The name of the service to use36 * @param {String} action Action to be run in cordova37 * @param {String[]} [args] Zero or more arguments to pass to the method38 */39module.exports = function (success, fail, service, action, args) {40 var proxy = execProxy.get(service, action);41 args = args || [];42 if (proxy) {43 44 var callbackId = service + cordova.callbackId++;45 46 if (typeof success === "function" || typeof fail === "function") {47 cordova.callbacks[callbackId] = {success: success, fail: fail};48 }49 try {50 51 // callbackOptions param represents additional optional parameters command could pass back, like keepCallback or52 // custom callbackId, for example {callbackId: id, keepCallback: true, status: cordova.callbackStatus.JSON_EXCEPTION }53 var onSuccess = function (result, callbackOptions) {54 callbackOptions = callbackOptions || {};55 var callbackStatus;56 // covering both undefined and null.57 // strict null comparison was causing callbackStatus to be undefined58 // and then no callback was called because of the check in cordova.callbackFromNative59 // see CB-8996 Mobilespec app hang on windows60 if (callbackOptions.status !== undefined && callbackOptions.status !== null) {61 callbackStatus = callbackOptions.status;62 }63 else {64 callbackStatus = cordova.callbackStatus.OK;65 }66 cordova.callbackSuccess(callbackOptions.callbackId || callbackId,67 {68 status: callbackStatus,69 message: result,70 keepCallback: callbackOptions.keepCallback || false71 });72 };73 var onError = function (err, callbackOptions) {74 callbackOptions = callbackOptions || {};75 var callbackStatus;76 // covering both undefined and null.77 // strict null comparison was causing callbackStatus to be undefined78 // and then no callback was called because of the check in cordova.callbackFromNative79 // note: status can be 080 if (callbackOptions.status !== undefined && callbackOptions.status !== null) {81 callbackStatus = callbackOptions.status;82 }83 else {84 callbackStatus = cordova.callbackStatus.OK;85 }86 cordova.callbackError(callbackOptions.callbackId || callbackId,87 {88 status: callbackStatus,89 message: err,90 keepCallback: callbackOptions.keepCallback || false91 });92 };93 proxy(onSuccess, onError, args);94 } catch (e) {95 console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e);96 }97 } else {98 console.log("Error: exec proxy not found for :: " + service + " :: " + action);99 100 if(typeof fail === "function" ) {101 fail("Missing Command Error");102 }103 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from '@testing-library/react-hooks'2import { useCounter } from './useCounter'3test('should increment counter', () => {4 const { result } = renderHook(() => useCounter())5 act(() => {6 result.current.increment()7 })8 expect(result.current.count).toBe(1)9})10export const useCounter = () => {11 const [count, setCount] = useState(0)12 const increment = () => {13 setCount(count + 1)14 }15 return {16 }17}18import React from 'react'19import { create } from 'react-test-renderer'20import App from './App'21describe('App component', () => {22 test('it matches the snapshot', () => {23 const component = create(<App />)24 expect(component.toJSON()).toMatchSnapshot()25 })26})27import React from 'react'28import { useCounter } from './useCounter'29const App = () => {30 const { count, increment } = useCounter()31 return (32 <p>{count}</p>33 <button onClick={increment}>Increment</button>34}35body {36 background-color: #282c34;37 color: white;38 text-align: center;39 font-family: 'Courier New', Courier, monospace;40}41import React from 'react'42import { create } from 'react-test-renderer'43import App from './App'44describe('App component', () => {45 test('it matches the snapshot', () => {46 const component = create(<App />)47 expect(component.toJSON()).toMatchSnapshot()48 })49})50import React from 'react'51import { useCounter } from './useCounter'52const App = () => {53 const { count, increment } = useCounter()54 return (55 <p>{count}</p>56 <button onClick={increment}>Increment</button>57}58body {59 background-color: #282c34;60 color: white;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks'2import { renderHook } from '@testing-library/react-hooks'3import { renderHook } from '@testing-library/react-hooks'4import { renderHook } from '@testing-library/react-hooks'5import { renderHook } from '@testing-library/react-hooks'6import { renderHook } from '@testing-library/react-hooks'7import { renderHook } from '@testing-library/react-hooks'8import { renderHook } from '@testing-library/react-hooks'9import { renderHook } from '@testing-library/react-hooks'10import { renderHook } from '@testing-library/react-hooks'11import { renderHook } from '@testing-library/react-hooks'12import { renderHook } from '@testing-library/react-hooks'13import { renderHook } from '@testing-library/react-hooks'14import { renderHook } from '@testing-library/react-hooks'15import { renderHook } from '@testing-library/react-hooks'16import { renderHook

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks'2import { useCounter } from './useCounter'3test('useCounter', () => {4 const { result } = renderHook(() => useCounter())5 expect(result.current.count).toBe(0)6 expect(typeof result.current.increment).toBe('function')7 expect(typeof result.current.decrement).toBe('function')8})9import { useState } from 'react'10export const useCounter = () => {11 const [count, setCount] = useState(0)12 const increment = () => setCount(count + 1)13 const decrement = () => setCount(count - 1)14 return {15 }16}17import { renderHook, act } from '@testing-library/react-hooks'18import { useCounter } from './useCounter'19test('useCounter', () => {20 const { result } = renderHook(() => useCounter())21 expect(result.current.count).toBe(0)22 expect(typeof result.current.increment).toBe('function')23 expect(typeof result.current.decrement).toBe('function')24 act(() => result.current.increment())25 expect(result.current.count).toBe(1)26 act(() => result.current.decrement())27 expect(result.current.count).toBe(0)28})29import { renderHook } from '@testing-library/react-hooks'30import { useCounter } from './useCounter'31test('useCounter', async () => {32 const { result, waitForNextUpdate } = renderHook(() => useCounter())33 expect(result.current.count).toBe(0)34 expect(typeof result.current.increment).toBe('function')35 expect(typeof result.current.decrement).toBe('function')36 result.current.increment()37 await waitForNextUpdate()38 expect(result.current.count).toBe(1)39 result.current.decrement()40 await waitForNextUpdate()41 expect(result.current.count).toBe(0)42})43import { useState } from 'react'44export const useCounter = () => {45 const [count, setCount] = useState(0)46 const increment = () => setCount(count + 1)47 const decrement = () => setCount(count - 1)48 return {49 }50}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks';2import { useFetch } from './useFetch';3describe('useFetch', () => {4 it('should fetch data', async () => {5 const { result, waitForNextUpdate } = renderHook(() => useFetch());6 await waitForNextUpdate();7 expect(result.current).toEqual('data');8 });9});10export const useFetch = () => {11 const [data, setData] = useState(null);12 useEffect(() => {13 .then(response => response.json())14 .then(json => setData(json.title));15 }, []);16 return data;17};18export const useFetch = () => {19 const [data, setData] = useState(null);20 useEffect(() => {21 .then(response => response.json())22 .then(json => setData(json.title));23 }, []);24 return data;25};26export const useFetch = () => {27 const [data, setData] = useState(null);28 useEffect(() => {29 .then(response => response.json())30 .then(json => setData(json.title));31 }, []);32 return data;33};34export const useFetch = () => {35 const [data, setData] = useState(null);36 useEffect(() => {37 .then(response => response.json())38 .then(json => setData(json.title));39 }, []);40 return data;41};42export const useFetch = () => {43 const [data, setData] = useState(null);44 useEffect(() => {45 .then(response => response.json())46 .then(json => setData(json.title));47 }, []);48 return data;49};50export const useFetch = () => {51 const [data, setData] = useState(null);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks'2import { useFetch } from './useFetch'3test('should return data', async () => {4 const { result, waitForNextUpdate } = renderHook(() =>5 await waitForNextUpdate()6 expect(result.current.data.title).toBe('delectus aut autem')7})8import { renderHook } from '@testing-library/react-hooks'9import { useFetch } from './useFetch'10test('should return data', async () => {11 const { result, waitForNextUpdate } = renderHook(() =>12 await waitForNextUpdate()13 expect(result.current.data.title).toBe('delectus aut autem')14})15import { renderHook } from '@testing-library/react-hooks'16import { useFetch } from './useFetch'17test('should return data', () => {18 const { result, waitForNextUpdate } = renderHook(() =>19 return waitForNextUpdate().then(() => {20 expect(result.current.data.title).toBe('delectus aut autem')21 })22})23import React from 'react';24import { render, fireEvent, waitForElement } from 'react-testing-library';25import 'jest-dom/extend-expect';26import { MemoryRouter } from 'react-router-dom';27import CreatePost from '../components/CreatePost';28describe('CreatePost', () => {29 it('should render the form', () => {30 const { getByText, getByPlaceholderText } =

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks';2import { useFetch } from './useFetch';3test('should useFetch hook', async () => {4 await waitForNextUpdate();5 const { data, loading, error } = result.current;6 expect(data.length).toBe(20);7 expect(loading).toBe(false);8 expect(error).toBe(null);9});10import { useState, useEffect, useRef } from 'react';11export const useFetch = (url) => {12 const isMounted = useRef(true);13 const [state, setState] = useState({ data: null, loading: true, error: null });14 useEffect(() => {15 return () => {16 isMounted.current = false;17 };18 }, []);19 useEffect(() => {20 setState({ data: null, loading: true, error: null });21 fetch(url)22 .then((resp) => resp.json())23 .then((data) => {24 if (isMounted.current) {25 setState({ loading: false, error: null, data });26 }27 });28 }, [url]);29 return state;30};31import { useState } from 'react';32export const useCounter = (initialState = 10) => {33 const [counter, setCounter] = useState(initialState);34 const increment = () => {35 setCounter(counter + 1);36 };37 const decrement = () => {38 setCounter(counter - 1);39 };40 const reset = () => {41 setCounter(initialState);42 };43 return {44 };45};46import { useState, useEffect, useRef } from 'react';47export const useFetch = (url) => {48 const isMounted = useRef(true);49 const [state, setState] = useState({ data: null, loading: true, error: null });50 useEffect(() => {51 return () => {52 isMounted.current = false;53 };54 }, []);55 useEffect(() => {56 setState({ data: null, loading: true, error: null });57 fetch(url)58 .then((resp) => resp.json())59 .then((data) => {60 if (is

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook, act } from "@testing-library/react-hooks";2import { useCounter } from "./counter";3describe("useCounter", () => {4 it("should call the callback", () => {5 const { result } = renderHook(() => useCounter());6 expect(result.current.count).toBe(0);7 act(() => {8 result.current.increment();9 });10 expect(result.current.count).toBe(1);11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { renderHook } from '@testing-library/react-hooks'2import { useFetch } from './useFetch'3it('should return data from an API', async () => {4 await waitForNextUpdate()5 expect(result.current.data.title).toBe('sunt aut facere repellat provident occaecati excepturi optio reprehenderit')6})7import { useState, useEffect } from 'react'8import axios from 'axios'9export function useFetch(url) {10 const [data, setData] = useState(null)11 const [error, setError] = useState(null)12 useEffect(() => {13 const fetchData = async () => {14 try {15 const response = await axios(url)16 setData(response.data)17 } catch (error) {18 setError(error)19 }20 }21 fetchData()22 }, [url])23 return { data, error }24}25import { renderHook } from '@testing-library/react-hooks'26import { useFetch } from './useFetch'27it('should return data from an API', async () => {28 await waitForNextUpdate()29 expect(result.current.data.title).toBe('sunt aut facere repellat provident occaecati excepturi optio reprehenderit')30})31import { renderHook } from '@testing-library/react-hooks'32import { useFetch } from './useFetch'33it('should return data from an API', async () => {34 await waitForNextUpdate()35 expect(result.current.data.title).toBe('sunt aut facere repellat provident occaecati excepturi optio reprehenderit')36})37import { renderHook } from '@testing-library/react-hooks'38import { useFetch } from './useFetch'39it('should return data from an API', async () => {40 await waitForNextUpdate()41 expect(result.current.data.title).toBe('sunt aut facere repellat provident occaecati excepturi opt

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run testing-library-react-hooks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful