提交 ad49d27c 编写于 作者: B bayanxing

testClearInterval 修复

Signed-off-by: Nbayanxing <bayanxing@kaihong.com>
上级 11a5a712
...@@ -19,505 +19,510 @@ import router from '@system.router'; ...@@ -19,505 +19,510 @@ import router from '@system.router';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium';
export default function basicabilityapi() { export default function basicabilityapi() {
describe('basicabilityapi', function () { describe('basicabilityapi', function () {
let testResult; let testResult;
let testResultFail; let testResultFail;
let test; let test;
beforeAll(function () { beforeAll(function () {
testResult = true; testResult = true;
testResultFail = false; testResultFail = false;
test = "success" test = "success"
});
beforeEach(function () {
});
afterEach(function () {
});
afterAll(function () {
});
async function backToIndex(){
let backToIndexPromise = new Promise((resolve, reject) => {
setTimeout(() => {
router.back({
uri: 'pages/index/index'
});
resolve();
}, 500);
}); });
let clearPromise = new Promise((resolve, reject) => { beforeEach(function () {
setTimeout(() => {
router.clear();
resolve();
}, 500);
});
await backToIndexPromise.then(() => {
return clearPromise;
}); });
} afterEach(function () {
/**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0100
* @tc.name testClearInterval
* @tc.desc Cancel the repetitive timing tasks previously set by setInterval.
*/
it('testClearInterval', 0, async function(done) {
console.info('testClearInterval START');
let res = 0;
let testTimes = 5
let intervalID = -1;
let promise1 = new Promise((resolve, reject) => {
intervalID = setInterval(function () {
if(res === testTimes ){
clearInterval(intervalID);
}
res++;
console.info('testClearInterval res = ' + res);
resolve();
}, 100);
}); });
Promise.all([promise1]).then(() => { afterAll(function () {
console.info('testClearInterval finally');
expect(testTimes).assertEqual(res);
console.info('testClearInterval END');
done();
}); });
});
/** async function backToIndex(){
* @tc.number SUB_ACE_BASICABILITY_JS_API_0200 let backToIndexPromise = new Promise((resolve, reject) => {
* @tc.name testConsole setTimeout(() => {
* @tc.desc Print a text message. router.back({
*/ uri: 'pages/index/index'
it('testConsole', 0, function () { });
console.info('testConsole START'); resolve();
try{ }, 500);
const versionCode = 1.1; });
console.info('[console.info] versionCode: ' + versionCode); let clearPromise = new Promise((resolve, reject) => {
console.debug('[console.debug] versionCode: ' + versionCode); setTimeout(() => {
console.log('[console.log] versionCode: ' + versionCode); router.clear();
console.warn('[console.warn] versionCode: ' + versionCode); resolve();
console.error('[console.error] versionCode: ' + versionCode); }, 500);
expect(test).assertEqual('success'); });
console.info('testConsole END'); await backToIndexPromise.then(() => {
} return clearPromise;
catch(e){ });
console.info('testConsole ERROR' + e);
} }
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0300 * @tc.number SUB_ACE_BASICABILITY_JS_API_0100
* @tc.name testRouterPush * @tc.name testClearInterval
* @tc.desc Go to the specified page of the application. * @tc.desc Cancel the repetitive timing tasks previously set by setInterval.
*/ */
it('testRouterPush', 0, async function (done) { it('testClearInterval', 0, async function(done) {
console.info('testRouterPush START'); console.info('testClearInterval START');
let options = { let res = 0;
uri : 'pages/routerPush/index' let intervalID = -1;
} let promise1 = new Promise((resolve, reject) => {
let promise1 = new Promise((resolve, reject) => { intervalID = setInterval(function () {
router.push(options); res++;
resolve(); console.info('testClearInterval res = ' + res);
}); resolve();
let promise2 = new Promise((resolve, reject) => { }, 100);
setTimeout(() => { });
let pages = router.getState(); let promise2 = new Promise((resolve, reject) => {
console.info("[router.push] getState" + JSON.stringify(pages)); setTimeout(function () {
expect("pages/routerPush/").assertEqual(pages.path); console.info('[clearInterval] start');
console.info("[router.push] getLength:" + router.getLength()); clearInterval(intervalID);
expect("2").assertEqual(router.getLength()); console.info('[clearInterval] end');
console.info('testRouterPush SUCCESS'); resolve();
resolve(); }, 600);
}, 500); });
}); Promise.all([promise1, promise2]).then(() => {
await promise1.then(() => { console.info('testClearInterval finally');
return promise2; expect(5).assertEqual(res);
}); console.info('testClearInterval END');
await backToIndex(); done();
console.info('testRouterPush END');
done();
});
/**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0310
* @tc.name testRouterPushNotExist
* @tc.desc Test push not exist page.
*/
it('testRouterPushNotExist', 0, async function (done) {
console.info('testRouterPushNotExist START');
let promise1 = new Promise((resolve, reject) => {
router.push({
uri: 'pages/routerNotExist/index'
}); });
resolve();
});
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
let pages = router.getState();
console.info("testRouterPushNotExist getState" + JSON.stringify(pages));
expect("pages/index/").assertEqual(pages.path);
console.info("testRouterPushNotExist getLength:" + router.getLength());
expect("1").assertEqual(router.getLength());
console.info('testRouterPushNotExist success');
resolve();
}, 500);
});
await promise1.then(() => {
return promise2;
}); });
console.info('testRouterPushNotExist END');
done();
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0400 * @tc.number SUB_ACE_BASICABILITY_JS_API_0200
* @tc.name testRouterReplace * @tc.name testConsole
* @tc.desc Replace the current page with a page in the application, and destroy the replaced page. * @tc.desc Print a text message.
*/ */
it('testRouterReplace', 0, async function (done) { it('testConsole', 0, function () {
console.info('testRouterReplace START'); console.info('testConsole START');
let options = { try{
uri : 'pages/routerPush/index' const versionCode = 1.1;
} console.info('[console.info] versionCode: ' + versionCode);
let promise1 = new Promise((resolve, reject) => { console.debug('[console.debug] versionCode: ' + versionCode);
router.push(options); console.log('[console.log] versionCode: ' + versionCode);
resolve(); console.warn('[console.warn] versionCode: ' + versionCode);
}); console.error('[console.error] versionCode: ' + versionCode);
let repleasePage = { expect(test).assertEqual('success');
uri : 'pages/routerReplace/index' console.info('testConsole END');
} }
let promise2 = new Promise((resolve, reject) => { catch(e){
setTimeout(() => { console.info('testConsole ERROR' + e);
router.replace(repleasePage); }
resolve();
}, 500);
}); });
//替换堆栈数量不会变
let promise3 = new Promise((resolve, reject) => { /**
setTimeout(() => { * @tc.number SUB_ACE_BASICABILITY_JS_API_0300
let pages = router.getState(); * @tc.name testRouterPush
console.info("[router.replace] getState" + JSON.stringify(pages)); * @tc.desc Go to the specified page of the application.
expect("pages/routerReplace/").assertEqual(pages.path); */
console.info("[router.replace] getLength:" + router.getLength()); it('testRouterPush', 0, async function (done) {
expect("2").assertEqual(router.getLength()); console.info('testRouterPush START');
console.info('testRouterReplace SUCCESS'); let options = {
uri : 'pages/routerPush/index'
}
let promise1 = new Promise((resolve, reject) => {
router.push(options);
resolve(); resolve();
}, 1000); });
}); let promise2 = new Promise((resolve, reject) => {
await promise1.then(() => { setTimeout(() => {
return promise2; let pages = router.getState();
}).then(() => { console.info("[router.push] getState" + JSON.stringify(pages));
return promise3; expect("pages/routerPush/").assertEqual(pages.path);
console.info("[router.push] getLength:" + router.getLength());
expect("2").assertEqual(router.getLength());
console.info('testRouterPush SUCCESS');
resolve();
}, 500);
});
await promise1.then(() => {
return promise2;
});
await backToIndex();
console.info('testRouterPush END');
done();
}); });
await backToIndex();
console.info('testRouterReplace END');
done();
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0410 * @tc.number SUB_ACE_BASICABILITY_JS_API_0310
* @tc.name testRouterReplaceNotExist * @tc.name testRouterPushNotExist
* @tc.desc Test replace not exist page. * @tc.desc Test push not exist page.
*/ */
it('testRouterReplaceNotExist', 0, async function (done) { it('testRouterPushNotExist', 0, async function (done) {
console.info('testRouterReplaceNotExist START'); console.info('testRouterPushNotExist START');
await setTimeout(() => { let promise1 = new Promise((resolve, reject) => {
router.replace({ router.push({
uri: 'pages/routerNotExist/index' uri: 'pages/routerNotExist/index'
});
resolve();
}); });
}, 500); let promise2 = new Promise((resolve, reject) => {
await setTimeout(() => { setTimeout(() => {
let pages = router.getState(); let pages = router.getState();
console.info("testRouterReplaceNotExist getState" + JSON.stringify(pages)); console.info("testRouterPushNotExist getState" + JSON.stringify(pages));
expect("pages/index/").assertEqual(pages.path); expect("pages/index/").assertEqual(pages.path);
console.info("testRouterReplaceNotExist getLength:" + router.getLength()); console.info("testRouterPushNotExist getLength:" + router.getLength());
expect("1").assertEqual(router.getLength()); expect("1").assertEqual(router.getLength());
console.info('testRouterReplaceNotExist END'); console.info('testRouterPushNotExist success');
resolve();
}, 500);
});
await promise1.then(() => {
return promise2;
});
console.info('testRouterPushNotExist END');
done(); done();
}, 1000); });
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0500 * @tc.number SUB_ACE_BASICABILITY_JS_API_0400
* @tc.name testRouterBack * @tc.name testRouterReplace
* @tc.desc Return to the previous page or the specified page. * @tc.desc Replace the current page with a page in the application, and destroy the replaced page.
*/ */
it('testRouterBack', 0, async function (done) { it('testRouterReplace', 0, async function (done) {
console.info('testRouterBack START'); console.info('testRouterReplace START');
let promise1 = new Promise((resolve, reject) => { let options = {
router.push({ uri : 'pages/routerPush/index'
uri: 'pages/routerPush/index' }
let promise1 = new Promise((resolve, reject) => {
router.push(options);
resolve();
});
let repleasePage = {
uri : 'pages/routerReplace/index'
}
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
router.replace(repleasePage);
resolve();
}, 500);
});
//替换堆栈数量不会变
let promise3 = new Promise((resolve, reject) => {
setTimeout(() => {
let pages = router.getState();
console.info("[router.replace] getState" + JSON.stringify(pages));
expect("pages/routerReplace/").assertEqual(pages.path);
console.info("[router.replace] getLength:" + router.getLength());
expect("2").assertEqual(router.getLength());
console.info('testRouterReplace SUCCESS');
resolve();
}, 1000);
}); });
resolve(); await promise1.then(() => {
return promise2;
}).then(() => {
return promise3;
});
await backToIndex();
console.info('testRouterReplace END');
done();
}); });
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => { /**
router.back({ * @tc.number SUB_ACE_BASICABILITY_JS_API_0410
uri: 'pages/index/index' * @tc.name testRouterReplaceNotExist
* @tc.desc Test replace not exist page.
*/
it('testRouterReplaceNotExist', 0, async function (done) {
console.info('testRouterReplaceNotExist START');
await setTimeout(() => {
router.replace({
uri: 'pages/routerNotExist/index'
}); });
resolve();
}, 500); }, 500);
}); await setTimeout(() => {
let promise3 = new Promise((resolve, reject) => {
setTimeout(() => {
let pages = router.getState(); let pages = router.getState();
console.info("[router.back] getState" + JSON.stringify(pages)); console.info("testRouterReplaceNotExist getState" + JSON.stringify(pages));
expect("pages/index/").assertEqual(pages.path); expect("pages/index/").assertEqual(pages.path);
console.info("[router.back] getLength:" + router.getLength()); console.info("testRouterReplaceNotExist getLength:" + router.getLength());
expect("1").assertEqual(router.getLength()); expect("1").assertEqual(router.getLength());
console.info('testRouterBack SUCCESS'); console.info('testRouterReplaceNotExist END');
resolve(); done();
}, 1000); }, 1000);
}); });
await promise1.then(() => {
return promise2;
}).then(() => {
return promise3;
});
console.info('testRouterBack END');
done();
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0600 * @tc.number SUB_ACE_BASICABILITY_JS_API_0500
* @tc.name testRouterClear * @tc.name testRouterBack
* @tc.desc Clear all historical pages in the page stack, and only keep the current page as the top page. * @tc.desc Return to the previous page or the specified page.
*/ */
it('testRouterClear', 0, function () { it('testRouterBack', 0, async function (done) {
console.info('testRouterClear START'); console.info('testRouterBack START');
router.clear(); let promise1 = new Promise((resolve, reject) => {
console.info("[router.clear] router.getLength:" + router.getLength()); router.push({
expect("1").assertEqual(router.getLength()); uri: 'pages/routerPush/index'
console.info('testRouterClear END'); });
});
/**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0700
* @tc.name testRouterLength
* @tc.desc Get the number of pages currently in the page stack.
*/
it('testRouterLength', 0, async function (done) {
console.info('testRouterLength START');
let size = router.getLength();
console.info('[router.getLength] pages stack size = ' + size);
expect(size).assertEqual('1');
let options = {
uri : 'pages/routerPush/index'
}
let promise1 = new Promise((resolve, reject) => {
router.push(options);
resolve();
});
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.info("testRouterLength getLength:" + router.getLength());
expect("2").assertEqual(router.getLength());
console.info('testRouterLength SUCCESS');
resolve(); resolve();
}, 500); });
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
router.back({
uri: 'pages/index/index'
});
resolve();
}, 500);
});
let promise3 = new Promise((resolve, reject) => {
setTimeout(() => {
let pages = router.getState();
console.info("[router.back] getState" + JSON.stringify(pages));
expect("pages/index/").assertEqual(pages.path);
console.info("[router.back] getLength:" + router.getLength());
expect("1").assertEqual(router.getLength());
console.info('testRouterBack SUCCESS');
resolve();
}, 1000);
});
await promise1.then(() => {
return promise2;
}).then(() => {
return promise3;
});
console.info('testRouterBack END');
done();
}); });
await promise1.then(() => {
return promise2; /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0600
* @tc.name testRouterClear
* @tc.desc Clear all historical pages in the page stack, and only keep the current page as the top page.
*/
it('testRouterClear', 0, function () {
console.info('testRouterClear START');
router.clear();
console.info("[router.clear] router.getLength:" + router.getLength());
expect("1").assertEqual(router.getLength());
console.info('testRouterClear END');
}); });
await backToIndex();
console.info('testRouterLength END');
done();
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0800 * @tc.number SUB_ACE_BASICABILITY_JS_API_0700
* @tc.name testRouterGetState * @tc.name testRouterLength
* @tc.desc Get the status information of the current page. * @tc.desc Get the number of pages currently in the page stack.
*/ */
it('testRouterGetState', 0, async function (done) { it('testRouterLength', 0, async function (done) {
console.info('testRouterGetState START'); console.info('testRouterLength START');
await setTimeout(() => { let size = router.getLength();
let page = router.getState(); console.info('[router.getLength] pages stack size = ' + size);
console.info('[router.getState] index: ' + page.index); expect(size).assertEqual('1');
console.info('[router.getState] name: ' + page.name); let options = {
console.info('[router.getState] path: ' + page.path); uri : 'pages/routerPush/index'
expect(page.index).assertEqual(1); }
expect(page.name).assertEqual('index'); let promise1 = new Promise((resolve, reject) => {
expect(page.path).assertEqual('pages/index/'); router.push(options);
console.info('testRouterGetState END'); resolve();
});
let promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.info("testRouterLength getLength:" + router.getLength());
expect("2").assertEqual(router.getLength());
console.info('testRouterLength SUCCESS');
resolve();
}, 500);
});
await promise1.then(() => {
return promise2;
});
await backToIndex();
console.info('testRouterLength END');
done(); done();
}, 500); });
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_0900 * @tc.number SUB_ACE_BASICABILITY_JS_API_0800
* @tc.name testPromptShowToast * @tc.name testRouterGetState
* @tc.desc Show text pop-up window. * @tc.desc Get the status information of the current page.
*/ */
it('testPromptShowToast', 0, function () { it('testRouterGetState', 0, async function (done) {
try{ console.info('testRouterGetState START');
console.info('testPromptShowToast START'); await setTimeout(() => {
const delay = 5000; let page = router.getState();
prompt.showToast({ console.info('[router.getState] index: ' + page.index);
message: 'message', console.info('[router.getState] name: ' + page.name);
duration: delay, console.info('[router.getState] path: ' + page.path);
}); expect(page.index).assertEqual(1);
expect(test).assertEqual('success'); expect(page.name).assertEqual('index');
console.info('[prompt.showToast] success'); expect(page.path).assertEqual('pages/index/');
console.info('testPromptShowToast END'); console.info('testRouterGetState END');
} done();
catch(e){ }, 500);
console.log('testPromptShowToast ERROR' + e); });
}
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1000 * @tc.number SUB_ACE_BASICABILITY_JS_API_0900
* @tc.name testPromptDialog * @tc.name testPromptShowToast
* @tc.desc Display the dialog box in the page. * @tc.desc Show text pop-up window.
*/ */
it('testPromptDialog', 0, function () { it('testPromptShowToast', 0, function () {
console.info('testPromptDialog START') try{
try{ console.info('testPromptShowToast START');
prompt.showDialog({ const delay = 5000;
title: 'dialog showDialog test', prompt.showToast({
message: 'message of dialog', message: 'message',
buttons: [ duration: delay,
{ });
text: 'OK', expect(test).assertEqual('success');
color: '#0000ff', console.info('[prompt.showToast] success');
index: 0 console.info('testPromptShowToast END');
}
catch(e){
console.log('testPromptShowToast ERROR' + e);
}
});
/**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1000
* @tc.name testPromptDialog
* @tc.desc Display the dialog box in the page.
*/
it('testPromptDialog', 0, function () {
console.info('testPromptDialog START')
try{
prompt.showDialog({
title: 'dialog showDialog test',
message: 'message of dialog',
buttons: [
{
text: 'OK',
color: '#0000ff',
index: 0
}
],
success: function (ret) {
console.info("[prompt.showDialog] ret.index " + ret.index);
expect(testResult).toBeTrue();
},
cancel: function () {
console.log('[prompt.showDialog] dialog cancel callback');
expect(testResultFail).toBeTrue();
},
complete: function () {
console.log('[prompt.showDialog] complete');
} }
], });
success: function (ret) { console.info('testPromptDialog END');
console.info("[prompt.showDialog] ret.index " + ret.index); }
expect(testResult).toBeTrue(); catch(e) {
}, console.info('testPromptDialog error ' + e);
cancel: function () { }
console.log('[prompt.showDialog] dialog cancel callback'); });
expect(testResultFail).toBeTrue();
},
complete: function () {
console.log('[prompt.showDialog] complete');
}
});
console.info('testPromptDialog END');
}
catch(e) {
console.info('testPromptDialog error ' + e);
}
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1100 * @tc.number SUB_ACE_BASICABILITY_JS_API_1100
* @tc.name testConfigurationGetLocale * @tc.name testConfigurationGetLocale
* @tc.desc Get the current language and region of the app. Synchronize with the language and region. * @tc.desc Get the current language and region of the app. Synchronize with the language and region.
*/ */
it('testConfigurationGetLocale', 0, function () { it('testConfigurationGetLocale', 0, function () {
console.info('testConfigurationGetLocale START'); console.info('testConfigurationGetLocale START');
const localeInfo = configuration.getLocale(); const localeInfo = configuration.getLocale();
console.info("[configuration.getLocale] localeInfo: " + JSON.stringify(localeInfo)); console.info("[configuration.getLocale] localeInfo: " + JSON.stringify(localeInfo));
console.info("[configuration.getLocale] language: " + localeInfo.language); console.info("[configuration.getLocale] language: " + localeInfo.language);
console.info("[configuration.getLocale] countryOrRegion: " + localeInfo.countryOrRegion); console.info("[configuration.getLocale] countryOrRegion: " + localeInfo.countryOrRegion);
console.info("[configuration.getLocale] dir: " + localeInfo.dir); console.info("[configuration.getLocale] dir: " + localeInfo.dir);
expect(localeInfo.language).assertEqual('zh'); expect(localeInfo.language).assertEqual('zh');
expect(localeInfo.dir).assertEqual('ltr'); expect(localeInfo.dir).assertEqual('ltr');
console.info('testConfigurationGetLocale END'); console.info('testConfigurationGetLocale END');
}); });
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1200 * @tc.number SUB_ACE_BASICABILITY_JS_API_1200
* @tc.name testSetTimeout * @tc.name testSetTimeout
* @tc.desc Set up a timer that executes a function or a specified piece of code after the timer expires. * @tc.desc Set up a timer that executes a function or a specified piece of code after the timer expires.
*/ */
it('testSetTimeout', 0, async function (done) { it('testSetTimeout', 0, async function (done) {
console.info('testSetTimeout START'); console.info('testSetTimeout START');
let startTime = new Date().getTime(); let startTime = new Date().getTime();
const delay = 200; const delay = 200;
await setTimeout(function (v1, v2) { await setTimeout(function (v1, v2) {
let endTime = new Date().getTime(); let endTime = new Date().getTime();
console.info("[setTimeout] startTime: " + startTime); console.info("[setTimeout] startTime: " + startTime);
console.info("[setTimeout] endTime: " + endTime); console.info("[setTimeout] endTime: " + endTime);
console.info('[setTimeout] delay: ' + (endTime - startTime)); console.info('[setTimeout] delay: ' + (endTime - startTime));
console.info('[setTimeout] v1: ' + v1); console.info('[setTimeout] v1: ' + v1);
console.info('[setTimeout] v2: ' + v2); console.info('[setTimeout] v2: ' + v2);
expect('test').assertEqual(v1); expect('test').assertEqual(v1);
expect('message').assertEqual(v2); expect('message').assertEqual(v2);
expect(endTime - startTime >= delay).assertTrue(); expect(endTime - startTime >= delay).assertTrue();
console.info('testSetTimeout END'); console.info('testSetTimeout END');
done(); done();
}, delay, 'test', 'message'); }, delay, 'test', 'message');
}); });
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1300 * @tc.number SUB_ACE_BASICABILITY_JS_API_1300
* @tc.name testClearTimeout * @tc.name testClearTimeout
* @tc.desc The timer previously established by calling setTimeout() is cancelled. * @tc.desc The timer previously established by calling setTimeout() is cancelled.
*/ */
it('testClearTimeout', 0, async function (done) { it('testClearTimeout', 0, async function (done) {
console.info('testClearTimeout START'); console.info('testClearTimeout START');
let res = 0; let res = 0;
let timeoutID = setTimeout(function () { let timeoutID = setTimeout(function () {
res++; res++;
}, 700); }, 700);
await setTimeout(function () { await setTimeout(function () {
console.info('testClearTimeout delay 0.5s') console.info('testClearTimeout delay 0.5s')
clearTimeout(timeoutID); clearTimeout(timeoutID);
console.info("[clearTimeout] success"); console.info("[clearTimeout] success");
}, 500); }, 500);
await setTimeout(function () { await setTimeout(function () {
expect(0).assertEqual(res); expect(0).assertEqual(res);
console.info('testClearTimeout END'); console.info('testClearTimeout END');
done(); done();
}, 1000); }, 1000);
}); });
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1400 * @tc.number SUB_ACE_BASICABILITY_JS_API_1400
* @tc.name testSetInterval * @tc.name testSetInterval
* @tc.desc Call a function or execute a code segment repeatedly, with a fixed time delay between each call. * @tc.desc Call a function or execute a code segment repeatedly, with a fixed time delay between each call.
*/ */
it('testSetInterval', 0, async function (done) { it('testSetInterval', 0, async function (done) {
console.info('testSetInterval START'); console.info('testSetInterval START');
let res = 0; let res = 0;
let intervalID = setInterval(function () { let intervalID = setInterval(function () {
res++; res++;
}, 100); }, 100);
await setTimeout(function () { await setTimeout(function () {
expect(9).assertEqual(res); expect(9).assertEqual(res);
console.info('testSetInterval SUCCESS'); console.info('testSetInterval SUCCESS');
clearInterval(intervalID); clearInterval(intervalID);
console.info('testSetInterval END'); console.info('testSetInterval END');
done(); done();
}, 1000); }, 1000);
}); });
/**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1500 /**
* @tc.name testRequestAnimationFrame * @tc.number SUB_ACE_BASICABILITY_JS_API_1500
* @tc.desc Sets a vsync after which a function will be executed. * @tc.name testRequestAnimationFrame
*/ * @tc.desc Sets a vsync after which a function will be executed.
it('testRequestAnimationFrame', 0, async function (done) { */
console.info('testRequestAnimationFrame START'); it('testRequestAnimationFrame', 0, async function (done) {
let requestId = requestAnimationFrame(function () { console.info('testRequestAnimationFrame START');
console.info('testRequestAnimationFrame success'); let requestId = requestAnimationFrame(function () {
expect(true).assertTrue(); console.info('testRequestAnimationFrame success');
done(); expect(true).assertTrue();
done();
});
}); });
});
/** /**
* @tc.number SUB_ACE_BASICABILITY_JS_API_1600 * @tc.number SUB_ACE_BASICABILITY_JS_API_1600
* @tc.name testCancelAnimationFrame * @tc.name testCancelAnimationFrame
* @tc.desc Indicates the vsync callback ID returned by "requestAnimationFrame()". * @tc.desc Indicates the vsync callback ID returned by "requestAnimationFrame()".
*/ */
it('testCancelAnimationFrame', 0, async function (done) { it('testCancelAnimationFrame', 0, async function (done) {
console.info('testCancelAnimationFrame START'); console.info('testCancelAnimationFrame START');
let result = true; let result = true;
let requestId = requestAnimationFrame(function () { let requestId = requestAnimationFrame(function () {
console.info('testCancelAnimationFrame fail'); console.info('testCancelAnimationFrame fail');
result = false; result = false;
});
cancelAnimationFrame(requestId);
await setTimeout(function () {
expect(result).assertTrue();
done();
}, 1000);
}); });
cancelAnimationFrame(requestId);
await setTimeout(function () {
expect(result).assertTrue();
done();
}, 1000);
}); });
});
} }
# This file is automatically generated by DevEco Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# For customization when using a Version Control System, please read the header note.
sdk.dir=D:/beta3Sdk
nodejs.dir=D:/software/DevEco Studio 3.0.0.900/tools/nodejs
npm.dir=D:/software/DevEco Studio 3.0.0.900/tools/nodejs
\ No newline at end of file
{
"lockfileVersion": 1
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册