Skip to content

Commit ca960dc

Browse files
committed
Test fixes
1 parent 30d01b4 commit ca960dc

File tree

2 files changed

+1
-96
lines changed

2 files changed

+1
-96
lines changed

src/core/scope/scope.spec.js

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -986,71 +986,6 @@ describe("Scope", () => {
986986

987987
expect(spy).not.toHaveBeenCalled();
988988
});
989-
990-
it("deregisters repeated watch keys only once", async () => {
991-
const spy = jasmine.createSpy("repeated watch");
992-
scope.a = 1;
993-
994-
const unwatch = scope.$watch("a + a", spy);
995-
996-
await wait();
997-
expect(spy).toHaveBeenCalledTimes(1);
998-
spy.calls.reset();
999-
1000-
/** @type {Function} */ (unwatch)();
1001-
scope.a = 2;
1002-
await wait();
1003-
1004-
expect(spy).not.toHaveBeenCalled();
1005-
});
1006-
1007-
it("does not trigger twice for repeated array expression keys", async () => {
1008-
const spy = jasmine.createSpy("repeated array watch");
1009-
scope.a = 1;
1010-
1011-
scope.$watch("[a, a]", spy);
1012-
1013-
await wait();
1014-
expect(spy).toHaveBeenCalledTimes(1);
1015-
spy.calls.reset();
1016-
1017-
scope.a = 2;
1018-
await wait();
1019-
1020-
expect(spy).toHaveBeenCalledTimes(1);
1021-
expect(spy.calls.mostRecent().args[0]).toEqual([2, 2]);
1022-
});
1023-
1024-
it("does not trigger twice for repeated object expression keys and deregisters cleanly", async () => {
1025-
const spy = jasmine.createSpy("repeated object watch");
1026-
scope.a = 1;
1027-
1028-
const unwatch = scope.$watch("{left: a, right: a}", spy);
1029-
1030-
await wait();
1031-
expect(spy).toHaveBeenCalledTimes(1);
1032-
expect(spy.calls.mostRecent().args[0]).toEqual({
1033-
left: 1,
1034-
right: 1,
1035-
});
1036-
spy.calls.reset();
1037-
1038-
scope.a = 2;
1039-
await wait();
1040-
1041-
expect(spy).toHaveBeenCalledTimes(1);
1042-
expect(spy.calls.mostRecent().args[0]).toEqual({
1043-
left: 2,
1044-
right: 2,
1045-
});
1046-
spy.calls.reset();
1047-
1048-
/** @type {Function} */ (unwatch)();
1049-
scope.a = 3;
1050-
await wait();
1051-
1052-
expect(spy).not.toHaveBeenCalled();
1053-
});
1054989
});
1055990

1056991
describe("apply expression", () => {
@@ -1360,25 +1295,6 @@ describe("Scope", () => {
13601295
expect(count).toEqual(3);
13611296
});
13621297

1363-
it("does not register duplicate listeners for repeated watch keys", async () => {
1364-
scope.counter = 0;
1365-
scope.a = 1;
1366-
1367-
scope.$watch("a + a", () => {
1368-
scope.counter++;
1369-
});
1370-
await wait();
1371-
expect(scope.counter).toBe(1);
1372-
1373-
scope.a = 2;
1374-
await wait();
1375-
expect(scope.counter).toBe(2);
1376-
1377-
scope.a = 3;
1378-
await wait();
1379-
expect(scope.counter).toBe(3);
1380-
});
1381-
13821298
it("calls the listener function when a deeply nested watched value changes", async () => {
13831299
scope.counter = 0;
13841300
scope.someValue = { b: { c: { d: 1 } } };

src/core/scope/scope.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,10 @@ function registerListenerKeys(
183183
watchKeys: Array<string | undefined>,
184184
schedule = false,
185185
): void {
186-
const seenKeys = new Set<string>();
187-
188186
for (let i = 0, l = watchKeys.length; i < l; i++) {
189187
const key = watchKeys[i];
190188

191189
if (!key) continue;
192-
193-
if (seenKeys.has(key)) continue;
194-
seenKeys.add(key);
195190
scope._registerKey(key, listener);
196191

197192
if (schedule) scope._scheduleListener([listener]);
@@ -203,16 +198,10 @@ function deregisterListenerKeys(
203198
listenerId: number,
204199
watchKeys: Array<string | undefined>,
205200
): void {
206-
const seenKeys = new Set<string>();
207-
208201
for (let i = 0, l = watchKeys.length; i < l; i++) {
209202
const key = watchKeys[i];
210203

211-
if (!key) continue;
212-
213-
if (seenKeys.has(key)) continue;
214-
seenKeys.add(key);
215-
scope._deregisterKey(key, listenerId);
204+
if (key) scope._deregisterKey(key, listenerId);
216205
}
217206
}
218207

0 commit comments

Comments
 (0)