Skip to content

Commit 381ca48

Browse files
author
Anatoly Ostrovsky
committed
Spec format improvements
1 parent c07e636 commit 381ca48

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

src/core/parse/parse.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe("parser", () => {
344344
scope.fooExp = "barVal";
345345
// By evaluating hasOwnProperty, the $parse cache will store a getter for
346346
// the scope's own hasOwnProperty function, which will mess up future cache look ups.
347-
// i.e. cache['hasOwnProperty'] = function(scope) { return scope.hasOwnProperty; }
347+
// i.e. cache['hasOwnProperty'] = (scope) => scope.hasOwnProperty;
348348
scope.$eval("hasOwnProperty");
349349
expect(scope.$eval("fooExp")).toBe("barVal");
350350
});

src/services/http/http.spec.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,7 @@ describe("$http", function () {
447447
});
448448

449449
it("does not serialize blobs for requests", async function () {
450-
let blob;
451-
if (window.Blob) {
452-
blob = new Blob(["hello"]);
453-
} else {
454-
const BlobBuilder =
455-
window.BlobBuilder ||
456-
window.WebKitBlobBuilder ||
457-
window.MozBlobBuilder ||
458-
window.MSBlobBuilder;
459-
const bb = new BlobBuilder();
460-
bb.append("hello");
461-
blob = bb.getBlob("text/plain");
462-
}
450+
let blob = new Blob(["hello"]);
463451
await $http({
464452
method: "POST",
465453
url: "/mock/blob",

src/services/sce/sce.spec.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ describe("SCE", () => {
1010
let errorLog = [];
1111

1212
describe("when disabled", () => {
13-
beforeEach(function () {
13+
beforeEach(() => {
1414
window.angular = new Angular();
1515
window.angular
1616
.module("myModule", ["ng"])
17-
.decorator("$exceptionHandler", function () {
17+
.decorator("$exceptionHandler", () => {
1818
return (exception) => {
1919
errorLog.push(exception.message);
2020
};
2121
});
2222
createInjector([
2323
"myModule",
24-
function ($sceProvider, $exceptionHandlerProvider) {
24+
($sceProvider, $exceptionHandlerProvider) => {
2525
$exceptionHandlerProvider.handler = (err) => logs.push(err.message);
2626
$sceProvider.enabled(false);
2727
},
@@ -36,12 +36,12 @@ describe("SCE", () => {
3636
});
3737

3838
describe("when enabled", () => {
39-
beforeEach(function () {
39+
beforeEach(() => {
4040
window.angular = new Angular();
4141
logs = [];
4242
createInjector([
4343
"ng",
44-
function ($sceProvider, $exceptionHandlerProvider) {
44+
($sceProvider, $exceptionHandlerProvider) => {
4545
$exceptionHandlerProvider.handler = (err) => {
4646
logs.push(err.message);
4747
};
@@ -550,20 +550,29 @@ describe("SCE", () => {
550550
const $$sanitizeUri = jasmine
551551
.createSpy("$$sanitizeUri")
552552
.and.returnValue("someSanitizedUrl");
553-
// module(($provide) => {
554-
// $provide.value("$$sanitizeUri", $$sanitizeUri);
555-
// });
556-
() => {
557-
expect($sce.getTrustedMediaUrl("someUrl")).toEqual(
558-
"someSanitizedUrl",
559-
);
560-
expect($$sanitizeUri).toHaveBeenCalledOnceWith("someUrl", true);
553+
window.angular = new Angular();
554+
window.angular.module("testSanitizeUri", ["ng"]).config([
555+
"$provide",
556+
($provide) => {
557+
$provide.value("$$sanitizeUri", $$sanitizeUri);
558+
},
559+
]);
560+
createInjector([
561+
"testSanitizeUri",
562+
($sceProvider, $exceptionHandlerProvider) => {
563+
$sceProvider.enabled(true);
564+
},
565+
]).invoke((_$sce_) => {
566+
$sce = _$sce_;
567+
});
561568

562-
$$sanitizeUri.calls.reset();
569+
expect($sce.getTrustedMediaUrl("someUrl")).toEqual("someSanitizedUrl");
570+
expect($$sanitizeUri).toHaveBeenCalledOnceWith("someUrl", true);
563571

564-
expect($sce.getTrustedUrl("someUrl")).toEqual("someSanitizedUrl");
565-
expect($$sanitizeUri).toHaveBeenCalledOnceWith("someUrl", false);
566-
};
572+
$$sanitizeUri.calls.reset();
573+
574+
expect($sce.getTrustedUrl("someUrl")).toEqual("someSanitizedUrl");
575+
expect($$sanitizeUri).toHaveBeenCalledOnceWith("someUrl", false);
567576
});
568577
});
569578

src/services/sce/sce.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ export interface SceService {
5353
parseAsHtml(expression: string): (context: any, locals: any) => any;
5454
parseAsResourceUrl(expression: string): (context: any, locals: any) => any;
5555
parseAsUrl(expression: string): (context: any, locals: any) => any;
56+
parseAsMediaUrl(expression: string): (context: any, locals: any) => any;
5657
trustAs(type: string, value: any): any;
5758
trustAsHtml(value: any): any;
5859
trustAsResourceUrl(value: any): any;
5960
trustAsUrl(value: any): any;
61+
trustAsMediaUrl(value: any): any;
6062
isEnabled(): boolean;
6163
valueOf(value?: any): any;
6264
}

src/shared/utils.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe("utility functions", () => {
7979
});
8080

8181
it("should create appropriate `_hashKey`s for non-primitive values", () => {
82-
const fn = function () {};
82+
const fn = () => {};
8383
const arr = [];
8484
const obj = {};
8585
const date = new Date();
@@ -145,9 +145,7 @@ describe("utility functions", () => {
145145
});
146146

147147
it("is function:[unique id] for functions", () => {
148-
const fn = function (a) {
149-
return a;
150-
};
148+
const fn = (a) => a;
151149
expect(hashKey(fn)).toMatch(/^function:\S+$/);
152150
});
153151

@@ -186,7 +184,7 @@ describe("utility functions", () => {
186184
expect(
187185
hashKey({
188186
myKey: "42",
189-
_hashKey: function () {
187+
_hashKey() {
190188
return this.myKey;
191189
},
192190
}),

0 commit comments

Comments
 (0)