diff --git a/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets index 3b2c266ccdda1cbdae970a5c0d41033e05c8884e..32e8c9a1e6850aa133652d1e59df7d79667d4f66 100644 --- a/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/abilitymontior/entry/src/main/ets/test/Ability.test.ets @@ -652,36 +652,37 @@ export default function abilityTest() { function UnSubscribeCallback() { console.debug("====>commonEvent_foreground UnSubscribeCallback====>"); } + var AddAbility function SubscribeCallBack(err, data) { console.debug("====>Subscribe CallBack data:====>" + JSON.stringify(data)); Subscriber.createSubscriber(commonEventSubscribeInfo, async (err, data) => { console.info("===ACTS_AddAbilityMonitor_1000===createSubscriber" + JSON.stringify(data)); - var AddAbility = data + AddAbility = data + Subscriber.subscribe(AddAbility, (err, data) => { + console.log('===ACTS_AddAbilityMonitor_1000CallBack===' + + err.code + JSON.stringify(data)) + Subscriber.unsubscribe(AddAbility, () => { + console.log('===UnSubscribeCallBack===') + Subscriber.unsubscribe(subscriber, UnSubscribeCallback); + }) + if (data.code == 1) { + expect(data.code).assertEqual(1); + setTimeout(() => { + done(); + }, 2500) + } + else { + expect().assertFail(); + setTimeout(() => { + done(); + }, 2500) + } + }) Delegator.getCurrentTopAbility().then((ability) => { console.info("===ACTS_AddAbilityMonitor_1000===ability" + JSON.stringify(ability).length); Delegator.doAbilityBackground(ability).then(async () => { console.info("===ACTS_AddAbilityMonitor_1000===data succeed."); expect(true).assertTrue(); - await Subscriber.subscribe(AddAbility, (err, data) => { - console.log('===ACTS_AddAbilityMonitor_1000CallBack===' - + err.code + JSON.stringify(data)) - Subscriber.unsubscribe(AddAbility, () => { - console.log('===UnSubscribeCallBack===') - Subscriber.unsubscribe(subscriber, UnSubscribeCallback); - }) - if (data.code == 1) { - expect(data.code).assertEqual(1); - setTimeout(() => { - done(); - }, 2500) - } - else { - expect().assertFail(); - setTimeout(() => { - done(); - }, 2500) - } - }) }).catch(() => { console.info("===ACTS_AddAbilityMonitor_1000===data succeed."); expect(false).assertTrue();