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 0b5a96cd747ca2e3c0a7c303d07dfa372ce4bcf5..4393ff932dde673a2f46acfecdf4b82e4c5589a6 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