Skip to content

Commit 567949d

Browse files
committed
Test fixes
1 parent 8897d0c commit 567949d

14 files changed

Lines changed: 67 additions & 626 deletions

File tree

src/core/compile/compile.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
createElementFromHTML as $,
1010
getController,
1111
getScope,
12-
getIsolateScope,
1312
} from "../../shared/dom.ts";
1413
import { isFunction, getNodeName, extend, assert } from "../../shared/utils.ts";
1514
import { Cache } from "../../shared/dom.ts";
@@ -1789,7 +1788,7 @@ describe("$compile", () => {
17891788
reloadModules();
17901789
const el = $("<div my-directive></div>");
17911790
$compile(el)($rootScope);
1792-
expect(getIsolateScope(el)).toBe(givenScope);
1791+
expect(getCacheData(el, "$isolateScope")).toBe(givenScope);
17931792
});
17941793

17951794
it("allows observing attribute to the isolate scope", () => {
@@ -7078,7 +7077,9 @@ describe("$compile", () => {
70787077
const directiveElement = element.querySelector("a");
70797078

70807079
expect(getScope(directiveElement)).toBeUndefined();
7081-
expect(getIsolateScope(directiveElement)).toBeDefined();
7080+
expect(
7081+
getCacheData(directiveElement, "$isolateScope"),
7082+
).toBeDefined();
70827083
});
70837084

70847085
it("should render async directive templates without attaching inherited scope data to child nodes", async () => {
@@ -7093,7 +7094,9 @@ describe("$compile", () => {
70937094

70947095
expect(asyncChild.textContent).toBe("async");
70957096
expect(getScope(asyncChild)).toBeUndefined();
7096-
expect(getIsolateScope(asyncDirective)).toBeUndefined();
7097+
expect(
7098+
getCacheData(asyncDirective, "$isolateScope"),
7099+
).toBeUndefined();
70977100
});
70987101

70997102
it("should render sync directive templates without attaching inherited scope data to child nodes", async () => {
@@ -7107,7 +7110,9 @@ describe("$compile", () => {
71077110

71087111
expect(syncChild.textContent).toBe("");
71097112
expect(getScope(syncChild)).toBeUndefined();
7110-
expect(getIsolateScope(syncDirective)).toBeDefined();
7113+
expect(
7114+
getCacheData(syncDirective, "$isolateScope"),
7115+
).toBeDefined();
71117116
});
71127117
});
71137118

src/directive/attrs/attrs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ entries(ALIASED_ATTR).forEach(([ngAttr]) => {
103103
): void {
104104
const nodeName = getNodeName(element);
105105

106+
if (attrName === "srcset") {
107+
const originalAttrName = attr.$attr[normalized];
108+
109+
if (originalAttrName) {
110+
element.removeAttribute(originalAttrName);
111+
}
112+
}
113+
106114
function sanitize(value: unknown): any {
107115
if (isNullOrUndefined(value)) {
108116
return value;

src/router/params/param-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { equals } from "../../shared/common.ts";
21
import {
32
assign,
43
createObject,
4+
equals,
55
hasOwn,
66
isDefined,
77
isInstanceOf,

src/router/state/state-builder.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,12 @@ function buildParams(
7474
params[param.id] = param;
7575
});
7676

77-
const urlParamIds = new Set<string>();
78-
79-
urlParams.forEach((param: { id: string }) => {
80-
urlParamIds.add(param.id);
81-
});
82-
8377
const paramConfigs = state.params || {};
8478

8579
const paramConfigKeys = keys(paramConfigs);
8680

8781
paramConfigKeys.forEach((id) => {
88-
if (!urlParamIds.has(id)) {
82+
if (!hasOwn(params, id)) {
8983
params[id] = paramFactory.fromConfig(id, null, state.self);
9084
}
9185
});

src/router/transition/transition-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import {
22
_exceptionHandlerProvider,
33
_routerProvider,
44
} from "../../injection-tokens.ts";
5-
import { copy } from "../../shared/common.ts";
6-
import { isDefined } from "../../shared/utils.ts";
5+
import { assign, isDefined } from "../../shared/utils.ts";
76
import {
87
registerAddCoreResolvables,
98
treeChangesCleanup,
@@ -537,7 +536,13 @@ function registerUpdateGlobalState(
537536
routerState._successfulTransitions._enqueue(trans);
538537
routerState._currentState = current;
539538
routerState._current = current?.self;
540-
copy(trans.params(), routerState._params);
539+
const params = routerState._params;
540+
541+
for (const key in params) {
542+
delete params[key];
543+
}
544+
545+
assign(params, trans.params());
541546
};
542547

543548
const clearCurrentTransition = (): void => {

src/router/url/url-matcher.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { arrayTuples, defaults, inherit, map } from "../../shared/common.ts";
1+
import { defaults } from "../../shared/common.ts";
22
import {
33
hasOwn,
4+
inherit,
45
isArray,
56
isDefined,
67
isInstanceOf,
@@ -137,9 +138,15 @@ export class UrlMatcher {
137138
(path) => path.location === DefType._PATH,
138139
);
139140

140-
return arrayTuples(staticSegments, [...pathParams, undefined])
141-
.flat()
142-
.filter((x: string | Param | undefined) => x !== "" && isDefined(x));
141+
const result: Array<string | Param> = [];
142+
143+
for (let i = 0; i < staticSegments.length; i++) {
144+
if (staticSegments[i] !== "") result.push(staticSegments[i]);
145+
146+
if (isDefined(pathParams[i])) result.push(pathParams[i]);
147+
}
148+
149+
return result;
143150
}
144151

145152
/**
@@ -232,12 +239,11 @@ export class UrlMatcher {
232239
weightsB = weights(b);
233240

234241
padArrays(weightsA, weightsB, 0);
235-
const _pairs = arrayTuples(weightsA, weightsB);
236242

237243
let cmp;
238244

239-
for (let i = 0, l = _pairs.length; i < l; i++) {
240-
cmp = _pairs[i][0] - _pairs[i][1];
245+
for (let i = 0, l = weightsA.length; i < l; i++) {
246+
cmp = weightsA[i]! - weightsB[i]!;
241247

242248
if (cmp !== 0) return cmp;
243249
}
@@ -529,9 +535,9 @@ export class UrlMatcher {
529535

530536
const split = reverseString(paramVal).split(/-(?!\\)/);
531537

532-
const allReversed = map(split, reverseString);
538+
const allReversed = split.map(reverseString);
533539

534-
return (allReversed as string[]).map(unquoteDashes).reverse();
540+
return allReversed.map(unquoteDashes).reverse();
535541
}
536542

537543
for (let i = 0; i < nPathSegments; i++) {
@@ -707,8 +713,7 @@ export class UrlMatcher {
707713
if (isNullOrUndefined(encoded)) return acc;
708714

709715
// If this parameter value is an array, encode the value using encodeDashes
710-
if (isArray(encoded))
711-
return acc + (map(encoded, encodeDashes) as string[]).join("-");
716+
if (isArray(encoded)) return acc + encoded.map(encodeDashes).join("-");
712717

713718
// If the parameter type is "raw", then do not encodeURIComponent
714719
if (param.raw) {
@@ -736,8 +741,7 @@ export class UrlMatcher {
736741

737742
if (encoded.length === 0) return undefined;
738743

739-
if (!param.raw)
740-
encoded = map(encoded, encodeURIComponent) as string | string[];
744+
if (!param.raw) encoded = encoded.map(encodeURIComponent);
741745

742746
return (encoded as any[]).map((val: any) => `${param.id}=${val}`);
743747
})

src/router/url/url-service.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { dealoc } from "../../shared/dom.ts";
22
import { Angular } from "../../angular.ts";
3-
import { map, find } from "../../shared/common.ts";
43
import { UrlMatcher } from "./url-matcher.ts";
54

65
describe("UrlMatcher", () => {
@@ -556,11 +555,12 @@ describe("UrlMatcher", () => {
556555

557556
// Pass again through Param.value() for normalization (like transitionTo)
558557
const paramDefs = m.parameters();
559-
const values = map(parsed, function (val, key) {
560-
return find(paramDefs, function (def) {
561-
return def.id === key;
562-
}).value(val);
558+
const values = {};
559+
560+
Object.entries(parsed).forEach(([key, val]) => {
561+
values[key] = paramDefs.find((def) => def.id === key).value(val);
563562
});
563+
564564
expect(values).toEqual(expected);
565565
});
566566

src/router/view/view.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { _router, _templateFactory } from "../../injection-tokens.ts";
2-
import { equals, removeFrom } from "../../shared/common.ts";
2+
import { removeFrom } from "../../shared/common.ts";
33
import { ViewConfig } from "../state/views.ts";
44
import type { PathNode } from "../path/path-node.ts";
55
import type { ViewDeclaration } from "../state/interface.ts";
@@ -225,13 +225,7 @@ export class ViewService {
225225
this._sync();
226226

227227
return () => {
228-
const idx = ngViews.indexOf(ngView);
229-
230-
if (idx === -1) {
231-
return;
232-
}
233-
234-
ngViews.splice(idx, 1);
228+
removeFrom(ngViews, ngView);
235229
this._sync();
236230
};
237231
}
@@ -263,7 +257,7 @@ export class ViewService {
263257
const viewContext = viewDecl.$context as ViewContext;
264258

265259
if (
266-
!equals(viewContext, ngViewContext) &&
260+
viewContext.name !== ngViewContext.name &&
267261
vcContext !== ngViewContext.name
268262
) {
269263
return false;

src/shared/common.spec.js

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
1-
import { defaults, filter, map, pick, tail } from "./common.js";
1+
import { defaults, tail } from "./common.js";
22
import { is, pattern, val } from "./hof.js";
33
import { isInjectable } from "./predicates.js";
44
import { Queue } from "./queue.js";
55

66
describe("common", function () {
7-
describe("filter", function () {
8-
it("should filter arrays", function () {
9-
const input = [1, 2, 3, 4, 5];
10-
const filtered = filter(input, function (int) {
11-
return int > 2;
12-
});
13-
expect(filtered.length).toBe(3);
14-
expect(filtered).toEqual([3, 4, 5]);
15-
});
16-
17-
it("should properly compact arrays", function () {
18-
expect(
19-
filter([0, 1, 0, 2, 0, 3, 4], function (v) {
20-
return !!v;
21-
}),
22-
).toEqual([1, 2, 3, 4]);
23-
});
24-
25-
it("should filter objects", function () {
26-
const input = { foo: 1, bar: 2, baz: 3, qux: 4 };
27-
const filtered = filter(input, function (value, _key) {
28-
return value > 2;
29-
});
30-
expect(Object.keys(filtered).length).toBe(2);
31-
expect(filtered).toEqual({ baz: 3, qux: 4 });
32-
});
33-
});
34-
357
describe("defaults", function () {
368
it("should do left-associative object merge", function () {
379
const options = { param1: "new val" };
@@ -109,55 +81,6 @@ describe("common", function () {
10981
});
11082
});
11183

112-
describe("pick", () => {
113-
it("should pick inherited properties", () => {
114-
const parent = { foo: "foo", bar: "bar" };
115-
const child = Object.create(parent);
116-
expect(pick(child, ["foo"])).toEqual({ foo: "foo" });
117-
});
118-
119-
it("should not pick missing properties", () => {
120-
const obj = { foo: "foo", bar: "bar" };
121-
expect(pick(obj, ["baz"])).toEqual({});
122-
});
123-
});
124-
125-
describe("map on arrays", () => {
126-
it("should map arrays", () => {
127-
const src = [1, 2, 3, 4];
128-
const dest = map(src, (x) => x * 2);
129-
130-
expect(src).toEqual([1, 2, 3, 4]);
131-
expect(dest).toEqual([2, 4, 6, 8]);
132-
});
133-
134-
it("should map arrays in place when target === src", () => {
135-
const src = [1, 2, 3, 4];
136-
const dest = map(src, (x) => x * 2, src);
137-
138-
expect(src).toEqual([2, 4, 6, 8]);
139-
expect(dest).toEqual([2, 4, 6, 8]);
140-
});
141-
});
142-
143-
describe("map on objects", () => {
144-
it("should map objects", () => {
145-
const src = { foo: 1, bar: 2, baz: 3 };
146-
const dest = map(src, (x) => x * 2);
147-
148-
expect(src).toEqual({ foo: 1, bar: 2, baz: 3 });
149-
expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 });
150-
});
151-
152-
it("should map objects in place when target === src", () => {
153-
const src = { foo: 1, bar: 2, baz: 3 };
154-
const dest = map(src, (x) => x * 2, src);
155-
156-
expect(src).toEqual({ foo: 2, bar: 4, baz: 6 });
157-
expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 });
158-
});
159-
});
160-
16184
describe("tail", () => {
16285
it("should return the last element of a non-empty array", () => {
16386
expect(tail([1, 2, 3])).toBe(3);

0 commit comments

Comments
 (0)