@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../src/public";
|
|
2
|
+
import { createInjector } from "../../src/injector";
|
|
3
|
+
|
|
4
|
+
describe("filter", function () {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
publishExternalAPI();
|
|
7
|
+
});
|
|
8
|
+
it("can be registered and obtained", () => {
|
|
9
|
+
var myFilter = () => {};
|
|
10
|
+
var myFilterFactory = () => {
|
|
11
|
+
return myFilter;
|
|
12
|
+
};
|
|
13
|
+
var injector = createInjector([
|
|
14
|
+
"ng",
|
|
15
|
+
function ($filterProvider) {
|
|
16
|
+
$filterProvider.register("my", myFilterFactory);
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
var $filter = injector.get("$filter");
|
|
20
|
+
expect($filter("my")).toBe(myFilter);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("allows registering multiple filters with an object", () => {
|
|
24
|
+
var myFilter = () => {};
|
|
25
|
+
var myOtherFilter = () => {};
|
|
26
|
+
var injector = createInjector([
|
|
27
|
+
"ng",
|
|
28
|
+
function ($filterProvider) {
|
|
29
|
+
$filterProvider.register({
|
|
30
|
+
my: () => {
|
|
31
|
+
return myFilter;
|
|
32
|
+
},
|
|
33
|
+
myOther: () => {
|
|
34
|
+
return myOtherFilter;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
]);
|
|
39
|
+
var $filter = injector.get("$filter");
|
|
40
|
+
expect($filter("my")).toBe(myFilter);
|
|
41
|
+
expect($filter("myOther")).toBe(myOtherFilter);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("is available through injector", () => {
|
|
45
|
+
var myFilter = () => {};
|
|
46
|
+
var injector = createInjector([
|
|
47
|
+
"ng",
|
|
48
|
+
function ($filterProvider) {
|
|
49
|
+
$filterProvider.register("my", () => {
|
|
50
|
+
return myFilter;
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
expect(injector.has("myFilter")).toBe(true);
|
|
55
|
+
expect(injector.get("myFilter")).toBe(myFilter);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("may have dependencies in factory", () => {
|
|
59
|
+
var injector = createInjector([
|
|
60
|
+
"ng",
|
|
61
|
+
function ($provide, $filterProvider) {
|
|
62
|
+
$provide.constant("suffix", "!");
|
|
63
|
+
$filterProvider.register("my", function (suffix) {
|
|
64
|
+
return function (v) {
|
|
65
|
+
return suffix + v;
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
expect(injector.has("myFilter")).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("can be registered through module API", () => {
|
|
74
|
+
var myFilter = () => {};
|
|
75
|
+
angular.module("myModule", []).filter("my", () => {
|
|
76
|
+
return myFilter;
|
|
77
|
+
});
|
|
78
|
+
var injector = createInjector(["ng", "myModule"]);
|
|
79
|
+
expect(injector.has("myFilter")).toBe(true);
|
|
80
|
+
expect(injector.get("myFilter")).toBe(myFilter);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("filter filter", function () {
|
|
85
|
+
beforeEach(function () {
|
|
86
|
+
publishExternalAPI();
|
|
87
|
+
});
|
|
88
|
+
it("is available", function () {
|
|
89
|
+
var injector = createInjector(["ng"]);
|
|
90
|
+
expect(injector.has("filterFilter")).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
// TODO
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("$filter", () => {
|
|
96
|
+
let $filterProvider;
|
|
97
|
+
let $filter;
|
|
98
|
+
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
publishExternalAPI();
|
|
101
|
+
const injector = createInjector([
|
|
102
|
+
"ng",
|
|
103
|
+
function (_$filterProvider_) {
|
|
104
|
+
$filterProvider = _$filterProvider_;
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
$filter = injector.get("$filter");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("provider", () => {
|
|
111
|
+
it("should allow registration of filters", () => {
|
|
112
|
+
const FooFilter = function () {
|
|
113
|
+
return function () {
|
|
114
|
+
return "foo";
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
$filterProvider.register("foo", FooFilter);
|
|
119
|
+
|
|
120
|
+
const fooFilter = $filter("foo");
|
|
121
|
+
expect(fooFilter()).toBe("foo");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should allow registration of a map of filters", () => {
|
|
125
|
+
const FooFilter = function () {
|
|
126
|
+
return function () {
|
|
127
|
+
return "foo";
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const BarFilter = function () {
|
|
132
|
+
return function () {
|
|
133
|
+
return "bar";
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
$filterProvider.register({
|
|
138
|
+
foo: FooFilter,
|
|
139
|
+
bar: BarFilter,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const fooFilter = $filter("foo");
|
|
143
|
+
expect(fooFilter()).toBe("foo");
|
|
144
|
+
|
|
145
|
+
const barFilter = $filter("bar");
|
|
146
|
+
expect(barFilter()).toBe("bar");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { createInjector } from "../../src/injector";
|
|
2
|
+
import { publishExternalAPI } from "../../src/public";
|
|
3
|
+
import { createHttpBackend } from "../../src/services/httpBackend";
|
|
4
|
+
import sinon from "sinon";
|
|
5
|
+
|
|
6
|
+
describe("$httpBackend", () => {
|
|
7
|
+
let $backend;
|
|
8
|
+
let $browser;
|
|
9
|
+
let xhr;
|
|
10
|
+
let callback;
|
|
11
|
+
let requests;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
xhr = sinon.useFakeXMLHttpRequest();
|
|
15
|
+
requests = [];
|
|
16
|
+
xhr.onCreate = function (req) {
|
|
17
|
+
requests.push(req);
|
|
18
|
+
};
|
|
19
|
+
publishExternalAPI();
|
|
20
|
+
let $injector = createInjector(["ng"]);
|
|
21
|
+
$browser = $injector.get("$browser");
|
|
22
|
+
xhr = sinon.useFakeXMLHttpRequest();
|
|
23
|
+
$backend = createHttpBackend(
|
|
24
|
+
$browser,
|
|
25
|
+
() => new window.XMLHttpRequest(),
|
|
26
|
+
$browser.defer,
|
|
27
|
+
);
|
|
28
|
+
callback = jasmine.createSpy("done");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
xhr.restore();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should do basics - open async xhr and send data", () => {
|
|
36
|
+
$backend("GET", "/some-url", "some-data", () => {});
|
|
37
|
+
expect(requests.length).toBe(1);
|
|
38
|
+
expect(requests[0].method).toBe("GET");
|
|
39
|
+
expect(requests[0].url).toBe("/some-url");
|
|
40
|
+
expect(requests[0].requestBody).toBe("some-data");
|
|
41
|
+
expect(requests[0].async).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should pass null to send if no body is set", () => {
|
|
45
|
+
$backend("GET", "/some-url", undefined, () => {});
|
|
46
|
+
expect(requests[0].requestBody).toBe(null);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should pass the correct falsy value to send if falsy body is set (excluding undefined, NaN)", () => {
|
|
50
|
+
[false, 0, "", null].forEach((value, index) => {
|
|
51
|
+
$backend("GET", "/some-url", value, () => {});
|
|
52
|
+
expect(requests[index].requestBody).toBe(value);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should pass NaN to send if NaN body is set", () => {
|
|
57
|
+
$backend("GET", "/some-url", NaN, () => {});
|
|
58
|
+
expect(isNaN(requests[0].requestBody)).toEqual(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should call completion function with xhr.statusText if present", () => {
|
|
62
|
+
callback.and.callFake((status, response, headers, statusText) => {
|
|
63
|
+
expect(statusText).toBe("OK");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
$backend("GET", "/some-url", null, callback);
|
|
67
|
+
requests[0].respond(200);
|
|
68
|
+
expect(callback).toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should set only the requested headers", () => {
|
|
72
|
+
$backend("POST", "URL", null, () => {}, {
|
|
73
|
+
"X-header1": "value1",
|
|
74
|
+
"X-header2": "value2",
|
|
75
|
+
});
|
|
76
|
+
expect(requests[0].requestHeaders["X-header1"]).toEqual("value1");
|
|
77
|
+
expect(requests[0].requestHeaders["X-header2"]).toEqual("value2");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should not try to read response data when request is aborted", () => {
|
|
81
|
+
callback.and.callFake((status, response, headers, statusText) => {
|
|
82
|
+
expect(status).toBe(-1);
|
|
83
|
+
expect(response).toBe(null);
|
|
84
|
+
expect(headers).toBe(null);
|
|
85
|
+
expect(statusText).toBe("");
|
|
86
|
+
});
|
|
87
|
+
$backend("GET", "/url", null, callback, {}, 2000);
|
|
88
|
+
requests[0].respond(0);
|
|
89
|
+
expect(callback).toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should complete the request on abort", () => {
|
|
93
|
+
callback.and.callFake(
|
|
94
|
+
(status, response, headers, statusText, xhrStatus) => {
|
|
95
|
+
expect(status).toBe(-1);
|
|
96
|
+
expect(response).toBe(null);
|
|
97
|
+
expect(headers).toBe(null);
|
|
98
|
+
expect(statusText).toBe("");
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
$backend("GET", "/url", null, callback, {});
|
|
102
|
+
|
|
103
|
+
expect(callback).not.toHaveBeenCalled();
|
|
104
|
+
requests[0].error();
|
|
105
|
+
expect(callback).toHaveBeenCalled();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should complete the request on error", () => {
|
|
109
|
+
callback.and.callFake(
|
|
110
|
+
(status, response, headers, statusText, xhrStatus) => {
|
|
111
|
+
expect(status).toBe(-1);
|
|
112
|
+
expect(response).toBe(null);
|
|
113
|
+
expect(headers).toBe(null);
|
|
114
|
+
expect(statusText).toBe("");
|
|
115
|
+
expect(xhrStatus).toBe("error");
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
$backend("GET", "/url", null, callback, {});
|
|
119
|
+
|
|
120
|
+
expect(callback).not.toHaveBeenCalled();
|
|
121
|
+
requests[0].error();
|
|
122
|
+
expect(callback).toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should complete the request on success", () => {
|
|
126
|
+
callback.and.callFake(
|
|
127
|
+
(status, response, headers, statusText, xhrStatus) => {
|
|
128
|
+
expect(status).toBe(200);
|
|
129
|
+
expect(response).toBe("response");
|
|
130
|
+
expect(headers).toBe("");
|
|
131
|
+
expect(statusText).toBe("OK");
|
|
132
|
+
expect(xhrStatus).toBe("complete");
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
$backend("GET", "/url", null, callback, {});
|
|
136
|
+
|
|
137
|
+
expect(callback).not.toHaveBeenCalled();
|
|
138
|
+
requests[0].respond(200, "", "response");
|
|
139
|
+
expect(callback).toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// it("should set withCredentials", () => {
|
|
143
|
+
// $backend("GET", "/some.url", null, callback, {}, null, true);
|
|
144
|
+
// expect(requests[0].withCredentials).toBeTrue();
|
|
145
|
+
// });
|
|
146
|
+
|
|
147
|
+
// it("should abort request on $timeout promise resolution", () => {
|
|
148
|
+
// callback.and.callFake(
|
|
149
|
+
// (status, response, headers, statusText, xhrStatus) => {
|
|
150
|
+
// expect(status).toBe(-1);
|
|
151
|
+
// expect(xhrStatus).toBe("timeout");
|
|
152
|
+
// },
|
|
153
|
+
// );
|
|
154
|
+
|
|
155
|
+
// $backend(
|
|
156
|
+
// "GET",
|
|
157
|
+
// "/url",
|
|
158
|
+
// null,
|
|
159
|
+
// callback,
|
|
160
|
+
// {},
|
|
161
|
+
// $timeout(() => {}, 2000),
|
|
162
|
+
// );
|
|
163
|
+
// spyOn(xhr, "abort");
|
|
164
|
+
// expect(xhr.abort).toHaveBeenCalled();
|
|
165
|
+
|
|
166
|
+
// requests[0].abort();
|
|
167
|
+
// expect(callback).toHaveBeenCalled();
|
|
168
|
+
// });
|
|
169
|
+
|
|
170
|
+
// it("should not abort resolved request on timeout promise resolution", () => {
|
|
171
|
+
// callback.and.callFake((status, response) => {
|
|
172
|
+
// expect(status).toBe(200);
|
|
173
|
+
// });
|
|
174
|
+
|
|
175
|
+
// $backend(
|
|
176
|
+
// "GET",
|
|
177
|
+
// "/url",
|
|
178
|
+
// null,
|
|
179
|
+
// callback,
|
|
180
|
+
// {},
|
|
181
|
+
// $timeout(() => {}, 2000),
|
|
182
|
+
// );
|
|
183
|
+
// xhr = MockXhr.$$lastInstance;
|
|
184
|
+
// spyOn(xhr, "abort");
|
|
185
|
+
|
|
186
|
+
// xhr.status = 200;
|
|
187
|
+
// xhr.onload();
|
|
188
|
+
// expect(callback).toHaveBeenCalled();
|
|
189
|
+
|
|
190
|
+
// $timeout.flush();
|
|
191
|
+
// expect(xhr.abort).not.toHaveBeenCalled();
|
|
192
|
+
// });
|
|
193
|
+
|
|
194
|
+
// it("should abort request on canceler promise resolution", () => {
|
|
195
|
+
// const canceler = $q.defer();
|
|
196
|
+
|
|
197
|
+
// callback.and.callFake(
|
|
198
|
+
// (status, response, headers, statusText, xhrStatus) => {
|
|
199
|
+
// expect(status).toBe(-1);
|
|
200
|
+
// expect(xhrStatus).toBe("abort");
|
|
201
|
+
// },
|
|
202
|
+
// );
|
|
203
|
+
|
|
204
|
+
// $backend("GET", "/url", null, callback, {}, canceler.promise);
|
|
205
|
+
// xhr = MockXhr.$$lastInstance;
|
|
206
|
+
|
|
207
|
+
// canceler.resolve();
|
|
208
|
+
// $browser.defer.flush();
|
|
209
|
+
|
|
210
|
+
// expect(callback).toHaveBeenCalled();
|
|
211
|
+
// });
|
|
212
|
+
|
|
213
|
+
// it("should cancel timeout on completion", () => {
|
|
214
|
+
// callback.and.callFake((status, response) => {
|
|
215
|
+
// expect(status).toBe(200);
|
|
216
|
+
// });
|
|
217
|
+
|
|
218
|
+
// $backend("GET", "/url", null, callback, {}, 2000);
|
|
219
|
+
// xhr = MockXhr.$$lastInstance;
|
|
220
|
+
// spyOn(xhr, "abort");
|
|
221
|
+
|
|
222
|
+
// expect($browser.deferredFns[0].time).toBe(2000);
|
|
223
|
+
|
|
224
|
+
// xhr.status = 200;
|
|
225
|
+
// xhr.onload();
|
|
226
|
+
// expect(callback).toHaveBeenCalled();
|
|
227
|
+
|
|
228
|
+
// expect($browser.deferredFns.length).toBe(0);
|
|
229
|
+
// expect(xhr.abort).not.toHaveBeenCalled();
|
|
230
|
+
// });
|
|
231
|
+
|
|
232
|
+
// it('should call callback with xhrStatus "abort" on explicit xhr.abort() when $timeout is set', () => {
|
|
233
|
+
// callback.and.callFake(
|
|
234
|
+
// (status, response, headers, statusText, xhrStatus) => {
|
|
235
|
+
// expect(status).toBe(-1);
|
|
236
|
+
// expect(xhrStatus).toBe("abort");
|
|
237
|
+
// },
|
|
238
|
+
// );
|
|
239
|
+
|
|
240
|
+
// $backend(
|
|
241
|
+
// "GET",
|
|
242
|
+
// "/url",
|
|
243
|
+
// null,
|
|
244
|
+
// callback,
|
|
245
|
+
// {},
|
|
246
|
+
// $timeout(() => {}, 2000),
|
|
247
|
+
// );
|
|
248
|
+
// spyOn(xhr, "abort").and.callThrough();
|
|
249
|
+
|
|
250
|
+
// xhr.abort();
|
|
251
|
+
|
|
252
|
+
// expect(callback).toHaveBeenCalled();
|
|
253
|
+
// });
|
|
254
|
+
|
|
255
|
+
it("should set up event listeners", () => {
|
|
256
|
+
const progressFn = function () {
|
|
257
|
+
"progressFn";
|
|
258
|
+
};
|
|
259
|
+
$backend("GET", "/url", null, callback, {}, null, null, null, {
|
|
260
|
+
progress: progressFn,
|
|
261
|
+
});
|
|
262
|
+
expect(requests[0].eventListeners.progress[1].listener).toBe(progressFn);
|
|
263
|
+
//expect(requests[0].eventListeners.progress[1].listener).toBe(uploadProgressFn);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// describe("responseType", () => {
|
|
267
|
+
// it("should set responseType and return xhr.response", () => {
|
|
268
|
+
// $backend("GET", "/whatever", null, callback, {}, null, null, "blob");
|
|
269
|
+
|
|
270
|
+
// const xhrInstance = MockXhr.$$lastInstance;
|
|
271
|
+
// expect(xhrInstance.responseType).toBe("blob");
|
|
272
|
+
|
|
273
|
+
// callback.and.callFake((status, response) => {
|
|
274
|
+
// expect(response).toBe(xhrInstance.response);
|
|
275
|
+
// });
|
|
276
|
+
|
|
277
|
+
// xhrInstance.response = { some: "object" };
|
|
278
|
+
// xhrInstance.onload();
|
|
279
|
+
|
|
280
|
+
// expect(callback).toHaveBeenCalled();
|
|
281
|
+
// });
|
|
282
|
+
|
|
283
|
+
// it("should read responseText if response was not defined", () => {
|
|
284
|
+
// // old browsers like IE9, don't support responseType, so they always respond with responseText
|
|
285
|
+
|
|
286
|
+
// $backend("GET", "/whatever", null, callback, {}, null, null, "blob");
|
|
287
|
+
|
|
288
|
+
// const xhrInstance = MockXhr.$$lastInstance;
|
|
289
|
+
// const responseText = '{"some": "object"}';
|
|
290
|
+
// expect(xhrInstance.responseType).toBe("blob");
|
|
291
|
+
|
|
292
|
+
// callback.and.callFake((status, response) => {
|
|
293
|
+
// expect(response).toBe(responseText);
|
|
294
|
+
// });
|
|
295
|
+
|
|
296
|
+
// xhrInstance.responseText = responseText;
|
|
297
|
+
// xhrInstance.onload();
|
|
298
|
+
|
|
299
|
+
// expect(callback).toHaveBeenCalled();
|
|
300
|
+
// });
|
|
301
|
+
// });
|
|
302
|
+
|
|
303
|
+
// describe("protocols that return 0 status code", () => {
|
|
304
|
+
// function respond(status, content) {
|
|
305
|
+
// xhr = MockXhr.$$lastInstance;
|
|
306
|
+
// xhr.status = status;
|
|
307
|
+
// xhr.responseText = content;
|
|
308
|
+
// xhr.onload();
|
|
309
|
+
// }
|
|
310
|
+
|
|
311
|
+
// beforeEach(() => {
|
|
312
|
+
// $backend = createHttpBackend($browser, createMockXhr);
|
|
313
|
+
// });
|
|
314
|
+
|
|
315
|
+
// it("should convert 0 to 200 if content and file protocol", () => {
|
|
316
|
+
// $backend("GET", "file:///whatever/index.html", null, callback);
|
|
317
|
+
// respond(0, "SOME CONTENT");
|
|
318
|
+
|
|
319
|
+
// expect(callback).toHaveBeenCalled();
|
|
320
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(200);
|
|
321
|
+
// });
|
|
322
|
+
|
|
323
|
+
// it("should convert 0 to 200 if content for protocols other than file", () => {
|
|
324
|
+
// $backend("GET", "someProtocol:///whatever/index.html", null, callback);
|
|
325
|
+
// respond(0, "SOME CONTENT");
|
|
326
|
+
|
|
327
|
+
// expect(callback).toHaveBeenCalled();
|
|
328
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(200);
|
|
329
|
+
// });
|
|
330
|
+
|
|
331
|
+
// it("should convert 0 to 404 if no content and file protocol", () => {
|
|
332
|
+
// $backend("GET", "file:///whatever/index.html", null, callback);
|
|
333
|
+
// respond(0, "");
|
|
334
|
+
|
|
335
|
+
// expect(callback).toHaveBeenCalled();
|
|
336
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(404);
|
|
337
|
+
// });
|
|
338
|
+
|
|
339
|
+
// it("should not convert 0 to 404 if no content for protocols other than file", () => {
|
|
340
|
+
// $backend("GET", "someProtocol:///whatever/index.html", null, callback);
|
|
341
|
+
// respond(0, "");
|
|
342
|
+
|
|
343
|
+
// expect(callback).toHaveBeenCalled();
|
|
344
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(0);
|
|
345
|
+
// });
|
|
346
|
+
|
|
347
|
+
// it("should convert 0 to 404 if no content - relative url", () => {
|
|
348
|
+
// /* global urlParsingNode: true */
|
|
349
|
+
// const originalUrlParsingNode = urlParsingNode;
|
|
350
|
+
|
|
351
|
+
// // temporarily overriding the DOM element to pretend that the test runs origin with file:// protocol
|
|
352
|
+
// urlParsingNode = {
|
|
353
|
+
// hash: "#/C:/",
|
|
354
|
+
// host: "",
|
|
355
|
+
// hostname: "",
|
|
356
|
+
// href: "file:///C:/base#!/C:/foo",
|
|
357
|
+
// pathname: "/C:/foo",
|
|
358
|
+
// port: "",
|
|
359
|
+
// protocol: "file:",
|
|
360
|
+
// search: "",
|
|
361
|
+
// setAttribute: () => {},
|
|
362
|
+
// };
|
|
363
|
+
|
|
364
|
+
// try {
|
|
365
|
+
// $backend("GET", "/whatever/index.html", null, callback);
|
|
366
|
+
// respond(0, "");
|
|
367
|
+
|
|
368
|
+
// expect(callback).toHaveBeenCalled();
|
|
369
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(404);
|
|
370
|
+
// } finally {
|
|
371
|
+
// urlParsingNode = originalUrlParsingNode;
|
|
372
|
+
// }
|
|
373
|
+
// });
|
|
374
|
+
|
|
375
|
+
// it("should return original backend status code if different from 0", () => {
|
|
376
|
+
// // request to http://
|
|
377
|
+
// $backend("POST", "http://rest_api/create_whatever", null, callback);
|
|
378
|
+
// respond(201, "");
|
|
379
|
+
|
|
380
|
+
// expect(callback).toHaveBeenCalled();
|
|
381
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(201);
|
|
382
|
+
|
|
383
|
+
// // request to file://
|
|
384
|
+
// $backend("POST", "file://rest_api/create_whatever", null, callback);
|
|
385
|
+
// respond(201, "");
|
|
386
|
+
|
|
387
|
+
// expect(callback).toHaveBeenCalled();
|
|
388
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(201);
|
|
389
|
+
|
|
390
|
+
// // request to file:// with HTTP status >= 300
|
|
391
|
+
// $backend("POST", "file://rest_api/create_whatever", null, callback);
|
|
392
|
+
// respond(503, "");
|
|
393
|
+
|
|
394
|
+
// expect(callback).toHaveBeenCalled();
|
|
395
|
+
// expect(callback.calls.mostRecent().args[0]).toBe(503);
|
|
396
|
+
// });
|
|
397
|
+
// });
|
|
398
|
+
});
|