From 2883a47b1e4a5a50b37d0816711b8468c1e16d8d Mon Sep 17 00:00:00 2001 From: y00576111 Date: Mon, 11 Oct 2021 13:02:31 +0800 Subject: [PATCH] add off testcase Signed-off-by: y00576111 Change-Id: Icfd03eda155e674901ae88273c7aadf1fd048282 --- .../src/main/js/test/Worker.test.js | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js index 0b5a96cd7..4393ff932 100644 --- a/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js +++ b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js @@ -384,6 +384,47 @@ describe('workerTest', function () { expect(times).assertEqual(10) }) + // check worker off function is ok + it('worker_off_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var zhangsan_times = 0; + ss.on("zhangsan", ()=>{ + zhangsan_times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(1) + + ss.off("zhangsan") + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(1) + }) + + // check worker off function is ok + it('worker_off_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var zhangsan_times = 0; + ss.on("zhangsan", ()=>{ + zhangsan_times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + + for (var i=0;i<3;i++) + { + ss.off("zhangsan") + } + + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + }) + // check worker removeEventListener function is ok it('worker_removeListener_test_001', 0, function () { var ss = new worker.Worker("workers/worker.js"); @@ -423,7 +464,6 @@ describe('workerTest', function () { ss.dispatchEvent({type: "zhangsan"}) expect(zhangsan_times).assertEqual(2) - }) // check worker removeAllListener function is ok -- GitLab