From bf4199a234042d6902ddbb61ceff1219470a0359 Mon Sep 17 00:00:00 2001 From: liangzhenyu123 Date: Mon, 21 Nov 2022 17:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liangzhenyu123 --- .../test/V9_PreferencesCallBackJsunit.test.js | 26 ++++++++++++++++++- .../test/V9_PreferencesPromiseJsunit.test.js | 26 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js index e265ba745..b58db0ae7 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js @@ -412,12 +412,36 @@ describe('preferencesV9CallbackTest', async function () { console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 key' + key); }; mPreference.on('change', observer); - mPreference.off('change', observer); + mPreference.off('sschange', observer); + expect(false).assertTrue() await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); await mPreference.flush(); } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + mPreference.off('change', observer); + } + done(); + }) + + /** + * @tc.name mPreference.off() + * @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1700 + * @tc.desc mPreference.off() + */ + it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1700', 0, async function (done) { + console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1700 begin.") + try { + var observer = function (key) { + console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1700 key' + key); + }; + mPreference.on('change', observer); + mPreference.off('change', "observer"); expect(false).assertTrue() + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); + await mPreference.flush(); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + mPreference.off('change', observer); } done(); }) diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js index 0435ad8b8..cac7c359f 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js @@ -412,12 +412,36 @@ describe('preferencesV9PromiseTest', async function () { console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1600 key' + key); }; mPreference.on('change', observer); - mPreference.off('change', observer); + mPreference.off('sschange', observer); + expect(false).assertTrue() await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); await mPreference.flush(); } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + mPreference.off('change', observer); + } + done(); + }) + + /** + * @tc.name mPreference.off() + * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1700 + * @tc.desc mPreference.off() + */ + it('SUB_DDM_JSPREFERENCEV9_PROMISE_1700', 0, async function (done) { + console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1700 begin.") + try { + var observer = function (key) { + console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1700 key' + key); + }; + mPreference.on('change', observer); + mPreference.off('change', "observer"); expect(false).assertTrue() + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); + await mPreference.flush(); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + mPreference.off('change', observer); } done(); }) -- GitLab