@angular-wave/angular.ts 0.9.3 → 0.9.5

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.
Files changed (703) hide show
  1. package/@types/angular.d.ts +4 -19
  2. package/@types/animations/animate.d.ts +2 -2
  3. package/@types/animations/animation.d.ts +1 -1
  4. package/@types/core/compile/attributes.d.ts +1 -1
  5. package/@types/core/compile/compile.d.ts +2 -2
  6. package/@types/core/controller/controller.d.ts +1 -1
  7. package/@types/core/controller/interface.d.ts +6 -0
  8. package/@types/core/di/ng-module.d.ts +27 -26
  9. package/@types/core/filter/filter.d.ts +5 -5
  10. package/@types/core/interpolate/interface.d.ts +13 -0
  11. package/@types/core/interpolate/interpolate.d.ts +1 -13
  12. package/@types/core/scope/scope.d.ts +4 -1
  13. package/@types/directive/http/http.d.ts +16 -16
  14. package/@types/directive/http/interface.d.ts +27 -0
  15. package/@types/directive/include/include.d.ts +4 -4
  16. package/@types/directive/inject/inject.d.ts +12 -0
  17. package/@types/directive/model/model.d.ts +1 -1
  18. package/@types/directive/script/script.d.ts +2 -2
  19. package/@types/directive/setter/setter.d.ts +4 -4
  20. package/@types/filters/filter.d.ts +2 -2
  21. package/@types/filters/filters.d.ts +2 -2
  22. package/@types/filters/interface.d.ts +8 -0
  23. package/@types/filters/limit-to.d.ts +2 -2
  24. package/@types/filters/order-by.d.ts +2 -2
  25. package/@types/interface.d.ts +105 -82
  26. package/@types/namespace.d.ts +76 -0
  27. package/@types/router/state/interface.d.ts +8 -8
  28. package/@types/router/state-filters.d.ts +4 -4
  29. package/@types/router/template-factory.d.ts +8 -8
  30. package/@types/router/transition/hook-builder.d.ts +5 -2
  31. package/@types/router/transition/hook-registry.d.ts +11 -2
  32. package/@types/router/transition/transition-service.d.ts +6 -2
  33. package/@types/router/transition/transition.d.ts +2 -2
  34. package/@types/router/view/view.d.ts +1 -8
  35. package/@types/router/view-scroll.d.ts +4 -2
  36. package/@types/services/{anchor-scroll.d.ts → anchor-scroll/anchor-scroll.d.ts} +2 -2
  37. package/@types/services/exception/exception-handler.d.ts +2 -2
  38. package/@types/services/exception/interface.d.ts +1 -1
  39. package/@types/services/http/http.d.ts +40 -2
  40. package/@types/services/http/interface.d.ts +11 -0
  41. package/@types/services/location/location.d.ts +1 -4
  42. package/@types/services/sce/sce.d.ts +3 -4
  43. package/@types/services/template-cache/template-cache.d.ts +4 -4
  44. package/@types/services/template-request/interface.d.ts +22 -0
  45. package/@types/services/{template-request.d.ts → template-request/template-request.d.ts} +4 -7
  46. package/@types/shared/common.d.ts +8 -69
  47. package/@types/shared/hof.d.ts +7 -7
  48. package/dist/angular-ts.esm.js +510 -570
  49. package/dist/angular-ts.umd.js +510 -570
  50. package/dist/angular-ts.umd.min.js +1 -1
  51. package/package.json +8 -1
  52. package/.github/workflows/ci.yml +0 -104
  53. package/.github/workflows/gh-pages.yml +0 -75
  54. package/.husky/pre-commit +0 -5
  55. package/.prettierignore +0 -9
  56. package/@types/services/cookie-reader.d.ts +0 -4
  57. package/@types/services/http-backend/http-backend.d.ts +0 -58
  58. package/@types/services/template-cache/interface.d.ts +0 -10
  59. package/CHANGELOG.md +0 -17667
  60. package/CODE_OF_CONDUCT.md +0 -3
  61. package/CONTRIBUTING.md +0 -247
  62. package/DEVELOPERS.md +0 -499
  63. package/Makefile +0 -60
  64. package/RELEASE.md +0 -86
  65. package/TRIAGING.md +0 -127
  66. package/docs/.cspell.yml +0 -8
  67. package/docs/.github/dependabot.yml +0 -14
  68. package/docs/.nvmrc +0 -1
  69. package/docs/CONTRIBUTING.md +0 -28
  70. package/docs/Dockerfile +0 -4
  71. package/docs/LICENSE +0 -201
  72. package/docs/README.md +0 -217
  73. package/docs/assets/icons/logo.svg +0 -1
  74. package/docs/assets/scss/_variables_project.scss +0 -12
  75. package/docs/assets/scss/_variables_project_after_bs.scss +0 -8
  76. package/docs/assets/scss/index.scss +0 -48
  77. package/docs/config.yaml +0 -15
  78. package/docs/content/_index.md +0 -28
  79. package/docs/content/docs/_index.md +0 -61
  80. package/docs/content/docs/directive/_index.md +0 -4
  81. package/docs/content/docs/directive/app.md +0 -11
  82. package/docs/content/docs/directive/aria.md +0 -0
  83. package/docs/content/docs/directive/bind.md +0 -72
  84. package/docs/content/docs/directive/blur.md +0 -38
  85. package/docs/content/docs/directive/channel.md +0 -37
  86. package/docs/content/docs/directive/class-even.md +0 -47
  87. package/docs/content/docs/directive/class-odd.md +0 -48
  88. package/docs/content/docs/directive/class.md +0 -64
  89. package/docs/content/docs/directive/click.md +0 -41
  90. package/docs/content/docs/directive/cloak.md +0 -74
  91. package/docs/content/docs/directive/copy.md +0 -38
  92. package/docs/content/docs/directive/cut.md +0 -40
  93. package/docs/content/docs/directive/dblclick.md +0 -41
  94. package/docs/content/docs/directive/focus.md +0 -38
  95. package/docs/content/docs/directive/get.md +0 -203
  96. package/docs/content/docs/directive/include.md +0 -7
  97. package/docs/content/docs/directive/keydown.md +0 -38
  98. package/docs/content/docs/directive/keyup.md +0 -38
  99. package/docs/content/docs/directive/load.md +0 -43
  100. package/docs/content/docs/directive/mousedown.md +0 -38
  101. package/docs/content/docs/directive/mouseenter.md +0 -38
  102. package/docs/content/docs/directive/mouseleave.md +0 -38
  103. package/docs/content/docs/directive/mousemove.md +0 -38
  104. package/docs/content/docs/directive/mouseout.md +0 -38
  105. package/docs/content/docs/directive/mouseover.md +0 -38
  106. package/docs/content/docs/directive/mouseup.md +0 -38
  107. package/docs/content/docs/directive/non-bindable.md +0 -28
  108. package/docs/content/docs/filter/_index.md +0 -4
  109. package/docs/content/docs/provider/_index.md +0 -4
  110. package/docs/content/docs/provider/eventBusProvider.md +0 -35
  111. package/docs/content/docs/provider/locationProvider.md +0 -26
  112. package/docs/content/docs/provider/logProvider.md +0 -59
  113. package/docs/content/docs/provider/templateCacheProvider.md +0 -100
  114. package/docs/content/docs/service/_index.md +0 -4
  115. package/docs/content/docs/service/eventBus.md +0 -56
  116. package/docs/content/docs/service/location.md +0 -57
  117. package/docs/content/docs/service/log.md +0 -113
  118. package/docs/content/docs/service/templateCache.md +0 -64
  119. package/docs/content/docs/service/url.md +0 -5
  120. package/docs/docker-compose.yaml +0 -12
  121. package/docs/docsy.work +0 -5
  122. package/docs/docsy.work.sum +0 -0
  123. package/docs/go.mod +0 -5
  124. package/docs/go.sum +0 -6
  125. package/docs/hugo-disabled.toml +0 -220
  126. package/docs/hugo.yaml +0 -200
  127. package/docs/layouts/404.html +0 -13
  128. package/docs/layouts/_markup/render-heading.html +0 -1
  129. package/docs/layouts/partials/hooks/head-end.html +0 -3
  130. package/docs/layouts/shortcodes/showcss.html +0 -2
  131. package/docs/layouts/shortcodes/showhtml.html +0 -2
  132. package/docs/layouts/shortcodes/showjs.html +0 -2
  133. package/docs/layouts/shortcodes/showraw.html +0 -1
  134. package/docs/layouts/shortcodes/version.html +0 -1
  135. package/docs/package-lock.json +0 -2293
  136. package/docs/package.json +0 -53
  137. package/docs/static/examples/counter/counter-test.html +0 -13
  138. package/docs/static/examples/counter/counter.html +0 -5
  139. package/docs/static/examples/counter/counter.test.js +0 -28
  140. package/docs/static/examples/eventbus/eventbus-test.html +0 -15
  141. package/docs/static/examples/eventbus/eventbus.html +0 -13
  142. package/docs/static/examples/eventbus/eventbus.js +0 -15
  143. package/docs/static/examples/eventbus/eventbus.test.js +0 -19
  144. package/docs/static/examples/ng-bind/ng-bind.html +0 -9
  145. package/docs/static/examples/ng-blur/ng-blur.html +0 -9
  146. package/docs/static/examples/ng-channel/ng-channel-test.html +0 -17
  147. package/docs/static/examples/ng-channel/ng-channel.html +0 -24
  148. package/docs/static/examples/ng-channel/ng-channel.test.js +0 -31
  149. package/docs/static/examples/ng-class/ng-class.html +0 -71
  150. package/docs/static/examples/ng-class-even/ng-class-even.html +0 -8
  151. package/docs/static/examples/ng-class-odd/ng-class-odd.html +0 -8
  152. package/docs/static/examples/ng-click/ng-click.html +0 -6
  153. package/docs/static/examples/ng-copy/ng-copy.html +0 -6
  154. package/docs/static/examples/ng-cut/ng-cut.html +0 -6
  155. package/docs/static/examples/ng-dblclick/ng-dblclick.html +0 -10
  156. package/docs/static/examples/ng-focus/ng-focus.html +0 -9
  157. package/docs/static/examples/ng-keydown/ng-keydown.html +0 -9
  158. package/docs/static/examples/ng-keyup/ng-keyup.html +0 -9
  159. package/docs/static/examples/ng-load/ng-load.html +0 -8
  160. package/docs/static/examples/ng-mousedown/ng-mousedown.html +0 -6
  161. package/docs/static/examples/ng-mouseenter/ng-mouseenter.html +0 -4
  162. package/docs/static/examples/ng-mouseleave/ng-mouseleave.html +0 -4
  163. package/docs/static/examples/ng-mousemove/ng-mousemove.html +0 -4
  164. package/docs/static/examples/ng-mouseout/ng-mouseout.html +0 -4
  165. package/docs/static/examples/ng-mouseover/ng-mouseover.html +0 -4
  166. package/docs/static/examples/ng-mouseup/ng-mouseup.html +0 -4
  167. package/docs/static/examples/ng-non-bindable/ng-non-bindable-test.html +0 -13
  168. package/docs/static/examples/ng-non-bindable/ng-non-bindable.html +0 -3
  169. package/docs/static/examples/ng-non-bindable/ng-non-bindable.test.js +0 -11
  170. package/docs/static/typedoc/.nojekyll +0 -1
  171. package/docs/static/typedoc/assets/hierarchy.js +0 -1
  172. package/docs/static/typedoc/assets/highlight.css +0 -78
  173. package/docs/static/typedoc/assets/icons.js +0 -18
  174. package/docs/static/typedoc/assets/icons.svg +0 -1
  175. package/docs/static/typedoc/assets/main.js +0 -60
  176. package/docs/static/typedoc/assets/navigation.js +0 -1
  177. package/docs/static/typedoc/assets/search.js +0 -1
  178. package/docs/static/typedoc/assets/style.css +0 -1633
  179. package/docs/static/typedoc/classes/Location.html +0 -55
  180. package/docs/static/typedoc/classes/LocationProvider.html +0 -20
  181. package/docs/static/typedoc/classes/LogProvider.html +0 -6
  182. package/docs/static/typedoc/classes/PubSub.html +0 -71
  183. package/docs/static/typedoc/classes/PubSubProvider.html +0 -3
  184. package/docs/static/typedoc/classes/TemplateCacheProvider.html +0 -5
  185. package/docs/static/typedoc/hierarchy.html +0 -1
  186. package/docs/static/typedoc/index.html +0 -1
  187. package/docs/static/typedoc/interfaces/ChangesObject.html +0 -6
  188. package/docs/static/typedoc/interfaces/ComponentOptions.html +0 -16
  189. package/docs/static/typedoc/interfaces/Controller.html +0 -12
  190. package/docs/static/typedoc/interfaces/DefaultPorts.html +0 -5
  191. package/docs/static/typedoc/interfaces/Directive.html +0 -37
  192. package/docs/static/typedoc/interfaces/DirectivePrePost.html +0 -4
  193. package/docs/static/typedoc/interfaces/Html5Mode.html +0 -23
  194. package/docs/static/typedoc/interfaces/HttpHeadersGetter.html +0 -1
  195. package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +0 -31
  196. package/docs/static/typedoc/interfaces/HttpRequestConfigHeaders.html +0 -6
  197. package/docs/static/typedoc/interfaces/HttpRequestTransformer.html +0 -1
  198. package/docs/static/typedoc/interfaces/HttpResponse.html +0 -7
  199. package/docs/static/typedoc/interfaces/HttpResponseTransformer.html +0 -1
  200. package/docs/static/typedoc/interfaces/HttpService.html +0 -38
  201. package/docs/static/typedoc/interfaces/LogService.html +0 -12
  202. package/docs/static/typedoc/interfaces/NgModelController.html +0 -30
  203. package/docs/static/typedoc/interfaces/NgModelOptions.html +0 -16
  204. package/docs/static/typedoc/interfaces/Provider.html +0 -34
  205. package/docs/static/typedoc/interfaces/RequestConfig.html +0 -48
  206. package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +0 -38
  207. package/docs/static/typedoc/interfaces/ServiceProvider.html +0 -5
  208. package/docs/static/typedoc/interfaces/TemplateCache.html +0 -7
  209. package/docs/static/typedoc/interfaces/TranscludeFunctionObject.html +0 -8
  210. package/docs/static/typedoc/interfaces/UrlParts.html +0 -9
  211. package/docs/static/typedoc/types/AnnotatedDirectiveFactory.html +0 -1
  212. package/docs/static/typedoc/types/AnnotatedFactory.html +0 -8
  213. package/docs/static/typedoc/types/CloneAttachFunction.html +0 -2
  214. package/docs/static/typedoc/types/ControllerConstructor.html +0 -2
  215. package/docs/static/typedoc/types/DirectiveCompileFn.html +0 -2
  216. package/docs/static/typedoc/types/DirectiveController.html +0 -2
  217. package/docs/static/typedoc/types/DirectiveFactory.html +0 -1
  218. package/docs/static/typedoc/types/DirectiveFactoryFn.html +0 -1
  219. package/docs/static/typedoc/types/DirectiveLinkFn.html +0 -2
  220. package/docs/static/typedoc/types/ExpandoStore.html +0 -2
  221. package/docs/static/typedoc/types/Expression.html +0 -6
  222. package/docs/static/typedoc/types/FilterFactory.html +0 -2
  223. package/docs/static/typedoc/types/FilterFn.html +0 -2
  224. package/docs/static/typedoc/types/HttpPromise.html +0 -1
  225. package/docs/static/typedoc/types/HttpResponseStatus.html +0 -1
  226. package/docs/static/typedoc/types/Injectable.html +0 -4
  227. package/docs/static/typedoc/types/InjectableClass.html +0 -1
  228. package/docs/static/typedoc/types/InjectableFactory.html +0 -1
  229. package/docs/static/typedoc/types/LogCall.html +0 -2
  230. package/docs/static/typedoc/types/LogServiceFactory.html +0 -2
  231. package/docs/static/typedoc/types/OnChangesObject.html +0 -2
  232. package/docs/static/typedoc/types/SwapModeType.html +0 -2
  233. package/docs/static/typedoc/types/TController.html +0 -2
  234. package/docs/static/typedoc/types/UrlChangeListener.html +0 -5
  235. package/docs/static/typedoc/variables/EventBus.html +0 -1
  236. package/docs/static/typedoc/variables/SwapMode.html +0 -11
  237. package/docs/static/version.js +0 -13
  238. package/docs/test-results/.last-run.json +0 -4
  239. package/docs/test-results/static-examples-counter-counter-counter-example/error-context.md +0 -50
  240. package/eslint.config.js +0 -26
  241. package/images/android-chrome-192x192.png +0 -0
  242. package/images/android-chrome-512x512.png +0 -0
  243. package/images/apple-touch-icon.png +0 -0
  244. package/images/favicon-16x16.png +0 -0
  245. package/images/favicon-32x32.png +0 -0
  246. package/images/favicon.ico +0 -0
  247. package/images/site.webmanifest +0 -19
  248. package/index.html +0 -86
  249. package/legacy.d.ts +0 -2599
  250. package/playwright.config.ts +0 -81
  251. package/public/jasmine/boot0.js +0 -66
  252. package/public/jasmine/boot1.js +0 -134
  253. package/public/jasmine/jasmine-html.js +0 -970
  254. package/public/jasmine/jasmine.css +0 -323
  255. package/public/jasmine/jasmine.js +0 -11406
  256. package/public/public/README.md +0 -1
  257. package/public/public/circle.html +0 -1
  258. package/public/public/jasmine-helper.css +0 -9
  259. package/public/public/my_child_directive.html +0 -1
  260. package/public/public/my_directive.html +0 -1
  261. package/public/public/my_other_directive.html +0 -1
  262. package/public/public/test.html +0 -1
  263. package/rollup.config.js +0 -51
  264. package/src/angular.js +0 -293
  265. package/src/angular.spec.js +0 -1191
  266. package/src/animations/animate-cache.js +0 -80
  267. package/src/animations/animate-children-directive.js +0 -32
  268. package/src/animations/animate-children-directive.md +0 -80
  269. package/src/animations/animate-css-driver.js +0 -284
  270. package/src/animations/animate-css.html +0 -58
  271. package/src/animations/animate-css.js +0 -915
  272. package/src/animations/animate-css.md +0 -263
  273. package/src/animations/animate-js-driver.js +0 -60
  274. package/src/animations/animate-js.html +0 -47
  275. package/src/animations/animate-js.js +0 -371
  276. package/src/animations/animate-queue.js +0 -859
  277. package/src/animations/animate-runner.js +0 -193
  278. package/src/animations/animate-swap.js +0 -33
  279. package/src/animations/animate-swap.md +0 -88
  280. package/src/animations/animate.html +0 -19
  281. package/src/animations/animate.js +0 -546
  282. package/src/animations/animate.md +0 -933
  283. package/src/animations/animate.spec.js +0 -490
  284. package/src/animations/animation.js +0 -519
  285. package/src/animations/animations.test.js +0 -10
  286. package/src/animations/interface.ts +0 -19
  287. package/src/animations/raf-scheduler.html +0 -19
  288. package/src/animations/raf-scheduler.js +0 -92
  289. package/src/animations/raf-scheduler.spec.js +0 -98
  290. package/src/animations/shared.js +0 -341
  291. package/src/binding.html +0 -19
  292. package/src/binding.spec.js +0 -474
  293. package/src/binding.test.js +0 -10
  294. package/src/core/compile/attributes.js +0 -337
  295. package/src/core/compile/compile.html +0 -19
  296. package/src/core/compile/compile.js +0 -3270
  297. package/src/core/compile/compile.md +0 -1128
  298. package/src/core/compile/compile.spec.js +0 -15574
  299. package/src/core/compile/compile.test.js +0 -12
  300. package/src/core/controller/controller.html +0 -22
  301. package/src/core/controller/controller.js +0 -189
  302. package/src/core/controller/controller.spec.js +0 -334
  303. package/src/core/controller/controller.test.js +0 -12
  304. package/src/core/core.html +0 -20
  305. package/src/core/core.test.js +0 -12
  306. package/src/core/di/injector.html +0 -19
  307. package/src/core/di/injector.js +0 -307
  308. package/src/core/di/injector.md +0 -740
  309. package/src/core/di/injector.spec.js +0 -2310
  310. package/src/core/di/injector.test.js +0 -12
  311. package/src/core/di/internal-injector.js +0 -284
  312. package/src/core/di/ng-module.html +0 -19
  313. package/src/core/di/ng-module.js +0 -226
  314. package/src/core/di/ng-module.spec.js +0 -263
  315. package/src/core/di/ng-module.test.js +0 -12
  316. package/src/core/filter/filter.html +0 -19
  317. package/src/core/filter/filter.js +0 -55
  318. package/src/core/filter/filter.md +0 -132
  319. package/src/core/filter/filter.spec.js +0 -149
  320. package/src/core/filter/filter.test.js +0 -12
  321. package/src/core/interpolate/interpolate.html +0 -22
  322. package/src/core/interpolate/interpolate.js +0 -408
  323. package/src/core/interpolate/interpolate.spec.js +0 -601
  324. package/src/core/interpolate/interpolate.test.js +0 -12
  325. package/src/core/parse/ast/ast-node.ts +0 -81
  326. package/src/core/parse/ast/ast.html +0 -19
  327. package/src/core/parse/ast/ast.js +0 -574
  328. package/src/core/parse/ast/ast.spec.js +0 -1453
  329. package/src/core/parse/ast/ast.test.js +0 -10
  330. package/src/core/parse/ast-type.js +0 -23
  331. package/src/core/parse/interface.ts +0 -84
  332. package/src/core/parse/interpreter.js +0 -915
  333. package/src/core/parse/lexer/lexer.html +0 -19
  334. package/src/core/parse/lexer/lexer.js +0 -338
  335. package/src/core/parse/lexer/lexer.spec.js +0 -303
  336. package/src/core/parse/lexer/lexer.test.js +0 -10
  337. package/src/core/parse/lexer/token.ts +0 -22
  338. package/src/core/parse/parse.html +0 -19
  339. package/src/core/parse/parse.js +0 -337
  340. package/src/core/parse/parse.md +0 -57
  341. package/src/core/parse/parse.spec.js +0 -2107
  342. package/src/core/parse/parse.test.js +0 -10
  343. package/src/core/parse/parser/parser.html +0 -19
  344. package/src/core/parse/parser/parser.js +0 -64
  345. package/src/core/parse/parser/parser.spec.js +0 -8
  346. package/src/core/parse/parser/parser.test.js +0 -10
  347. package/src/core/prop.spec.js +0 -775
  348. package/src/core/root-element.spec.js +0 -14
  349. package/src/core/sanitize/interface.ts +0 -10
  350. package/src/core/sanitize/sanitize-uri.js +0 -75
  351. package/src/core/sanitize/sanitize-uri.spec.js +0 -249
  352. package/src/core/sanitize/sanitize-uri.test.js +0 -12
  353. package/src/core/sanitize/sanitize.html +0 -22
  354. package/src/core/scope/scope.html +0 -19
  355. package/src/core/scope/scope.js +0 -1249
  356. package/src/core/scope/scope.spec.js +0 -3000
  357. package/src/core/scope/scope.test.js +0 -12
  358. package/src/directive/aria/aria.html +0 -19
  359. package/src/directive/aria/aria.js +0 -382
  360. package/src/directive/aria/aria.md +0 -145
  361. package/src/directive/aria/aria.spec.js +0 -1241
  362. package/src/directive/aria/aria.test.js +0 -12
  363. package/src/directive/attrs/attrs.html +0 -19
  364. package/src/directive/attrs/attrs.js +0 -106
  365. package/src/directive/attrs/attrs.md +0 -224
  366. package/src/directive/attrs/attrs.spec.js +0 -71
  367. package/src/directive/attrs/attrs.test.js +0 -12
  368. package/src/directive/attrs/boolean.html +0 -19
  369. package/src/directive/attrs/boolean.spec.js +0 -137
  370. package/src/directive/attrs/boolean.test.js +0 -12
  371. package/src/directive/attrs/element-style.html +0 -22
  372. package/src/directive/attrs/element-style.spec.js +0 -85
  373. package/src/directive/attrs/element-style.test.js +0 -12
  374. package/src/directive/attrs/src.html +0 -19
  375. package/src/directive/attrs/src.spec.js +0 -163
  376. package/src/directive/attrs/src.test.js +0 -12
  377. package/src/directive/bind/bind-html.spec.js +0 -36
  378. package/src/directive/bind/bind.html +0 -20
  379. package/src/directive/bind/bind.js +0 -78
  380. package/src/directive/bind/bind.md +0 -142
  381. package/src/directive/bind/bind.spec.js +0 -314
  382. package/src/directive/bind/bind.test.js +0 -12
  383. package/src/directive/channel/channel.html +0 -19
  384. package/src/directive/channel/channel.js +0 -30
  385. package/src/directive/channel/channel.spec.js +0 -67
  386. package/src/directive/channel/channel.test.js +0 -10
  387. package/src/directive/class/class-test.html +0 -23
  388. package/src/directive/class/class.html +0 -19
  389. package/src/directive/class/class.js +0 -184
  390. package/src/directive/class/class.spec.js +0 -704
  391. package/src/directive/class/class.test.js +0 -12
  392. package/src/directive/cloak/cloak.html +0 -19
  393. package/src/directive/cloak/cloak.js +0 -11
  394. package/src/directive/cloak/cloak.spec.js +0 -44
  395. package/src/directive/cloak/cloak.test.js +0 -12
  396. package/src/directive/controller/controller.html +0 -22
  397. package/src/directive/controller/controller.js +0 -11
  398. package/src/directive/controller/controller.md +0 -46
  399. package/src/directive/controller/controller.spec.js +0 -175
  400. package/src/directive/controller/controller.test.js +0 -12
  401. package/src/directive/events/click.spec.js +0 -35
  402. package/src/directive/events/event.spec.js +0 -267
  403. package/src/directive/events/events-test.html +0 -36
  404. package/src/directive/events/events.html +0 -20
  405. package/src/directive/events/events.js +0 -65
  406. package/src/directive/events/events.md +0 -125
  407. package/src/directive/events/events.test.js +0 -12
  408. package/src/directive/form/form.html +0 -19
  409. package/src/directive/form/form.js +0 -669
  410. package/src/directive/form/form.spec.js +0 -1515
  411. package/src/directive/form/form.test.js +0 -12
  412. package/src/directive/http/delete.spec.js +0 -26
  413. package/src/directive/http/form-router-test.html +0 -44
  414. package/src/directive/http/form-test.html +0 -18
  415. package/src/directive/http/get.spec.js +0 -488
  416. package/src/directive/http/http.html +0 -22
  417. package/src/directive/http/http.js +0 -342
  418. package/src/directive/http/http.test.js +0 -12
  419. package/src/directive/http/post-example.html +0 -30
  420. package/src/directive/http/post.spec.js +0 -521
  421. package/src/directive/http/put.spec.js +0 -26
  422. package/src/directive/if/if-animate-css.html +0 -57
  423. package/src/directive/if/if-animate-svg.html +0 -25
  424. package/src/directive/if/if.html +0 -19
  425. package/src/directive/if/if.js +0 -72
  426. package/src/directive/if/if.md +0 -76
  427. package/src/directive/if/if.spec.js +0 -293
  428. package/src/directive/if/if.test.js +0 -114
  429. package/src/directive/include/include.html +0 -19
  430. package/src/directive/include/include.js +0 -151
  431. package/src/directive/include/include.md +0 -87
  432. package/src/directive/include/include.spec.js +0 -734
  433. package/src/directive/include/include.test.js +0 -12
  434. package/src/directive/init/init.html +0 -19
  435. package/src/directive/init/init.js +0 -22
  436. package/src/directive/init/init.md +0 -41
  437. package/src/directive/init/init.spec.js +0 -68
  438. package/src/directive/init/init.test.js +0 -12
  439. package/src/directive/input/input-example.html +0 -15
  440. package/src/directive/input/input.html +0 -19
  441. package/src/directive/input/input.js +0 -1078
  442. package/src/directive/input/input.md +0 -706
  443. package/src/directive/input/input.spec.js +0 -3700
  444. package/src/directive/input/input.test.js +0 -12
  445. package/src/directive/messages/messages.html +0 -22
  446. package/src/directive/messages/messages.js +0 -349
  447. package/src/directive/messages/messages.md +0 -543
  448. package/src/directive/messages/messages.spec.js +0 -1083
  449. package/src/directive/messages/messages.test.js +0 -12
  450. package/src/directive/model/change.md +0 -25
  451. package/src/directive/model/model.html +0 -19
  452. package/src/directive/model/model.js +0 -1170
  453. package/src/directive/model/model.spec.js +0 -1976
  454. package/src/directive/model/model.test.js +0 -12
  455. package/src/directive/model-options/model-option.test.js +0 -12
  456. package/src/directive/model-options/model-options.html +0 -22
  457. package/src/directive/model-options/model-options.js +0 -142
  458. package/src/directive/model-options/model-options.md +0 -407
  459. package/src/directive/model-options/model-options.spec.js +0 -1022
  460. package/src/directive/non-bindable/non-bindable.html +0 -22
  461. package/src/directive/non-bindable/non-bindable.js +0 -9
  462. package/src/directive/non-bindable/non-bindable.spec.js +0 -59
  463. package/src/directive/non-bindable/non-bindable.test.js +0 -12
  464. package/src/directive/observe/observe-demo.html +0 -184
  465. package/src/directive/observe/observe.html +0 -19
  466. package/src/directive/observe/observe.js +0 -41
  467. package/src/directive/observe/observe.spec.js +0 -106
  468. package/src/directive/observe/observe.test.js +0 -10
  469. package/src/directive/on/on.html +0 -19
  470. package/src/directive/on/on.spec.js +0 -215
  471. package/src/directive/on/on.test.js +0 -12
  472. package/src/directive/options/options-example.html +0 -17
  473. package/src/directive/options/options.html +0 -22
  474. package/src/directive/options/options.js +0 -542
  475. package/src/directive/options/options.md +0 -179
  476. package/src/directive/options/options.spec.js +0 -3554
  477. package/src/directive/options/options.test.js +0 -12
  478. package/src/directive/ref/href.html +0 -19
  479. package/src/directive/ref/href.spec.js +0 -141
  480. package/src/directive/ref/href.test.js +0 -19
  481. package/src/directive/ref/ref.html +0 -19
  482. package/src/directive/ref/ref.js +0 -89
  483. package/src/directive/ref/ref.spec.js +0 -546
  484. package/src/directive/repeat/repeat.html +0 -19
  485. package/src/directive/repeat/repeat.js +0 -333
  486. package/src/directive/repeat/repeat.md +0 -330
  487. package/src/directive/repeat/repeat.spec.js +0 -1209
  488. package/src/directive/repeat/repeat.test.js +0 -12
  489. package/src/directive/script/script.html +0 -19
  490. package/src/directive/script/script.js +0 -17
  491. package/src/directive/script/script.md +0 -11
  492. package/src/directive/script/script.spec.js +0 -47
  493. package/src/directive/script/script.test.js +0 -12
  494. package/src/directive/select/select.html +0 -19
  495. package/src/directive/select/select.js +0 -594
  496. package/src/directive/select/select.md +0 -74
  497. package/src/directive/select/select.spec.js +0 -2566
  498. package/src/directive/select/select.test.js +0 -12
  499. package/src/directive/setter/setter.html +0 -19
  500. package/src/directive/setter/setter.js +0 -59
  501. package/src/directive/setter/setter.spec.js +0 -100
  502. package/src/directive/setter/setter.test.js +0 -12
  503. package/src/directive/show-hide/show-hide.html +0 -22
  504. package/src/directive/show-hide/show-hide.js +0 -65
  505. package/src/directive/show-hide/show-hide.md +0 -255
  506. package/src/directive/show-hide/show-hide.spec.js +0 -268
  507. package/src/directive/show-hide/show-hide.test.js +0 -12
  508. package/src/directive/style/style.html +0 -19
  509. package/src/directive/style/style.js +0 -27
  510. package/src/directive/style/style.md +0 -23
  511. package/src/directive/style/style.spec.js +0 -183
  512. package/src/directive/style/style.test.js +0 -12
  513. package/src/directive/switch/switch.html +0 -19
  514. package/src/directive/switch/switch.js +0 -133
  515. package/src/directive/switch/switch.md +0 -66
  516. package/src/directive/switch/switch.spec.js +0 -509
  517. package/src/directive/switch/switch.test.js +0 -12
  518. package/src/directive/transclude/transclude.js +0 -122
  519. package/src/directive/validators/validators.html +0 -22
  520. package/src/directive/validators/validators.js +0 -346
  521. package/src/directive/validators/validators.spec.js +0 -740
  522. package/src/directive/validators/validators.test.js +0 -12
  523. package/src/filters/filter.js +0 -213
  524. package/src/filters/filter.md +0 -69
  525. package/src/filters/filter.spec.js +0 -719
  526. package/src/filters/filters.html +0 -22
  527. package/src/filters/filters.js +0 -239
  528. package/src/filters/filters.spec.js +0 -36
  529. package/src/filters/filters.test.js +0 -12
  530. package/src/filters/json.md +0 -16
  531. package/src/filters/limit-to.js +0 -55
  532. package/src/filters/limit-to.md +0 -19
  533. package/src/filters/limit-to.spec.js +0 -252
  534. package/src/filters/order-by.js +0 -181
  535. package/src/filters/order-by.md +0 -83
  536. package/src/filters/order-by.spec.js +0 -883
  537. package/src/index.js +0 -6
  538. package/src/index.spec.js +0 -11
  539. package/src/injection-tokens.js +0 -78
  540. package/src/interface.ts +0 -421
  541. package/src/ng.js +0 -289
  542. package/src/ng.spec.js +0 -33
  543. package/src/router/common/trace.js +0 -240
  544. package/src/router/directives/component-example.html +0 -37
  545. package/src/router/directives/state-directives.html +0 -22
  546. package/src/router/directives/state-directives.js +0 -393
  547. package/src/router/directives/state-directives.md +0 -435
  548. package/src/router/directives/state-directives.spec.js +0 -1091
  549. package/src/router/directives/state-directives.test.js +0 -10
  550. package/src/router/directives/view-directive.js +0 -489
  551. package/src/router/directives/view-directive.spec.js +0 -1937
  552. package/src/router/directives/view-directive.test.js +0 -10
  553. package/src/router/directives/view-directives.html +0 -22
  554. package/src/router/glob/glob.html +0 -19
  555. package/src/router/glob/glob.js +0 -102
  556. package/src/router/glob/glob.spec.js +0 -108
  557. package/src/router/glob/glob.test.js +0 -12
  558. package/src/router/hooks/core-resolvables.js +0 -38
  559. package/src/router/hooks/ignored-transition.js +0 -25
  560. package/src/router/hooks/invalid-transition.js +0 -14
  561. package/src/router/hooks/lazy-load.js +0 -104
  562. package/src/router/hooks/on-enter-exit-retain.js +0 -55
  563. package/src/router/hooks/redirect-to.js +0 -38
  564. package/src/router/hooks/resolve.js +0 -57
  565. package/src/router/hooks/update-globals.js +0 -34
  566. package/src/router/hooks/url.js +0 -34
  567. package/src/router/hooks/views.js +0 -41
  568. package/src/router/params/interface.ts +0 -626
  569. package/src/router/params/param-factory.js +0 -23
  570. package/src/router/params/param-type.js +0 -133
  571. package/src/router/params/param-types.js +0 -153
  572. package/src/router/params/param.js +0 -243
  573. package/src/router/params/state-params.js +0 -36
  574. package/src/router/path/path-node.js +0 -78
  575. package/src/router/path/path-utils.js +0 -207
  576. package/src/router/resolve/interface.ts +0 -208
  577. package/src/router/resolve/resolvable.js +0 -123
  578. package/src/router/resolve/resolve-context.js +0 -190
  579. package/src/router/router-test-hashbang.html +0 -45
  580. package/src/router/router-test.html +0 -41
  581. package/src/router/router.html +0 -22
  582. package/src/router/router.js +0 -54
  583. package/src/router/router.test.js +0 -12
  584. package/src/router/services.spec.js +0 -52
  585. package/src/router/state/README.md +0 -21
  586. package/src/router/state/interface.ts +0 -1007
  587. package/src/router/state/state-builder.js +0 -376
  588. package/src/router/state/state-builder.spec.js +0 -86
  589. package/src/router/state/state-matcher.js +0 -64
  590. package/src/router/state/state-object.js +0 -118
  591. package/src/router/state/state-queue-manager.js +0 -95
  592. package/src/router/state/state-registry.js +0 -257
  593. package/src/router/state/state-service.js +0 -699
  594. package/src/router/state/state.html +0 -23
  595. package/src/router/state/state.spec.js +0 -1002
  596. package/src/router/state/state.test.js +0 -12
  597. package/src/router/state/target-state.js +0 -162
  598. package/src/router/state/views.js +0 -195
  599. package/src/router/state-filter.spec.js +0 -139
  600. package/src/router/state-filters.js +0 -46
  601. package/src/router/template-factory.html +0 -19
  602. package/src/router/template-factory.js +0 -249
  603. package/src/router/template-factory.spec.js +0 -155
  604. package/src/router/template-factory.test.js +0 -12
  605. package/src/router/transition/hook-builder.js +0 -133
  606. package/src/router/transition/hook-registry.js +0 -172
  607. package/src/router/transition/interface.js +0 -18
  608. package/src/router/transition/interface.ts +0 -922
  609. package/src/router/transition/reject-factory.js +0 -122
  610. package/src/router/transition/transition-event-type.js +0 -26
  611. package/src/router/transition/transition-hook.js +0 -199
  612. package/src/router/transition/transition-service.js +0 -302
  613. package/src/router/transition/transition.js +0 -652
  614. package/src/router/url/url-config.js +0 -155
  615. package/src/router/url/url-matcher.js +0 -532
  616. package/src/router/url/url-rule.js +0 -231
  617. package/src/router/url/url-rules.js +0 -350
  618. package/src/router/url/url-service.js +0 -446
  619. package/src/router/url/url-service.spec.js +0 -1288
  620. package/src/router/url/url.html +0 -19
  621. package/src/router/url/url.test.js +0 -12
  622. package/src/router/view/interface.ts +0 -51
  623. package/src/router/view/view.html +0 -19
  624. package/src/router/view/view.js +0 -274
  625. package/src/router/view/view.spec.js +0 -100
  626. package/src/router/view/view.test.js +0 -12
  627. package/src/router/view-hook.spec.js +0 -215
  628. package/src/router/view-scroll.js +0 -33
  629. package/src/router/view-scroll.spec.js +0 -72
  630. package/src/services/anchor-scroll.html +0 -76
  631. package/src/services/anchor-scroll.js +0 -147
  632. package/src/services/cookie-reader.js +0 -48
  633. package/src/services/exception/exception-handler.js +0 -75
  634. package/src/services/exception/interface.ts +0 -7
  635. package/src/services/http/http.html +0 -23
  636. package/src/services/http/http.js +0 -922
  637. package/src/services/http/http.md +0 -413
  638. package/src/services/http/http.spec.js +0 -3941
  639. package/src/services/http/http.test.js +0 -11
  640. package/src/services/http/interface.ts +0 -243
  641. package/src/services/http/template-request.spec.js +0 -220
  642. package/src/services/http-backend/http-backend.html +0 -22
  643. package/src/services/http-backend/http-backend.js +0 -158
  644. package/src/services/http-backend/http-backend.spec.js +0 -389
  645. package/src/services/http-backend/http-backend.test.js +0 -12
  646. package/src/services/location/interface.ts +0 -70
  647. package/src/services/location/location.html +0 -22
  648. package/src/services/location/location.js +0 -1006
  649. package/src/services/location/location.spec.js +0 -3792
  650. package/src/services/location/location.test.js +0 -12
  651. package/src/services/log/interface.ts +0 -39
  652. package/src/services/log/log.html +0 -19
  653. package/src/services/log/log.js +0 -74
  654. package/src/services/log/log.spec.js +0 -64
  655. package/src/services/log/log.test.js +0 -12
  656. package/src/services/pubsub/pubsub.html +0 -19
  657. package/src/services/pubsub/pubsub.js +0 -349
  658. package/src/services/pubsub/pubsub.spec.js +0 -400
  659. package/src/services/pubsub/pubsub.test.js +0 -12
  660. package/src/services/sce/sce.html +0 -19
  661. package/src/services/sce/sce.js +0 -847
  662. package/src/services/sce/sce.md +0 -300
  663. package/src/services/sce/sce.spec.js +0 -617
  664. package/src/services/sce/sce.test.js +0 -12
  665. package/src/services/template-cache/interface.ts +0 -10
  666. package/src/services/template-cache/template-cache.html +0 -22
  667. package/src/services/template-cache/template-cache.js +0 -15
  668. package/src/services/template-cache/template-cache.spec.js +0 -134
  669. package/src/services/template-cache/template-cache.test.js +0 -12
  670. package/src/services/template-request.js +0 -142
  671. package/src/shared/cache.js +0 -7
  672. package/src/shared/common.js +0 -438
  673. package/src/shared/common.spec.js +0 -294
  674. package/src/shared/constants.js +0 -21
  675. package/src/shared/dom.js +0 -716
  676. package/src/shared/hof.js +0 -151
  677. package/src/shared/hof.spec.js +0 -60
  678. package/src/shared/interface.ts +0 -21
  679. package/src/shared/min-err.spec.js +0 -178
  680. package/src/shared/noderef.js +0 -225
  681. package/src/shared/predicates.js +0 -34
  682. package/src/shared/queue.js +0 -105
  683. package/src/shared/queue.spec.js +0 -80
  684. package/src/shared/shared.html +0 -24
  685. package/src/shared/shared.test.js +0 -12
  686. package/src/shared/strings.js +0 -142
  687. package/src/shared/strings.spec.js +0 -40
  688. package/src/shared/test-utils.js +0 -47
  689. package/src/shared/url-utils/interface.ts +0 -54
  690. package/src/shared/url-utils/url-utils.html +0 -22
  691. package/src/shared/url-utils/url-utils.js +0 -122
  692. package/src/shared/url-utils/url-utils.spec.js +0 -148
  693. package/src/shared/url-utils/url-utils.test.js +0 -12
  694. package/src/shared/utils.js +0 -1255
  695. package/src/shared/utils.spec.js +0 -178
  696. package/src/src.html +0 -21
  697. package/src/src.test.js +0 -10
  698. package/tsconfig.json +0 -19
  699. package/tsconfig.types.json +0 -14
  700. package/typedoc.json +0 -8
  701. package/utils/express.js +0 -203
  702. package/utils/version.cjs +0 -23
  703. package/vite.config.js +0 -14
@@ -1,3941 +0,0 @@
1
- import { createInjector } from "../../core/di/injector.js";
2
- import { isObject } from "../../shared/utils.js";
3
- import { Angular } from "../../angular.js";
4
- import { wait } from "../../shared/test-utils.js";
5
-
6
- export function getLastAjaxRequest() {
7
- let ajaxEntries = performance
8
- .getEntriesByType("resource")
9
- .filter((entry) => entry.initiatorType === "xmlhttprequest");
10
- return ajaxEntries[ajaxEntries.length - 1];
11
- }
12
-
13
- describe("$http", function () {
14
- let $http, $injector, $httpBackend, requests, response, $rootScope;
15
-
16
- beforeEach(function () {
17
- window.angular = new Angular();
18
- requests = [];
19
- $injector = createInjector(["ng"]);
20
- $http = $injector.get("$http");
21
- $httpBackend = $injector.get("$httpBackend");
22
- $rootScope = $injector.get("$rootScope");
23
- });
24
-
25
- it("is a function", function () {
26
- expect($http instanceof Function).toBe(true);
27
- });
28
-
29
- it("returns a Promise", function () {
30
- const result = $http({ url: "test" });
31
- expect(result).toBeDefined();
32
- expect(result.then).toBeDefined();
33
- });
34
-
35
- it("makes an XMLHttpRequest to given URL", async function () {
36
- await $http({
37
- method: "POST",
38
- url: "/mock/hello",
39
- data: "hello",
40
- }).then((res) => {
41
- requests.push(res);
42
- });
43
- expect(requests.length).toBe(1);
44
- expect(requests[0].config.method).toBe("POST");
45
- expect(requests[0].config.url).toBe("/mock/hello");
46
- expect(requests[0].config.data).toBe("hello");
47
- });
48
-
49
- it("resolves promise when XHR result received", async function () {
50
- await $http({
51
- method: "GET",
52
- url: "/mock/hello",
53
- }).then(function (r) {
54
- response = r;
55
- });
56
- expect(response).toBeDefined();
57
- expect(response.status).toBe(200);
58
- expect(response.statusText).toBe("OK");
59
- expect(response.data).toBe("Hello");
60
- expect(response.config.url).toEqual("/mock/hello");
61
- });
62
-
63
- it("rejects promise when XHR result received with error status", async function () {
64
- await $http({
65
- method: "GET",
66
- url: "/mock/401",
67
- }).catch(function (r) {
68
- response = r;
69
- });
70
- expect(response).toBeDefined();
71
- expect(response.status).toBe(401);
72
- expect(response.statusText).toBe("Unauthorized");
73
- expect(response.data).toBe("Unauthorized");
74
- expect(response.config.url).toEqual("/mock/401");
75
- });
76
-
77
- it("uses GET method by default", async function () {
78
- await $http({
79
- url: "/mock/hello",
80
- }).then(function (r) {
81
- response = r;
82
- });
83
- expect(response).toBeDefined();
84
- expect(response.config.method).toBe("GET");
85
- });
86
-
87
- it("sets default headers on request", async function () {
88
- await $http({
89
- url: "/mock/hello",
90
- headers: {
91
- Accept: "text/plain",
92
- "Cache-Control": "no-cache",
93
- },
94
- }).then(function (r) {
95
- response = r;
96
- });
97
- expect(response).toBeDefined();
98
-
99
- expect(response.config.headers.Accept).toBe("text/plain");
100
- expect(response.config.headers["Cache-Control"]).toBe("no-cache");
101
- });
102
-
103
- it("sets method-specific default headers on POST request", async function () {
104
- await $http({
105
- method: "POST",
106
- url: "/mock/hello",
107
- data: "42",
108
- }).then(function (r) {
109
- response = r;
110
- });
111
- expect(response).toBeDefined();
112
- expect(response.config.headers["Content-Type"]).toBe(
113
- "application/json;charset=utf-8",
114
- );
115
- });
116
-
117
- it("sets method-specific default headers on PUT request", async function () {
118
- await $http({
119
- method: "PUT",
120
- url: "/mock/put",
121
- data: "42",
122
- }).then(function (r) {
123
- response = r;
124
- });
125
- expect(response).toBeDefined();
126
- expect(response.config.headers["Content-Type"]).toBe(
127
- "application/json;charset=utf-8",
128
- );
129
- });
130
-
131
- it("sets method-specific default headers on PATCH request", async function () {
132
- await $http({
133
- method: "PATCH",
134
- url: "/mock/patch",
135
- data: "42",
136
- }).then(function (r) {
137
- response = r;
138
- });
139
- expect(response).toBeDefined();
140
- expect(response.config.headers["Content-Type"]).toBe(
141
- "application/json;charset=utf-8",
142
- );
143
- });
144
-
145
- it("exposes default headers for overriding", async function () {
146
- $http.defaults.headers.post.Accept = "text/plain";
147
- $http.defaults.headers.post["Content-Type"] = "text/plain;charset=utf-8";
148
- await $http({
149
- method: "POST",
150
- url: "/mock/hello",
151
- data: "42",
152
- }).then(function (r) {
153
- response = r;
154
- });
155
- expect(response).toBeDefined();
156
- expect(response.config.headers["Accept"]).toBe("text/plain");
157
- expect(response.config.headers["Content-Type"]).toBe(
158
- "text/plain;charset=utf-8",
159
- );
160
- });
161
-
162
- it("merges default headers case-insensitively", async function () {
163
- await $http({
164
- method: "POST",
165
- url: "/mock/hello",
166
- data: "42",
167
- headers: {
168
- "content-type": "text/plain;charset=utf-8",
169
- },
170
- }).then(function (r) {
171
- response = r;
172
- });
173
- expect(response).toBeDefined();
174
-
175
- expect(response.config.headers["content-type"]).toBe(
176
- "text/plain;charset=utf-8",
177
- );
178
- expect(response.config.headers["Content-Type"]).toBeUndefined();
179
- });
180
-
181
- it("does not send content-type header when no data", async function () {
182
- await $http({
183
- method: "POST",
184
- url: "/mock/hello",
185
- headers: {
186
- "Content-Type": "application/json;charset=utf-8",
187
- },
188
- }).then(function (r) {
189
- response = r;
190
- });
191
- expect(response).toBeDefined();
192
- expect(response.config.headers["Content-Type"]).not.toBe(
193
- "application/json;charset=utf-8",
194
- );
195
- });
196
-
197
- it("supports functions as header values", async function () {
198
- const contentTypeSpy = jasmine
199
- .createSpy()
200
- .and.returnValue("text/plain;charset=utf-8");
201
- $http.defaults.headers.post["Content-Type"] = contentTypeSpy;
202
- const request = {
203
- method: "POST",
204
- url: "/mock/hello",
205
- data: 42,
206
- };
207
- await $http(request).then(function (r) {
208
- response = r;
209
- });
210
- expect(contentTypeSpy).toHaveBeenCalledWith(request);
211
- expect(response.config.headers["Content-Type"]).toBe(
212
- "text/plain;charset=utf-8",
213
- );
214
- });
215
-
216
- it("ignores header function value when null/undefined", async function () {
217
- const cacheControlSpy = jasmine.createSpy().and.returnValue(null);
218
- $http.defaults.headers.post["Cache-Control"] = cacheControlSpy;
219
- const request = {
220
- method: "POST",
221
- url: "/mock/hello",
222
- data: 42,
223
- };
224
- await $http(request).then(function (r) {
225
- response = r;
226
- });
227
- expect(cacheControlSpy).toHaveBeenCalledWith(request);
228
- expect(response.config.headers["Cache-Control"]).toBeUndefined();
229
- });
230
-
231
- it("makes response headers available", async function () {
232
- await $http({
233
- method: "POST",
234
- url: "/mock/hello",
235
- data: 42,
236
- }).then(function (r) {
237
- response = r;
238
- });
239
- expect(response.headers).toBeDefined();
240
- expect(response.headers instanceof Function).toBe(true);
241
- expect(response.headers("Content-Type")).toBe("text/html; charset=utf-8");
242
- });
243
-
244
- it("may returns all response headers", async function () {
245
- await $http({
246
- method: "POST",
247
- url: "/mock/hello",
248
- data: 42,
249
- }).then(function (r) {
250
- response = r;
251
- });
252
- expect(response.headers()).toBeTruthy();
253
- });
254
-
255
- it("allows setting withCredentials", async function () {
256
- await $http({
257
- method: "POST",
258
- url: "/mock/hello",
259
- data: 42,
260
- withCredentials: true,
261
- }).then(function (r) {
262
- response = r;
263
- });
264
- expect(response.config.withCredentials).toBe(true);
265
- });
266
-
267
- it("allows setting withCredentials from defaults", async function () {
268
- $http.defaults.withCredentials = true;
269
- await $http({
270
- method: "POST",
271
- url: "/mock/hello",
272
- data: 42,
273
- }).then(function (r) {
274
- response = r;
275
- });
276
- expect(response.config.withCredentials).toBe(true);
277
- });
278
-
279
- it("allows transforming requests with functions", async function () {
280
- let transformedData;
281
- await $http({
282
- method: "POST",
283
- url: "/mock/hello",
284
- data: 42,
285
- transformRequest: function (data) {
286
- transformedData = "*" + data + "*";
287
- return transformedData;
288
- },
289
- }).then(function (r) {
290
- response = r;
291
- });
292
- expect(transformedData).toBe("*42*");
293
- });
294
-
295
- it("allows multiple request transform functions", async function () {
296
- let transformedData;
297
- await $http({
298
- method: "POST",
299
- url: "/mock/hello",
300
- data: 42,
301
- transformRequest: [
302
- function (data) {
303
- transformedData = "*" + data + "*";
304
- return transformedData;
305
- },
306
- function (data) {
307
- transformedData = "-" + data + "-";
308
- return transformedData;
309
- },
310
- ],
311
- });
312
- expect(transformedData).toBe("-*42*-");
313
- });
314
-
315
- it("allows settings transforms in defaults", async function () {
316
- let transformedData;
317
- $http.defaults.transformRequest = [
318
- function (data) {
319
- transformedData = "*" + data + "*";
320
- return transformedData;
321
- },
322
- ];
323
- await $http({
324
- method: "POST",
325
- url: "/mock/hello",
326
- data: 42,
327
- });
328
- expect(transformedData).toBe("*42*");
329
- });
330
-
331
- it("passes request headers getter to transforms", async function () {
332
- let transformedData;
333
- $http.defaults.transformRequest = [
334
- function (data, headers) {
335
- if (headers("Content-Type") === "text/emphasized") {
336
- transformedData = "*" + data + "*";
337
- return transformedData;
338
- } else {
339
- return data;
340
- }
341
- },
342
- ];
343
- await $http({
344
- method: "POST",
345
- url: "/mock/hello",
346
- data: 42,
347
- headers: {
348
- "content-type": "text/emphasized",
349
- },
350
- });
351
- expect(transformedData).toBe("*42*");
352
- });
353
-
354
- it("allows transforming responses with functions", async function () {
355
- await $http({
356
- url: "/mock/hello",
357
- transformResponse: function (data) {
358
- return "*" + data + "*";
359
- },
360
- }).then(function (r) {
361
- response = r;
362
- });
363
- await wait();
364
-
365
- expect(response.data).toEqual("*Hello*");
366
- });
367
-
368
- it("passes response headers to transform functions", async function () {
369
- await $http({
370
- url: "/mock/hello",
371
- transformResponse: function (data) {
372
- return "*" + data + "*";
373
- },
374
- }).then(function (r) {
375
- response = r;
376
- });
377
- await wait();
378
-
379
- expect(response.data).toEqual("*Hello*");
380
- });
381
-
382
- it("allows setting default response transforms", async function () {
383
- $http.defaults.transformResponse = [
384
- function (data) {
385
- return "*" + data + "*";
386
- },
387
- ];
388
- await $http({
389
- url: "/mock/hello",
390
- }).then(function (r) {
391
- response = r;
392
- });
393
- await wait();
394
-
395
- expect(response.data).toEqual("*Hello*");
396
- });
397
-
398
- it("transforms error responses also", async function () {
399
- await $http({
400
- url: "/mock/401",
401
- transformResponse: function (data) {
402
- return "*" + data + "*";
403
- },
404
- }).catch(function (r) {
405
- response = r;
406
- });
407
- await wait();
408
-
409
- expect(response.data).toEqual("*Unauthorized*");
410
- });
411
-
412
- it("passes HTTP status to response transformers", async function () {
413
- let response;
414
- await $http({
415
- url: "/mock/401",
416
- transformResponse: function (data, headers, status) {
417
- if (status === 401) {
418
- return "unauthorized";
419
- } else {
420
- return data;
421
- }
422
- },
423
- }).catch(function (r) {
424
- response = r;
425
- });
426
- await wait();
427
-
428
- expect(response.data).toEqual("unauthorized");
429
- });
430
-
431
- it("serializes object data to JSON for requests", async function () {
432
- await $http({
433
- method: "POST",
434
- url: "/mock/post",
435
- data: { aKey: 42 },
436
- }).then(function (r) {
437
- response = r;
438
- });
439
- await wait();
440
- expect(response.data).toEqual({ aKey: 42 });
441
- expect(response.config.data).toEqual({ aKey: 42 });
442
- });
443
-
444
- it("serializes array data to JSON for requests", async function () {
445
- await $http({
446
- method: "POST",
447
- url: "/mock/post",
448
- data: [1, "two", 3],
449
- }).then(function (r) {
450
- response = r;
451
- });
452
- await wait();
453
- expect(response.data).toEqual([1, "two", 3]);
454
- });
455
-
456
- it("does not serialize blobs for requests", async function () {
457
- let blob;
458
- if (window.Blob) {
459
- blob = new Blob(["hello"]);
460
- } else {
461
- const BlobBuilder =
462
- window.BlobBuilder ||
463
- window.WebKitBlobBuilder ||
464
- window.MozBlobBuilder ||
465
- window.MSBlobBuilder;
466
- const bb = new BlobBuilder();
467
- bb.append("hello");
468
- blob = bb.getBlob("text/plain");
469
- }
470
- await $http({
471
- method: "POST",
472
- url: "/mock/blob",
473
- data: blob,
474
- }).then(function (r) {
475
- response = r;
476
- });
477
-
478
- await wait();
479
-
480
- expect(response.config.data.size).toEqual(5);
481
- expect(response.data).toEqual("");
482
- });
483
-
484
- it("does not serialize form data for requests", async function () {
485
- const formData = new FormData();
486
- formData.append("aField", "aValue");
487
- await $http({
488
- method: "POST",
489
- url: "/mock/form",
490
- data: formData,
491
- }).then(function (r) {
492
- response = r;
493
- });
494
-
495
- await wait();
496
-
497
- expect(response.config.data).toEqual(formData);
498
- expect(response.data).toEqual("");
499
- });
500
-
501
- it("parses JSON data for JSON responses", async function () {
502
- await $http({
503
- method: "POST",
504
- url: "/mock/post",
505
- data: { aKey: 42 },
506
- }).then(function (r) {
507
- response = r;
508
- });
509
- await wait();
510
-
511
- expect(isObject(response.data)).toBe(true);
512
- expect(response.data.aKey).toBe(42);
513
- });
514
-
515
- it("parses a JSON object response without content type", async function () {
516
- await $http({
517
- method: "POST",
518
- url: "/mock/nocontent",
519
- data: { aKey: 42 },
520
- }).then(function (r) {
521
- response = r;
522
- });
523
- await wait();
524
-
525
- expect(isObject(response.data)).toBe(true);
526
- expect(response.data.aKey).toBe(42);
527
- });
528
-
529
- it("parses a JSON array response without content type", async function () {
530
- await $http({
531
- method: "POST",
532
- url: "/mock/nocontent",
533
- data: [1, 2, 3],
534
- }).then(function (r) {
535
- response = r;
536
- });
537
- await wait();
538
-
539
- expect(Array.isArray(response.data)).toBe(true);
540
- expect(response.data).toEqual([1, 2, 3]);
541
- });
542
-
543
- it("does not choke on response resembling JSON but not valid", async function () {
544
- let response;
545
- await $http({
546
- method: "POST",
547
- url: "/mock/invalidarray",
548
- }).then(function (r) {
549
- response = r;
550
- });
551
- await wait();
552
-
553
- expect(response.data).toEqual("{1, 2, 3]");
554
- });
555
-
556
- it("does not try to parse interpolation expr as JSON", async function () {
557
- let response;
558
- await $http({
559
- method: "GET",
560
- url: "/mock/interpolation",
561
- }).then(function (r) {
562
- response = r;
563
- });
564
- await wait();
565
- expect(response.data).toEqual("{{expr}}");
566
- });
567
-
568
- it("adds params to URL", async function () {
569
- await $http({
570
- method: "GET",
571
- url: "/mock/hello",
572
- params: {
573
- a: 42,
574
- },
575
- }).then(function (r) {
576
- response = r;
577
- });
578
- await wait();
579
- expect(
580
- response.config.paramSerializer(response.config.params).endsWith("a=42"),
581
- ).toBeTrue();
582
- });
583
-
584
- it("adds additional params to URL", async function () {
585
- await $http({
586
- url: "/mock/hello?a=42",
587
- params: {
588
- b: 42,
589
- },
590
- }).then(function (r) {
591
- response = r;
592
- });
593
- await wait();
594
- expect(
595
- response.config.paramSerializer(response.config.params).endsWith("b=42"),
596
- ).toBeTrue();
597
- });
598
-
599
- it("escapes url characters in params", async function () {
600
- await $http({
601
- url: "/mock/hello",
602
- params: {
603
- "==": "&&",
604
- },
605
- }).then(function (r) {
606
- response = r;
607
- });
608
- await wait();
609
-
610
- expect(
611
- response.config
612
- .paramSerializer(response.config.params)
613
- .endsWith("%3D%3D=%26%26"),
614
- ).toBeTrue();
615
- });
616
-
617
- it("does not attach null or undefined params", async function () {
618
- await $http({
619
- url: "/mock/hello",
620
- params: {
621
- a: null,
622
- b: undefined,
623
- },
624
- }).then(function (r) {
625
- response = r;
626
- });
627
- await wait();
628
- expect(
629
- response.config.paramSerializer(response.config.params).endsWith(""),
630
- ).toBeTrue();
631
- });
632
-
633
- it("attaches multiple params from arrays", async function () {
634
- await $http({
635
- url: "/mock/hello",
636
- params: {
637
- a: [42, 43],
638
- },
639
- }).then(function (r) {
640
- response = r;
641
- });
642
- await wait();
643
- expect(
644
- response.config
645
- .paramSerializer(response.config.params)
646
- .endsWith("a=42&a=43"),
647
- ).toBeTrue();
648
- });
649
-
650
- it("serializes objects to json", async function () {
651
- await $http({
652
- method: "POST",
653
- url: "/mock/post",
654
- params: {
655
- a: { b: 42 },
656
- },
657
- }).then(function (r) {
658
- response = r;
659
- });
660
- await wait();
661
- expect(
662
- response.config
663
- .paramSerializer(response.config.params)
664
- .endsWith("a=%7B%22b%22:42%7D"),
665
- ).toBeTrue();
666
- });
667
-
668
- it("serializes dates to ISO strings", async function () {
669
- await $http({
670
- url: "/mock/hello",
671
- params: {
672
- a: new Date(2015, 0, 1, 12, 0, 0),
673
- },
674
- }).then(function (r) {
675
- response = r;
676
- });
677
- await wait();
678
- expect(
679
- response.config
680
- .paramSerializer(response.config.params)
681
- .endsWith("00:00.000Z"),
682
- ).toBeTrue();
683
- });
684
-
685
- it("allows substituting param serializer", async function () {
686
- await $http({
687
- url: "/mock/hello",
688
- params: {
689
- a: 42,
690
- b: 43,
691
- },
692
- paramSerializer: function (params) {
693
- return Object.keys(params)
694
- .map(function (k) {
695
- return k + "=" + params[k] + "lol";
696
- })
697
- .join("&");
698
- },
699
- }).then(function (r) {
700
- response = r;
701
- });
702
- await wait();
703
-
704
- expect(
705
- response.config
706
- .paramSerializer(response.config.params)
707
- .endsWith("a=42lol&b=43lol"),
708
- ).toBeTrue();
709
- });
710
-
711
- it("allows substituting param serializer through DI", async function () {
712
- const injector = createInjector([
713
- "ng",
714
- function ($provide) {
715
- $provide.factory("mySpecialSerializer", function () {
716
- return function (params) {
717
- return Object.keys(params)
718
- .map(function (k) {
719
- return k + "=" + params[k] + "lol";
720
- })
721
- .join("&");
722
- };
723
- });
724
- },
725
- ]);
726
-
727
- await injector.invoke(async function ($http, $rootScope) {
728
- await $http({
729
- url: "/mock/hello",
730
- params: {
731
- a: 42,
732
- b: 43,
733
- },
734
- paramSerializer: "mySpecialSerializer",
735
- }).then(function (r) {
736
- response = r;
737
- });
738
- await wait();
739
- });
740
- expect(
741
- response.config
742
- .paramSerializer(response.config.params)
743
- .endsWith("a=42lol&b=43lol"),
744
- ).toBeTrue();
745
- });
746
-
747
- it("makes default param serializer available through DI", async function () {
748
- const injector = createInjector(["ng"]);
749
- injector.invoke(function ($httpParamSerializer) {
750
- const result = $httpParamSerializer({ a: 42, b: 43 });
751
- expect(result).toEqual("a=42&b=43");
752
- });
753
- });
754
-
755
- it("supports shorthand method for GET", async function () {
756
- await $http
757
- .get("/mock/hello", {
758
- params: { q: 42 },
759
- })
760
- .then(function (r) {
761
- response = r;
762
- });
763
- await wait();
764
-
765
- expect(
766
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
767
- ).toBeTrue();
768
- expect(response.config.method).toBe("GET");
769
- });
770
-
771
- it("supports shorthand method for HEAD", async function () {
772
- await $http
773
- .head("/mock/head", {
774
- params: { q: 42 },
775
- })
776
- .then(function (r) {
777
- response = r;
778
- });
779
- await wait();
780
-
781
- expect(
782
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
783
- ).toBeTrue();
784
- expect(response.config.method).toBe("HEAD");
785
- });
786
-
787
- it("supports shorthand method for DELETE", async function () {
788
- await $http
789
- .delete("/mock/delete", {
790
- params: { q: 42 },
791
- })
792
- .then(function (r) {
793
- response = r;
794
- });
795
-
796
- await wait();
797
-
798
- expect(
799
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
800
- ).toBeTrue();
801
- expect(response.config.method).toBe("DELETE");
802
- });
803
-
804
- it("supports shorthand method for POST with data", async function () {
805
- await $http
806
- .post("/mock/hello", "data", {
807
- params: { q: 42 },
808
- })
809
- .then(function (r) {
810
- response = r;
811
- });
812
- await wait();
813
-
814
- expect(
815
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
816
- ).toBeTrue();
817
- expect(response.config.method).toBe("POST");
818
- expect(response.config.data).toBe("data");
819
- });
820
-
821
- it("supports shorthand method for PUT with data", async function () {
822
- await $http
823
- .put("/mock/put", "data", {
824
- params: { q: 42 },
825
- })
826
- .then(function (r) {
827
- response = r;
828
- });
829
- await wait();
830
- expect(
831
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
832
- ).toBeTrue();
833
- expect(response.config.method).toBe("PUT");
834
- expect(response.config.data).toBe("data");
835
- });
836
-
837
- it("supports shorthand method for PATCH with data", async function () {
838
- await $http
839
- .patch("/mock/patch", "data", {
840
- params: { q: 42 },
841
- })
842
- .then(function (r) {
843
- response = r;
844
- });
845
- await wait();
846
-
847
- expect(
848
- response.config.paramSerializer(response.config.params).endsWith("q=42"),
849
- ).toBeTrue();
850
- expect(response.config.method).toBe("PATCH");
851
- expect(response.config.data).toBe("data");
852
- });
853
-
854
- it("allows attaching interceptor factories", async function () {
855
- const interceptorFactorySpy = jasmine.createSpy();
856
- const injector = createInjector([
857
- "ng",
858
- function ($httpProvider) {
859
- $httpProvider.interceptors.push(interceptorFactorySpy);
860
- },
861
- ]);
862
- $http = injector.get("$http");
863
-
864
- expect(interceptorFactorySpy).toHaveBeenCalled();
865
- });
866
-
867
- it("uses DI to instantiate interceptors", async function () {
868
- const interceptorFactorySpy = jasmine.createSpy();
869
- const injector = createInjector([
870
- "ng",
871
- function ($httpProvider) {
872
- $httpProvider.interceptors.push(["$rootScope", interceptorFactorySpy]);
873
- },
874
- ]);
875
- $http = injector.get("$http");
876
- const $rootScope = injector.get("$rootScope");
877
-
878
- expect(interceptorFactorySpy).toHaveBeenCalledWith($rootScope);
879
- });
880
-
881
- it("allows referencing existing interceptor factories", async function () {
882
- const interceptorFactorySpy = jasmine.createSpy().and.returnValue({});
883
- const injector = createInjector([
884
- "ng",
885
- function ($provide, $httpProvider) {
886
- $provide.factory("myInterceptor", interceptorFactorySpy);
887
- $httpProvider.interceptors.push("myInterceptor");
888
- },
889
- ]);
890
- $http = injector.get("$http");
891
-
892
- expect(interceptorFactorySpy).toHaveBeenCalled();
893
- });
894
-
895
- it("allows intercepting requests", async function () {
896
- const injector = createInjector([
897
- "ng",
898
- function ($httpProvider) {
899
- $httpProvider.interceptors.push(function () {
900
- return {
901
- request: function (config) {
902
- config.params.intercepted = true;
903
- return config;
904
- },
905
- };
906
- });
907
- },
908
- ]);
909
- $http = injector.get("$http");
910
- $rootScope = injector.get("$rootScope");
911
-
912
- await $http.get("/mock/hello", { params: {} }).then(function (r) {
913
- response = r;
914
- });
915
-
916
- await wait();
917
-
918
- expect(
919
- response.config
920
- .paramSerializer(response.config.params)
921
- .endsWith("intercepted=true"),
922
- ).toBeTrue();
923
- });
924
-
925
- it("allows returning promises from request intercepts", async function () {
926
- const injector = createInjector([
927
- "ng",
928
- function ($httpProvider) {
929
- $httpProvider.interceptors.push(function () {
930
- return {
931
- request: function (config) {
932
- config.params.intercepted = true;
933
- return Promise.resolve(config);
934
- },
935
- };
936
- });
937
- },
938
- ]);
939
- $http = injector.get("$http");
940
- $rootScope = injector.get("$rootScope");
941
-
942
- await $http.get("/mock/hello", { params: {} }).then(function (r) {
943
- response = r;
944
- });
945
- await wait();
946
-
947
- expect(
948
- response.config
949
- .paramSerializer(response.config.params)
950
- .endsWith("intercepted=true"),
951
- ).toBeTrue();
952
- });
953
-
954
- it("allows intercepting responses", async function () {
955
- const injector = createInjector([
956
- "ng",
957
- function ($httpProvider) {
958
- $httpProvider.interceptors.push(() => ({
959
- response: function (response) {
960
- response.intercepted = true;
961
- return response;
962
- },
963
- }));
964
- },
965
- ]);
966
- $http = injector.get("$http");
967
- $rootScope = injector.get("$rootScope");
968
-
969
- let response;
970
- await $http.get("/mock/hello").then(function (r) {
971
- response = r;
972
- });
973
- await wait();
974
-
975
- expect(response.intercepted).toBe(true);
976
- });
977
-
978
- it("allows intercepting request errors", async function () {
979
- const requestErrorSpy = jasmine.createSpy();
980
- const injector = createInjector([
981
- "ng",
982
- function ($httpProvider) {
983
- $httpProvider.interceptors.push(() => ({
984
- request: function (config) {
985
- throw "fail";
986
- },
987
- }));
988
- $httpProvider.interceptors.push(() => {
989
- return {
990
- requestError: requestErrorSpy,
991
- };
992
- });
993
- },
994
- ]);
995
- $http = injector.get("$http");
996
- $rootScope = injector.get("$rootScope");
997
-
998
- try {
999
- await $http.get("/mock/hello").then(function (r) {
1000
- response = r;
1001
- });
1002
- } catch {}
1003
-
1004
- expect(requestErrorSpy).toHaveBeenCalledWith("fail");
1005
- });
1006
-
1007
- it("allows intercepting response errors", async function () {
1008
- const responseErrorSpy = jasmine.createSpy();
1009
- const injector = createInjector([
1010
- "ng",
1011
- function ($httpProvider) {
1012
- $httpProvider.interceptors.push(() => ({
1013
- responseError: responseErrorSpy,
1014
- }));
1015
- $httpProvider.interceptors.push(() => ({
1016
- response: function () {
1017
- throw "fail";
1018
- },
1019
- }));
1020
- },
1021
- ]);
1022
- $http = injector.get("$http");
1023
- $rootScope = injector.get("$rootScope");
1024
-
1025
- await $http.get("/mock/hello");
1026
- await wait();
1027
- await wait();
1028
-
1029
- expect(responseErrorSpy).toHaveBeenCalledWith("fail");
1030
- });
1031
-
1032
- it("allows attaching success handlers", async function () {
1033
- let data, status, config;
1034
- await $http.get("/mock/hello").then(function (res) {
1035
- data = res.data;
1036
- status = res.status;
1037
- config = res.config;
1038
- });
1039
- await wait();
1040
-
1041
- expect(data).toBe("Hello");
1042
- expect(status).toBe(200);
1043
- expect(config.method).toBe("GET");
1044
- });
1045
-
1046
- it("allows attaching error handlers", async function () {
1047
- let res;
1048
- await $http.get("/mock/401").then(
1049
- () => {},
1050
- function (r) {
1051
- res = r;
1052
- },
1053
- );
1054
- await wait();
1055
-
1056
- expect(res.data).toBe("Unauthorized");
1057
- expect(res.status).toBe(401);
1058
- expect(res.config.method).toBe("GET");
1059
- });
1060
-
1061
- it("allows aborting a request with a Promise", async function () {
1062
- const timeout = Promise.withResolvers();
1063
- $http
1064
- .get("/mock/never", {
1065
- timeout: timeout.promise,
1066
- })
1067
- .then(
1068
- function () {},
1069
- function (err) {
1070
- response = err;
1071
- },
1072
- );
1073
- timeout.resolve();
1074
- await wait();
1075
- expect(response.xhrStatus).toBe("abort");
1076
- });
1077
-
1078
- it("allows aborting a request after a timeout", async function () {
1079
- await $http
1080
- .get("/mock/never", {
1081
- timeout: 50,
1082
- })
1083
- .then(
1084
- function () {},
1085
- function (err) {
1086
- response = err;
1087
- },
1088
- );
1089
- await wait();
1090
-
1091
- expect(response.xhrStatus).toBe("timeout");
1092
- });
1093
-
1094
- describe("pending requests", function () {
1095
- it("are in the collection while pending", async function () {
1096
- $http.get("/mock/hello");
1097
- expect($http.pendingRequests.length).toBe(0);
1098
- await wait();
1099
- expect($http.pendingRequests).toBeDefined();
1100
- expect($http.pendingRequests.length).toBe(1);
1101
- expect($http.pendingRequests[0].url).toBe("/mock/hello");
1102
- });
1103
-
1104
- it("are also cleared on failure", async function () {
1105
- await $http.get("/mock/401").then(
1106
- () => {},
1107
- (err) => {},
1108
- );
1109
-
1110
- await wait();
1111
-
1112
- expect($http.pendingRequests.length).toBe(0);
1113
- });
1114
- });
1115
-
1116
- describe("useApplyAsync", function () {
1117
- beforeEach(function () {
1118
- const injector = createInjector([
1119
- "ng",
1120
- function ($httpProvider) {
1121
- $httpProvider.useApplyAsync(true);
1122
- },
1123
- ]);
1124
- $http = injector.get("$http");
1125
- $rootScope = injector.get("$rootScope");
1126
- });
1127
-
1128
- it("does not resolve promise immediately when enabled", async function () {
1129
- const resolvedSpy = jasmine.createSpy();
1130
- $http.get("/mock/hello").then(resolvedSpy);
1131
- await wait();
1132
-
1133
- expect(resolvedSpy).not.toHaveBeenCalled();
1134
- });
1135
-
1136
- it("resolves promise later when enabled", async function () {
1137
- const resolvedSpy = jasmine.createSpy();
1138
- await $http.get("/mock/hello").then(resolvedSpy);
1139
- await wait();
1140
-
1141
- expect(resolvedSpy).toHaveBeenCalled();
1142
- });
1143
- });
1144
- });
1145
-
1146
- // describe("$http", () => {
1147
- // let callback;
1148
- // let mockedCookies;
1149
- // const customParamSerializer = function (params) {
1150
- // return Object.keys(params).join("_");
1151
- // };
1152
-
1153
- // beforeEach(
1154
- // module(() => {
1155
- // callback = jasmine.createSpy("done");
1156
- // mockedCookies = {};
1157
- // }),
1158
- // );
1159
-
1160
- // beforeEach(
1161
- // module({
1162
- // $$cookieReader() {
1163
- // return mockedCookies;
1164
- // },
1165
- // customParamSerializer,
1166
- // }),
1167
- // );
1168
-
1169
- // afterEach(inject(($exceptionHandler, $httpBackend, $rootScope) => {
1170
- // forEach($exceptionHandler.errors, (e) => {
1171
- // dump("Unhandled exception: ", e);
1172
- // });
1173
-
1174
- // if ($exceptionHandler.errors.length) {
1175
- // throw "Unhandled exceptions trapped in $exceptionHandler!";
1176
- // }
1177
-
1178
- // $httpBackend.verifyNoOutstandingExpectation();
1179
- // }));
1180
-
1181
- // describe("$httpProvider", () => {
1182
- // describe("interceptors", () => {
1183
- // it("should chain request, requestReject, response and responseReject interceptors", () => {
1184
- // module(($httpProvider) => {
1185
- // let savedConfig;
1186
- // let savedResponse;
1187
- // $httpProvider.interceptors.push(($q) => ({
1188
- // request(config) {
1189
- // config.url += "/1";
1190
- // savedConfig = config;
1191
- // return $q.reject("/2");
1192
- // },
1193
- // }));
1194
- // $httpProvider.interceptors.push(($q) => ({
1195
- // requestError(error) {
1196
- // savedConfig.url += error;
1197
- // return Promise.resolve(savedConfig);
1198
- // },
1199
- // }));
1200
- // $httpProvider.interceptors.push(() => ({
1201
- // responseError(rejection) {
1202
- // savedResponse.data += rejection;
1203
- // return savedResponse;
1204
- // },
1205
- // }));
1206
- // $httpProvider.interceptors.push(($q) => ({
1207
- // response(response) {
1208
- // response.data += ":1";
1209
- // savedResponse = response;
1210
- // return $q.reject(":2");
1211
- // },
1212
- // }));
1213
- // });
1214
- // inject(($http, $httpBackend, $rootScope) => {
1215
- // let response;
1216
- // $httpBackend.expect("GET", "/url/1/2").respond("response");
1217
- // await $http({ method: "GET", url: "/url" }).then((r) => {
1218
- // response = r;
1219
- // });
1220
- // await wait();
1221
- // $httpBackend.flush();
1222
- // expect(response.data).toEqual("response:1:2");
1223
- // });
1224
- // });
1225
-
1226
- // it("should verify order of execution", () => {
1227
- // module(($httpProvider) => {
1228
- // $httpProvider.interceptors.push(($q) => ({
1229
- // request(config) {
1230
- // config.url += "/outer";
1231
- // return config;
1232
- // },
1233
- // response(response) {
1234
- // response.data = `{${response.data}} outer`;
1235
- // return response;
1236
- // },
1237
- // }));
1238
- // $httpProvider.interceptors.push(($q) => ({
1239
- // request(config) {
1240
- // config.url += "/inner";
1241
- // return config;
1242
- // },
1243
- // response(response) {
1244
- // response.data = `{${response.data}} inner`;
1245
- // return response;
1246
- // },
1247
- // }));
1248
- // });
1249
- // inject(($http, $httpBackend) => {
1250
- // let response;
1251
- // $httpBackend.expect("GET", "/url/outer/inner").respond("response");
1252
- // await $http({ method: "GET", url: "/url" }).then((r) => {
1253
- // response = r;
1254
- // });
1255
- // $httpBackend.flush();
1256
- // expect(response.data).toEqual("{{response} inner} outer");
1257
- // });
1258
- // });
1259
- // });
1260
-
1261
- // describe("request interceptors", () => {
1262
- // it("should pass request config as a promise", () => {
1263
- // let run = false;
1264
- // module(($httpProvider) => {
1265
- // $httpProvider.interceptors.push(() => ({
1266
- // request(config) {
1267
- // expect(config.url).toEqual("/url");
1268
- // expect(config.data).toEqual({ one: "two" });
1269
- // expect(config.headers.foo).toEqual("bar");
1270
- // run = true;
1271
- // return config;
1272
- // },
1273
- // }));
1274
- // });
1275
- // inject(($http, $httpBackend, $rootScope) => {
1276
- // $httpBackend.expect("POST", "/url").respond("");
1277
- // await $http({
1278
- // method: "POST",
1279
- // url: "/url",
1280
- // data: { one: "two" },
1281
- // headers: { foo: "bar" },
1282
- // });
1283
- // await wait();
1284
- // expect(run).toEqual(true);
1285
- // });
1286
- // });
1287
-
1288
- // it("should allow manipulation of request", () => {
1289
- // module(($httpProvider) => {
1290
- // $httpProvider.interceptors.push(() => ({
1291
- // request(config) {
1292
- // config.url = "/intercepted";
1293
- // config.headers.foo = "intercepted";
1294
- // return config;
1295
- // },
1296
- // }));
1297
- // });
1298
- // inject(($http, $httpBackend, $rootScope) => {
1299
- // $httpBackend
1300
- // .expect(
1301
- // "GET",
1302
- // "/intercepted",
1303
- // null,
1304
- // (headers) => headers.foo === "intercepted",
1305
- // )
1306
- // .respond("");
1307
- // $http.get("/url");
1308
- // await wait();
1309
- // });
1310
- // });
1311
-
1312
- // it("should allow replacement of the headers object", () => {
1313
- // module(($httpProvider) => {
1314
- // $httpProvider.interceptors.push(() => ({
1315
- // request(config) {
1316
- // config.headers = { foo: "intercepted" };
1317
- // return config;
1318
- // },
1319
- // }));
1320
- // });
1321
- // inject(($http, $httpBackend, $rootScope) => {
1322
- // $httpBackend
1323
- // .expect("GET", "/url", null, (headers) =>
1324
- // angular.equals(headers, { foo: "intercepted" }),
1325
- // )
1326
- // .respond("");
1327
- // $http.get("/url");
1328
- // await wait();
1329
- // });
1330
- // });
1331
-
1332
- // it("should reject the http promise if an interceptor fails", () => {
1333
- // const reason = new Error("interceptor failed");
1334
- // module(($httpProvider) => {
1335
- // $httpProvider.interceptors.push(($q) => ({
1336
- // request(promise) {
1337
- // return $q.reject(reason);
1338
- // },
1339
- // }));
1340
- // });
1341
- // inject(($http, $httpBackend, $rootScope) => {
1342
- // const success = jasmine.createSpy();
1343
- // const error = jasmine.createSpy();
1344
- // $http.get("/url").then(success, error);
1345
- // await wait();
1346
- // expect(success).not.toHaveBeenCalled();
1347
- // expect(error).toHaveBeenCalledWith(reason);
1348
- // });
1349
- // });
1350
-
1351
- // it("should not manipulate the passed-in config", () => {
1352
- // module(($httpProvider) => {
1353
- // $httpProvider.interceptors.push(() => ({
1354
- // request(config) {
1355
- // config.url = "/intercepted";
1356
- // config.headers.foo = "intercepted";
1357
- // return config;
1358
- // },
1359
- // }));
1360
- // });
1361
- // inject(($http, $httpBackend, $rootScope) => {
1362
- // const config = { headers: { foo: "bar" } };
1363
- // const configCopy = angular.copy(config);
1364
- // $httpBackend.expect("GET", "/intercepted").respond("");
1365
- // $http.get("/url", config);
1366
- // await wait();
1367
- // expect(config).toEqual(configCopy);
1368
- // $httpBackend.expect("POST", "/intercepted").respond("");
1369
- // $http.post("/url", { bar: "baz" }, config);
1370
- // await wait();
1371
- // expect(config).toEqual(configCopy);
1372
- // });
1373
- // });
1374
-
1375
- // it("should support interceptors defined as services", () => {
1376
- // module(($provide, $httpProvider) => {
1377
- // $provide.factory("myInterceptor", () => ({
1378
- // request(config) {
1379
- // config.url = "/intercepted";
1380
- // return config;
1381
- // },
1382
- // }));
1383
- // $httpProvider.interceptors.push("myInterceptor");
1384
- // });
1385
- // inject(($http, $httpBackend, $rootScope) => {
1386
- // $httpBackend.expect("POST", "/intercepted").respond("");
1387
- // $http.post("/url");
1388
- // await wait();
1389
- // });
1390
- // });
1391
-
1392
- // it("should support complex interceptors based on promises", () => {
1393
- // module(($provide, $httpProvider) => {
1394
- // $provide.factory("myInterceptor", ($q, $rootScope) => ({
1395
- // request(config) {
1396
- // return Promise.resolve("/intercepted").then((intercepted) => {
1397
- // config.url = intercepted;
1398
- // return config;
1399
- // });
1400
- // },
1401
- // }));
1402
- // $httpProvider.interceptors.push("myInterceptor");
1403
- // });
1404
- // inject(($http, $httpBackend, $rootScope) => {
1405
- // $httpBackend.expect("POST", "/intercepted").respond("");
1406
- // $http.post("/two");
1407
- // await wait();
1408
- // });
1409
- // });
1410
- // });
1411
- // });
1412
-
1413
- // describe("the instance", () => {
1414
- // let $httpBackend;
1415
- // let $http;
1416
- // let $rootScope;
1417
- // let $sce;
1418
-
1419
- // beforeEach(
1420
- // module(($sceDelegateProvider) => {
1421
- // // Setup a special trusted url that we can use in testing JSONP requests
1422
- // $sceDelegateProvider.trustedResourceUrlList([
1423
- // "http://special.trusted.resource.com/**",
1424
- // ]);
1425
- // }),
1426
- // );
1427
-
1428
- // beforeEach(inject([
1429
- // "$httpBackend",
1430
- // "$http",
1431
- // "$rootScope",
1432
- // "$sce",
1433
- // function ($hb, $h, $rs, $sc) {
1434
- // $httpBackend = $hb;
1435
- // $http = $h;
1436
- // $rootScope = $rs;
1437
- // $sce = $sc;
1438
- // spyOn($rootScope, "$apply").and.callThrough();
1439
- // },
1440
- // ]));
1441
-
1442
- // it("should throw error if the request configuration is not an object", () => {
1443
- // expect(() => {
1444
- // $http("/url");
1445
- // }).toThrow(
1446
- // "$http",
1447
- // "badreq",
1448
- // "Http request configuration must be an object. Received: /url",
1449
- // );
1450
- // });
1451
-
1452
- // it("should throw error if the request configuration url is not a string nor a trusted object", () => {
1453
- // expect(() => {
1454
- // await $http({ url: false });
1455
- // }).toThrow(
1456
- // "$http",
1457
- // "badreq",
1458
- // "Http request configuration url must be a string or a $sce trusted object. Received: false",
1459
- // );
1460
- // expect(() => {
1461
- // await $http({ url: null });
1462
- // }).toThrow(
1463
- // "$http",
1464
- // "badreq",
1465
- // "Http request configuration url must be a string or a $sce trusted object. Received: null",
1466
- // );
1467
- // expect(() => {
1468
- // await $http({ url: 42 });
1469
- // }).toThrow(
1470
- // "$http",
1471
- // "badreq",
1472
- // "Http request configuration url must be a string or a $sce trusted object. Received: 42",
1473
- // );
1474
- // expect(() => {
1475
- // await $http({});
1476
- // }).toThrow(
1477
- // "$http",
1478
- // "badreq",
1479
- // "Http request configuration url must be a string or a $sce trusted object. Received: undefined",
1480
- // );
1481
- // });
1482
-
1483
- // it("should accept a $sce trusted object for the request configuration url", () => {
1484
- // $httpBackend.expect("GET", "/url").respond("");
1485
- // await $http({ url: $sce.trustAsResourceUrl("/url") });
1486
- // });
1487
-
1488
- // it("should send GET requests if no method specified", () => {
1489
- // $httpBackend.expect("GET", "/url").respond("");
1490
- // await $http({ url: "/url" });
1491
- // });
1492
-
1493
- // it("should do basic request", () => {
1494
- // $httpBackend.expect("GET", "/url").respond("");
1495
- // await $http({ url: "/url", method: "GET" });
1496
- // });
1497
-
1498
- // it("should pass data if specified", () => {
1499
- // $httpBackend.expect("POST", "/url", "some-data").respond("");
1500
- // await $http({ url: "/url", method: "POST", data: "some-data" });
1501
- // });
1502
-
1503
- // describe("params", () => {
1504
- // it("should do basic request with params and encode", () => {
1505
- // $httpBackend.expect("GET", "/url?a%3D=%3F%26&b=2").respond("");
1506
- // await $http({ url: "/url", params: { "a=": "?&", b: 2 }, method: "GET" });
1507
- // });
1508
-
1509
- // it("should merge params if url contains some already", () => {
1510
- // $httpBackend.expect("GET", "/url?c=3&a=1&b=2").respond("");
1511
- // await $http({ url: "/url?c=3", params: { a: 1, b: 2 }, method: "GET" });
1512
- // });
1513
-
1514
- // it("should jsonify objects in params map", () => {
1515
- // $httpBackend.expect("GET", "/url?a=1&b=%7B%22c%22:3%7D").respond("");
1516
- // await $http({ url: "/url", params: { a: 1, b: { c: 3 } }, method: "GET" });
1517
- // });
1518
-
1519
- // it("should expand arrays in params map", () => {
1520
- // $httpBackend.expect("GET", "/url?a=1&a=2&a=3").respond("");
1521
- // await $http({ url: "/url", params: { a: [1, 2, 3] }, method: "GET" });
1522
- // });
1523
-
1524
- // it("should not encode @ in url params", () => {
1525
- // // encodeURIComponent is too aggressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt
1526
- // // with regards to the character set (pchar) allowed in path segments
1527
- // // so we need this test to make sure that we don't over-encode the params and break stuff
1528
- // // like buzz api which uses @self
1529
-
1530
- // $httpBackend
1531
- // .expect("GET", "/Path?!do%26h=g%3Da+h&:bar=$baz@1")
1532
- // .respond("");
1533
- // await $http({
1534
- // url: "/Path",
1535
- // params: { ":bar": "$baz@1", "!do&h": "g=a h" },
1536
- // method: "GET",
1537
- // });
1538
- // });
1539
-
1540
- // it("should not add question mark when params is empty", () => {
1541
- // $httpBackend.expect("GET", "/url").respond("");
1542
- // await $http({ url: "/url", params: {}, method: "GET" });
1543
- // });
1544
-
1545
- // it("should not double quote dates", () => {
1546
- // $httpBackend
1547
- // .expect("GET", "/url?date=2014-07-15T17:30:00.000Z")
1548
- // .respond("");
1549
- // await $http({
1550
- // url: "/url",
1551
- // params: { date: new Date("2014-07-15T17:30:00.000Z") },
1552
- // method: "GET",
1553
- // });
1554
- // });
1555
-
1556
- // describe("custom params serialization", () => {
1557
- // it("should allow specifying custom paramSerializer as function", () => {
1558
- // $httpBackend.expect("GET", "/url?foo_bar").respond("");
1559
- // await $http({
1560
- // url: "/url",
1561
- // params: { foo: "fooVal", bar: "barVal" },
1562
- // paramSerializer: customParamSerializer,
1563
- // });
1564
- // });
1565
-
1566
- // it("should allow specifying custom paramSerializer as function from DI", () => {
1567
- // $httpBackend.expect("GET", "/url?foo_bar").respond("");
1568
- // await $http({
1569
- // url: "/url",
1570
- // params: { foo: "fooVal", bar: "barVal" },
1571
- // paramSerializer: "customParamSerializer",
1572
- // });
1573
- // });
1574
- // });
1575
- // });
1576
-
1577
- // describe("callbacks", () => {
1578
- // it("should pass in the response object when a request is successful", () => {
1579
- // $httpBackend
1580
- // .expect("GET", "/url")
1581
- // .respond(207, "my content", { "content-encoding": "smurf" });
1582
- // await $http({ url: "/url", method: "GET" }).then((response) => {
1583
- // expect(response.data).toBe("my content");
1584
- // expect(response.status).toBe(207);
1585
- // expect(response.headers()).toEqual(
1586
- // extend(Object.create(null), { "content-encoding": "smurf" }),
1587
- // );
1588
- // expect(response.config.url).toBe("/url");
1589
- // callback();
1590
- // });
1591
-
1592
- // $httpBackend.flush();
1593
- // expect(callback).toHaveBeenCalled();
1594
- // });
1595
-
1596
- // it("should pass statusText in response object when a request is successful", () => {
1597
- // $httpBackend.expect("GET", "/url").respond(200, "SUCCESS", {}, "OK");
1598
- // await $http({ url: "/url", method: "GET" }).then((response) => {
1599
- // expect(response.statusText).toBe("OK");
1600
- // callback();
1601
- // });
1602
-
1603
- // $httpBackend.flush();
1604
- // expect(callback).toHaveBeenCalled();
1605
- // });
1606
-
1607
- // it("should pass statusText in response object when a request fails", () => {
1608
- // $httpBackend
1609
- // .expect("GET", "/url")
1610
- // .respond(404, "ERROR", {}, "Not Found");
1611
- // await $http({ url: "/url", method: "GET" }).then(null, (response) => {
1612
- // expect(response.statusText).toBe("Not Found");
1613
- // callback();
1614
- // });
1615
-
1616
- // $httpBackend.flush();
1617
- // expect(callback).toHaveBeenCalled();
1618
- // });
1619
-
1620
- // it("should pass xhrStatus in response object when a request is successful", () => {
1621
- // $httpBackend.expect("GET", "/url").respond(200, "SUCCESS", {}, "OK");
1622
- // await $http({ url: "/url", method: "GET" }).then((response) => {
1623
- // expect(response.xhrStatus).toBe("complete");
1624
- // callback();
1625
- // });
1626
-
1627
- // $httpBackend.flush();
1628
- // expect(callback).toHaveBeenCalled();
1629
- // });
1630
-
1631
- // it("should pass xhrStatus in response object when a request fails", () => {
1632
- // $httpBackend
1633
- // .expect("GET", "/url")
1634
- // .respond(404, "ERROR", {}, "Not Found");
1635
- // await $http({ url: "/url", method: "GET" }).then(null, (response) => {
1636
- // expect(response.xhrStatus).toBe("complete");
1637
- // callback();
1638
- // });
1639
-
1640
- // $httpBackend.flush();
1641
- // expect(callback).toHaveBeenCalled();
1642
- // });
1643
-
1644
- // it("should pass in the response object when a request failed", () => {
1645
- // $httpBackend
1646
- // .expect("GET", "/url")
1647
- // .respond(543, "bad error", { "request-id": "123" });
1648
- // await $http({ url: "/url", method: "GET" }).then(null, (response) => {
1649
- // expect(response.data).toBe("bad error");
1650
- // expect(response.status).toBe(543);
1651
- // expect(response.headers()).toEqual(
1652
- // extend(Object.create(null), { "request-id": "123" }),
1653
- // );
1654
- // expect(response.config.url).toBe("/url");
1655
- // callback();
1656
- // });
1657
-
1658
- // $httpBackend.flush();
1659
- // expect(callback).toHaveBeenCalled();
1660
- // });
1661
- // });
1662
-
1663
- // describe("response headers", () => {
1664
- // it("should return single header", () => {
1665
- // $httpBackend.expect("GET", "/url").respond("", { date: "date-val" });
1666
- // callback.and.callFake((r) => {
1667
- // expect(r.headers("date")).toBe("date-val");
1668
- // });
1669
-
1670
- // await $http({ url: "/url", method: "GET" }).then(callback);
1671
- // $httpBackend.flush();
1672
-
1673
- // expect(callback).toHaveBeenCalled();
1674
- // });
1675
-
1676
- // it("should return null when single header does not exist", () => {
1677
- // $httpBackend
1678
- // .expect("GET", "/url")
1679
- // .respond("", { "Some-Header": "Fake" });
1680
- // callback.and.callFake((r) => {
1681
- // r.headers(); // we need that to get headers parsed first
1682
- // expect(r.headers("nothing")).toBe(null);
1683
- // });
1684
-
1685
- // await $http({ url: "/url", method: "GET" }).then(callback);
1686
- // $httpBackend.flush();
1687
-
1688
- // expect(callback).toHaveBeenCalled();
1689
- // });
1690
-
1691
- // it("should return all headers as object", () => {
1692
- // $httpBackend.expect("GET", "/url").respond("", {
1693
- // "content-encoding": "gzip",
1694
- // server: "Apache",
1695
- // });
1696
-
1697
- // callback.and.callFake((r) => {
1698
- // expect(r.headers()).toEqual(
1699
- // extend(Object.create(null), {
1700
- // "content-encoding": "gzip",
1701
- // server: "Apache",
1702
- // }),
1703
- // );
1704
- // });
1705
-
1706
- // await $http({ url: "/url", method: "GET" }).then(callback);
1707
- // $httpBackend.flush();
1708
-
1709
- // expect(callback).toHaveBeenCalled();
1710
- // });
1711
-
1712
- // it("should return empty object for jsonp request", () => {
1713
- // callback.and.callFake((r) => {
1714
- // expect(r.headers()).toEqual(Object.create(null));
1715
- // });
1716
-
1717
- // $httpBackend
1718
- // .expect("JSONP", "/some?callback=JSON_CALLBACK")
1719
- // .respond(200);
1720
- // await $http({ url: $sce.trustAsResourceUrl("/some"), method: "JSONP" }).then(
1721
- // callback,
1722
- // );
1723
- // $httpBackend.flush();
1724
- // expect(callback).toHaveBeenCalled();
1725
- // });
1726
- // });
1727
-
1728
- // describe("response headers parser", () =>
1729
-
1730
- // it("should parse basic", () => {
1731
- // const parsed = parseHeaders(
1732
- // "date: Thu, 04 Aug 2011 20:23:08 GMT\n" +
1733
- // "content-encoding: gzip\n" +
1734
- // "transfer-encoding: chunked\n" +
1735
- // "x-cache-info: not cacheable; response has already expired, not cacheable; response has already expired\n" +
1736
- // "connection: Keep-Alive\n" +
1737
- // "x-backend-server: pm-dekiwiki03\n" +
1738
- // "pragma: no-cache\n" +
1739
- // "server: Apache\n" +
1740
- // "x-frame-options: DENY\n" +
1741
- // "content-type: text/html; charset=utf-8\n" +
1742
- // "vary: Cookie, Accept-Encoding\n" +
1743
- // "keep-alive: timeout=5, max=1000\n" +
1744
- // "expires: Thu: , 19 Nov 1981 08:52:00 GMT\n",
1745
- // );
1746
-
1747
- // expect(parsed.date).toBe("Thu, 04 Aug 2011 20:23:08 GMT");
1748
- // expect(parsed["content-encoding"]).toBe("gzip");
1749
- // expect(parsed["transfer-encoding"]).toBe("chunked");
1750
- // expect(parsed["keep-alive"]).toBe("timeout=5, max=1000");
1751
- // });
1752
-
1753
- // it("should parse lines without space after colon", () => {
1754
- // expect(parseHeaders("key:value").key).toBe("value");
1755
- // });
1756
-
1757
- // it("should trim the values", () => {
1758
- // expect(parseHeaders("key: value ").key).toBe("value");
1759
- // });
1760
-
1761
- // it("should allow headers without value", () => {
1762
- // expect(parseHeaders("key:").key).toBe("");
1763
- // });
1764
-
1765
- // it("should merge headers with same key", () => {
1766
- // expect(parseHeaders("key: a\nkey:b\n").key).toBe("a, b");
1767
- // });
1768
-
1769
- // it("should normalize keys to lower case", () => {
1770
- // expect(parseHeaders("KeY: value").key).toBe("value");
1771
- // });
1772
-
1773
- // it("should parse CRLF as delimiter", () => {
1774
- // // IE does use CRLF
1775
- // expect(parseHeaders("a: b\r\nc: d\r\n")).toEqual(
1776
- // extend(Object.create(null), { a: "b", c: "d" }),
1777
- // );
1778
- // expect(parseHeaders("a: b\r\nc: d\r\n").a).toBe("b");
1779
- // });
1780
-
1781
- // it("should parse tab after semi-colon", () => {
1782
- // expect(parseHeaders("a:\tbb").a).toBe("bb");
1783
- // expect(parseHeaders("a: \tbb").a).toBe("bb");
1784
- // });
1785
-
1786
- // it("should parse multiple values for the same header", () => {
1787
- // expect(parseHeaders("key:value1\nkey:value2").key).toBe(
1788
- // "value1, value2",
1789
- // );
1790
- // });
1791
- // });
1792
-
1793
- // describe("request headers", () => {
1794
- // it("should send custom headers", () => {
1795
- // $httpBackend
1796
- // .expect(
1797
- // "GET",
1798
- // "/url",
1799
- // undefined,
1800
- // (headers) => headers.Custom === "header",
1801
- // )
1802
- // .respond("");
1803
-
1804
- // await $http({
1805
- // url: "/url",
1806
- // method: "GET",
1807
- // headers: {
1808
- // Custom: "header",
1809
- // },
1810
- // });
1811
-
1812
- // $httpBackend.flush();
1813
- // });
1814
-
1815
- // it("should set default headers for GET request", () => {
1816
- // $httpBackend
1817
- // .expect(
1818
- // "GET",
1819
- // "/url",
1820
- // undefined,
1821
- // (headers) => headers.Accept === "application/json, text/plain, */*",
1822
- // )
1823
- // .respond("");
1824
-
1825
- // await $http({ url: "/url", method: "GET", headers: {} });
1826
- // $httpBackend.flush();
1827
- // });
1828
-
1829
- // it("should set default headers for POST request", () => {
1830
- // $httpBackend
1831
- // .expect(
1832
- // "POST",
1833
- // "/url",
1834
- // "messageBody",
1835
- // (headers) =>
1836
- // headers.Accept === "application/json, text/plain, */*" &&
1837
- // headers["Content-Type"] === "application/json;charset=utf-8",
1838
- // )
1839
- // .respond("");
1840
-
1841
- // await $http({
1842
- // url: "/url",
1843
- // method: "POST",
1844
- // headers: {},
1845
- // data: "messageBody",
1846
- // });
1847
- // $httpBackend.flush();
1848
- // });
1849
-
1850
- // it("should set default headers for PUT request", () => {
1851
- // $httpBackend
1852
- // .expect(
1853
- // "PUT",
1854
- // "/url",
1855
- // "messageBody",
1856
- // (headers) =>
1857
- // headers.Accept === "application/json, text/plain, */*" &&
1858
- // headers["Content-Type"] === "application/json;charset=utf-8",
1859
- // )
1860
- // .respond("");
1861
-
1862
- // await $http({ url: "/url", method: "PUT", headers: {}, data: "messageBody" });
1863
- // $httpBackend.flush();
1864
- // });
1865
-
1866
- // it("should set default headers for PATCH request", () => {
1867
- // $httpBackend
1868
- // .expect(
1869
- // "PATCH",
1870
- // "/url",
1871
- // "messageBody",
1872
- // (headers) =>
1873
- // headers.Accept === "application/json, text/plain, */*" &&
1874
- // headers["Content-Type"] === "application/json;charset=utf-8",
1875
- // )
1876
- // .respond("");
1877
-
1878
- // await $http({
1879
- // url: "/url",
1880
- // method: "PATCH",
1881
- // headers: {},
1882
- // data: "messageBody",
1883
- // });
1884
- // $httpBackend.flush();
1885
- // });
1886
-
1887
- // it("should set default headers for custom HTTP method", () => {
1888
- // $httpBackend
1889
- // .expect(
1890
- // "FOO",
1891
- // "/url",
1892
- // undefined,
1893
- // (headers) => headers.Accept === "application/json, text/plain, */*",
1894
- // )
1895
- // .respond("");
1896
-
1897
- // await $http({ url: "/url", method: "FOO", headers: {} });
1898
- // $httpBackend.flush();
1899
- // });
1900
-
1901
- // it("should override default headers with custom", () => {
1902
- // $httpBackend
1903
- // .expect(
1904
- // "POST",
1905
- // "/url",
1906
- // "messageBody",
1907
- // (headers) =>
1908
- // headers.Accept === "Rewritten" &&
1909
- // headers["Content-Type"] === "Rewritten",
1910
- // )
1911
- // .respond("");
1912
-
1913
- // await $http({
1914
- // url: "/url",
1915
- // method: "POST",
1916
- // data: "messageBody",
1917
- // headers: {
1918
- // Accept: "Rewritten",
1919
- // "Content-Type": "Rewritten",
1920
- // },
1921
- // });
1922
- // $httpBackend.flush();
1923
- // });
1924
-
1925
- // it("should delete default headers if custom header function returns null", () => {
1926
- // $httpBackend
1927
- // .expect(
1928
- // "POST",
1929
- // "/url",
1930
- // "messageBody",
1931
- // (headers) => !("Accept" in headers),
1932
- // )
1933
- // .respond("");
1934
-
1935
- // await $http({
1936
- // url: "/url",
1937
- // method: "POST",
1938
- // data: "messageBody",
1939
- // headers: {
1940
- // Accept: function() {
1941
- // return null;
1942
- // },
1943
- // },
1944
- // });
1945
- // $httpBackend.flush();
1946
- // });
1947
-
1948
- // it("should override default headers with custom in a case insensitive manner", () => {
1949
- // $httpBackend
1950
- // .expect(
1951
- // "POST",
1952
- // "/url",
1953
- // "messageBody",
1954
- // (headers) =>
1955
- // headers.accept === "Rewritten" &&
1956
- // headers["content-type"] === "Content-Type Rewritten" &&
1957
- // isUndefined(headers.Accept) &&
1958
- // isUndefined(headers["Content-Type"]),
1959
- // )
1960
- // .respond("");
1961
-
1962
- // await $http({
1963
- // url: "/url",
1964
- // method: "POST",
1965
- // data: "messageBody",
1966
- // headers: {
1967
- // accept: "Rewritten",
1968
- // "content-type": "Content-Type Rewritten",
1969
- // },
1970
- // });
1971
- // $httpBackend.flush();
1972
- // });
1973
-
1974
- // it("should not send Content-Type header if request data/body is undefined", () => {
1975
- // $httpBackend
1976
- // .expect(
1977
- // "POST",
1978
- // "/url",
1979
- // undefined,
1980
- // (headers) => !headers.hasOwnProperty("Content-Type"),
1981
- // )
1982
- // .respond("");
1983
-
1984
- // $httpBackend
1985
- // .expect(
1986
- // "POST",
1987
- // "/url2",
1988
- // undefined,
1989
- // (headers) => !headers.hasOwnProperty("content-type"),
1990
- // )
1991
- // .respond("");
1992
-
1993
- // await $http({ url: "/url", method: "POST" });
1994
- // await $http({
1995
- // url: "/url2",
1996
- // method: "POST",
1997
- // headers: { "content-type": "Rewritten" },
1998
- // });
1999
- // $httpBackend.flush();
2000
- // });
2001
-
2002
- // it("should NOT delete Content-Type header if request data/body is set by request transform", () => {
2003
- // $httpBackend
2004
- // .expect(
2005
- // "POST",
2006
- // "/url",
2007
- // { one: "two" },
2008
- // (headers) =>
2009
- // headers["Content-Type"] === "application/json;charset=utf-8",
2010
- // )
2011
- // .respond("");
2012
-
2013
- // await $http({
2014
- // url: "/url",
2015
- // method: "POST",
2016
- // transformRequest(data) {
2017
- // data = { one: "two" };
2018
- // return data;
2019
- // },
2020
- // });
2021
-
2022
- // $httpBackend.flush();
2023
- // });
2024
-
2025
- // it("should send execute result if header value is function", () => {
2026
- // const headerConfig = {
2027
- // Accept: function () {
2028
- // return "Rewritten";
2029
- // },
2030
- // };
2031
-
2032
- // function checkHeaders(headers) {
2033
- // return headers.Accept === "Rewritten";
2034
- // }
2035
-
2036
- // $httpBackend.expect("GET", "/url", undefined, checkHeaders).respond("");
2037
- // $httpBackend
2038
- // .expect("POST", "/url", undefined, checkHeaders)
2039
- // .respond("");
2040
- // $httpBackend.expect("PUT", "/url", undefined, checkHeaders).respond("");
2041
- // $httpBackend
2042
- // .expect("PATCH", "/url", undefined, checkHeaders)
2043
- // .respond("");
2044
- // $httpBackend
2045
- // .expect("DELETE", "/url", undefined, checkHeaders)
2046
- // .respond("");
2047
-
2048
- // await $http({ url: "/url", method: "GET", headers: headerConfig });
2049
- // await $http({ url: "/url", method: "POST", headers: headerConfig });
2050
- // await $http({ url: "/url", method: "PUT", headers: headerConfig });
2051
- // await $http({ url: "/url", method: "PATCH", headers: headerConfig });
2052
- // await $http({ url: "/url", method: "DELETE", headers: headerConfig });
2053
-
2054
- // $httpBackend.flush();
2055
- // });
2056
-
2057
- // it("should expose a config object to header functions", () => {
2058
- // const config = {
2059
- // foo: "Rewritten",
2060
- // headers: {
2061
- // Accept: function (config) {
2062
- // return config.foo;
2063
- // },
2064
- // },
2065
- // };
2066
-
2067
- // $httpBackend
2068
- // .expect("GET", "/url", undefined, { Accept: "Rewritten" })
2069
- // .respond("");
2070
- // $http.get("/url", config);
2071
- // $httpBackend.flush();
2072
- // });
2073
-
2074
- // it("should not allow modifications to a config object in header functions", () => {
2075
- // const config = {
2076
- // headers: {
2077
- // Accept: function (config) {
2078
- // config.foo = "bar";
2079
- // return "Rewritten";
2080
- // },
2081
- // },
2082
- // };
2083
-
2084
- // $httpBackend
2085
- // .expect("GET", "/url", undefined, { Accept: "Rewritten" })
2086
- // .respond("");
2087
- // $http.get("/url", config);
2088
- // $httpBackend.flush();
2089
-
2090
- // expect(config.foo).toBeUndefined();
2091
- // });
2092
- // });
2093
-
2094
- // describe("short methods", () => {
2095
- // function checkHeader(name, value) {
2096
- // return function (headers) {
2097
- // return headers[name] === value;
2098
- // };
2099
- // }
2100
-
2101
- // it("should have get()", () => {
2102
- // $httpBackend.expect("GET", "/url").respond("");
2103
- // $http.get("/url");
2104
- // });
2105
-
2106
- // it("get() should allow config param", () => {
2107
- // $httpBackend
2108
- // .expect("GET", "/url", undefined, checkHeader("Custom", "Header"))
2109
- // .respond("");
2110
- // $http.get("/url", { headers: { Custom: "Header" } });
2111
- // });
2112
-
2113
- // it("should handle empty response header", () => {
2114
- // $httpBackend.expect("GET", "/url", undefined).respond(200, "", {
2115
- // "Custom-Empty-Response-Header": "",
2116
- // Constructor: "",
2117
- // });
2118
- // $http.get("/url").then(callback);
2119
- // $httpBackend.flush();
2120
- // expect(callback).toHaveBeenCalled();
2121
- // const { headers } = callback.calls.mostRecent().args[0];
2122
- // expect(headers("custom-empty-response-Header")).toEqual("");
2123
- // expect(headers("ToString")).toBe(null);
2124
- // expect(headers("Constructor")).toBe("");
2125
- // });
2126
-
2127
- // it("should have delete()", () => {
2128
- // $httpBackend.expect("DELETE", "/url").respond("");
2129
- // $http.delete("/url");
2130
- // });
2131
-
2132
- // it("delete() should allow config param", () => {
2133
- // $httpBackend
2134
- // .expect("DELETE", "/url", undefined, checkHeader("Custom", "Header"))
2135
- // .respond("");
2136
- // $http.delete("/url", { headers: { Custom: "Header" } });
2137
- // });
2138
-
2139
- // it("should have head()", () => {
2140
- // $httpBackend.expect("HEAD", "/url").respond("");
2141
- // $http.head("/url");
2142
- // });
2143
-
2144
- // it("head() should allow config param", () => {
2145
- // $httpBackend
2146
- // .expect("HEAD", "/url", undefined, checkHeader("Custom", "Header"))
2147
- // .respond("");
2148
- // $http.head("/url", { headers: { Custom: "Header" } });
2149
- // });
2150
-
2151
- // it("should have post()", () => {
2152
- // $httpBackend.expect("POST", "/url", "some-data").respond("");
2153
- // $http.post("/url", "some-data");
2154
- // });
2155
-
2156
- // it("post() should allow config param", () => {
2157
- // $httpBackend
2158
- // .expect("POST", "/url", "some-data", checkHeader("Custom", "Header"))
2159
- // .respond("");
2160
- // $http.post("/url", "some-data", { headers: { Custom: "Header" } });
2161
- // });
2162
-
2163
- // it("should have put()", () => {
2164
- // $httpBackend.expect("PUT", "/url", "some-data").respond("");
2165
- // $http.put("/url", "some-data");
2166
- // });
2167
-
2168
- // it("put() should allow config param", () => {
2169
- // $httpBackend
2170
- // .expect("PUT", "/url", "some-data", checkHeader("Custom", "Header"))
2171
- // .respond("");
2172
- // $http.put("/url", "some-data", { headers: { Custom: "Header" } });
2173
- // });
2174
-
2175
- // it("should have patch()", () => {
2176
- // $httpBackend.expect("PATCH", "/url", "some-data").respond("");
2177
- // $http.patch("/url", "some-data");
2178
- // });
2179
-
2180
- // it("patch() should allow config param", () => {
2181
- // $httpBackend
2182
- // .expect("PATCH", "/url", "some-data", checkHeader("Custom", "Header"))
2183
- // .respond("");
2184
- // $http.patch("/url", "some-data", { headers: { Custom: "Header" } });
2185
- // });
2186
-
2187
- // });
2188
- // describe("callbacks", () => {
2189
- // it("should $apply after success callback", () => {
2190
- // $httpBackend.when("GET").respond(200);
2191
- // await $http({ method: "GET", url: "/some" });
2192
- // $httpBackend.flush();
2193
- // expect($rootScope.$apply).toHaveBeenCalled();
2194
- // });
2195
-
2196
- // it("should $apply after error callback", () => {
2197
- // $httpBackend.when("GET").respond(404);
2198
- // await $http({ method: "GET", url: "/some" }).catch(() => {});
2199
- // $httpBackend.flush();
2200
- // expect($rootScope.$apply).toHaveBeenCalled();
2201
- // });
2202
-
2203
- // it("should $apply even if exception thrown during callback", inject((
2204
- // $exceptionHandler,
2205
- // ) => {
2206
- // $httpBackend.when("GET").respond(200);
2207
- // callback.and.throwError("error in callback");
2208
-
2209
- // await $http({ method: "GET", url: "/some" }).then(callback);
2210
- // $httpBackend.flush();
2211
- // expect($rootScope.$apply).toHaveBeenCalled();
2212
-
2213
- // $exceptionHandler.errors = [];
2214
- // }));
2215
-
2216
- // it("should pass the event handlers through to the backend", () => {
2217
- // const progressFn = jasmine.createSpy("progressFn");
2218
- // const uploadProgressFn = jasmine.createSpy("uploadProgressFn");
2219
- // $httpBackend.when("GET").respond(200);
2220
- // await $http({
2221
- // method: "GET",
2222
- // url: "/some",
2223
- // eventHandlers: { progress: progressFn },
2224
- // uploadEventHandlers: { progress: uploadProgressFn },
2225
- // });
2226
- // await wait();
2227
- // const mockXHR = MockXhr.$$lastInstance;
2228
- // expect(mockXHR.$$events.progress).toEqual(jasmine.any(Function));
2229
- // expect(mockXHR.upload.$$events.progress).toEqual(jasmine.any(Function));
2230
-
2231
- // const eventObj = {};
2232
- // spyOn($rootScope, "$digest");
2233
-
2234
- // mockXHR.$$events.progress(eventObj);
2235
- // expect(progressFn).toHaveBeenCalledOnceWith(eventObj);
2236
- // expect($rootScope.$digest).toHaveBeenCalledTimes(1);
2237
-
2238
- // mockXHR.upload.$$events.progress(eventObj);
2239
- // expect(uploadProgressFn).toHaveBeenCalledOnceWith(eventObj);
2240
- // expect($rootScope.$digest).toHaveBeenCalledTimes(2);
2241
- // });
2242
- // });
2243
-
2244
- // describe("transformData", () => {
2245
- // describe("request", () => {
2246
- // describe("default", () => {
2247
- // it("should transform object into json", () => {
2248
- // $httpBackend.expect("POST", "/url", '{"one":"two"}').respond("");
2249
- // await $http({ method: "POST", url: "/url", data: { one: "two" } });
2250
- // });
2251
-
2252
- // it("should transform object with date into json", () => {
2253
- // $httpBackend
2254
- // .expect("POST", "/url", {
2255
- // date: new Date(Date.UTC(2013, 11, 25)),
2256
- // })
2257
- // .respond("");
2258
- // await $http({
2259
- // method: "POST",
2260
- // url: "/url",
2261
- // data: { date: new Date(Date.UTC(2013, 11, 25)) },
2262
- // });
2263
- // });
2264
-
2265
- // it("should ignore strings", () => {
2266
- // $httpBackend.expect("POST", "/url", "string-data").respond("");
2267
- // await $http({ method: "POST", url: "/url", data: "string-data" });
2268
- // });
2269
-
2270
- // it("should ignore File objects", () => {
2271
- // const file = {
2272
- // some: true,
2273
- // // $httpBackend compares toJson values by default,
2274
- // // we need to be sure it's not serialized into json string
2275
- // test(actualValue) {
2276
- // return this === actualValue;
2277
- // },
2278
- // };
2279
-
2280
- // // I'm really sorry for doing this :-D
2281
- // // Unfortunately I don't know how to trick toString.apply(obj) comparison
2282
- // spyOn(window, "isFile").and.returnValue(true);
2283
-
2284
- // $httpBackend.expect("POST", "/some", file).respond("");
2285
- // await $http({ method: "POST", url: "/some", data: file });
2286
- // });
2287
- // });
2288
-
2289
- // it("should ignore Blob objects", () => {
2290
- // if (!window.Blob) return;
2291
-
2292
- // const blob = new Blob(["blob!"], { type: "text/plain" });
2293
-
2294
- // $httpBackend.expect("POST", "/url", "[object Blob]").respond("");
2295
- // await $http({ method: "POST", url: "/url", data: blob });
2296
- // });
2297
-
2298
- // it("should ignore FormData objects", () => {
2299
- // if (!window.FormData) return;
2300
-
2301
- // const formData = new FormData();
2302
- // formData.append("angular", "is great");
2303
-
2304
- // $httpBackend.expect("POST", "/url", "[object FormData]").respond("");
2305
- // await $http({ method: "POST", url: "/url", data: formData });
2306
- // });
2307
-
2308
- // it("should have access to request headers", () => {
2309
- // $httpBackend.expect("POST", "/url", "header1").respond(200);
2310
- // $http
2311
- // .post("/url", "req", {
2312
- // headers: { h1: "header1" },
2313
- // transformRequest(data, headers) {
2314
- // return headers("h1");
2315
- // },
2316
- // })
2317
- // .then(callback);
2318
- // $httpBackend.flush();
2319
-
2320
- // expect(callback).toHaveBeenCalled();
2321
- // });
2322
-
2323
- // it("should have access to request headers with mixed case", () => {
2324
- // $httpBackend.expect("POST", "/url", "header1").respond(200);
2325
- // $http
2326
- // .post("/url", "req", {
2327
- // headers: { H1: "header1" },
2328
- // transformRequest(data, headers) {
2329
- // return headers("H1");
2330
- // },
2331
- // })
2332
- // .then(callback);
2333
- // $httpBackend.flush();
2334
-
2335
- // expect(callback).toHaveBeenCalled();
2336
- // });
2337
-
2338
- // it("should not allow modifications to headers in a transform functions", () => {
2339
- // const config = {
2340
- // headers: { Accept: "bar" },
2341
- // transformRequest(data, headers) {
2342
- // angular.extend(headers(), {
2343
- // Accept: "foo",
2344
- // });
2345
- // },
2346
- // };
2347
-
2348
- // $httpBackend
2349
- // .expect("GET", "/url", undefined, { Accept: "bar" })
2350
- // .respond(200);
2351
- // $http.get("/url", config).then(callback);
2352
- // $httpBackend.flush();
2353
-
2354
- // expect(callback).toHaveBeenCalled();
2355
- // });
2356
-
2357
- // it("should pipeline more functions", () => {
2358
- // function first(d, h) {
2359
- // return `${d}-first:${h("h1")}`;
2360
- // }
2361
- // function second(d) {
2362
- // return uppercase(d);
2363
- // }
2364
-
2365
- // $httpBackend.expect("POST", "/url", "REQ-FIRST:V1").respond(200);
2366
- // $http
2367
- // .post("/url", "req", {
2368
- // headers: { h1: "v1" },
2369
- // transformRequest: [first, second],
2370
- // })
2371
- // .then(callback);
2372
- // $httpBackend.flush();
2373
-
2374
- // expect(callback).toHaveBeenCalled();
2375
- // });
2376
- // });
2377
-
2378
- // describe("response", () => {
2379
- // describe("default", () => {
2380
- // it("should deserialize json objects", () => {
2381
- // $httpBackend
2382
- // .expect("GET", "/url")
2383
- // .respond('{"foo":"bar","baz":23}');
2384
- // await $http({ method: "GET", url: "/url" }).then(callback);
2385
- // $httpBackend.flush();
2386
-
2387
- // expect(callback).toHaveBeenCalled();
2388
- // expect(callback.calls.mostRecent().args[0].data).toEqual({
2389
- // foo: "bar",
2390
- // baz: 23,
2391
- // });
2392
- // });
2393
-
2394
- // it("should deserialize json arrays", () => {
2395
- // $httpBackend
2396
- // .expect("GET", "/url")
2397
- // .respond('[1, "abc", {"foo":"bar"}]');
2398
- // await $http({ method: "GET", url: "/url" }).then(callback);
2399
- // $httpBackend.flush();
2400
-
2401
- // expect(callback).toHaveBeenCalled();
2402
- // expect(callback.calls.mostRecent().args[0].data).toEqual([
2403
- // 1,
2404
- // "abc",
2405
- // { foo: "bar" },
2406
- // ]);
2407
- // });
2408
-
2409
- // it("should ignore leading/trailing whitespace", () => {
2410
- // $httpBackend
2411
- // .expect("GET", "/url")
2412
- // .respond(' \n {"foo":"bar","baz":23} \r\n \n ');
2413
- // await $http({ method: "GET", url: "/url" }).then(callback);
2414
- // $httpBackend.flush();
2415
-
2416
- // expect(callback).toHaveBeenCalled();
2417
- // expect(callback.calls.mostRecent().args[0].data).toEqual({
2418
- // foo: "bar",
2419
- // baz: 23,
2420
- // });
2421
- // });
2422
-
2423
- // it("should deserialize json numbers when response header contains application/json", () => {
2424
- // $httpBackend
2425
- // .expect("GET", "/url")
2426
- // .respond("123", { "Content-Type": "application/json" });
2427
- // await $http({ method: "GET", url: "/url" }).then(callback);
2428
- // $httpBackend.flush();
2429
-
2430
- // expect(callback).toHaveBeenCalled();
2431
- // expect(callback.calls.mostRecent().args[0].data).toEqual(123);
2432
- // });
2433
-
2434
- // it("should deserialize json strings when response header contains application/json", () => {
2435
- // $httpBackend
2436
- // .expect("GET", "/url")
2437
- // .respond('"asdf"', { "Content-Type": "application/json" });
2438
- // await $http({ method: "GET", url: "/url" }).then(callback);
2439
- // $httpBackend.flush();
2440
-
2441
- // expect(callback).toHaveBeenCalled();
2442
- // expect(callback.calls.mostRecent().args[0].data).toEqual("asdf");
2443
- // });
2444
-
2445
- // it("should deserialize json nulls when response header contains application/json", () => {
2446
- // $httpBackend
2447
- // .expect("GET", "/url")
2448
- // .respond("null", { "Content-Type": "application/json" });
2449
- // await $http({ method: "GET", url: "/url" }).then(callback);
2450
- // $httpBackend.flush();
2451
-
2452
- // expect(callback).toHaveBeenCalled();
2453
- // expect(callback.calls.mostRecent().args[0].data).toEqual(null);
2454
- // });
2455
-
2456
- // it("should deserialize json true when response header contains application/json", () => {
2457
- // $httpBackend
2458
- // .expect("GET", "/url")
2459
- // .respond("true", { "Content-Type": "application/json" });
2460
- // await $http({ method: "GET", url: "/url" }).then(callback);
2461
- // $httpBackend.flush();
2462
-
2463
- // expect(callback).toHaveBeenCalled();
2464
- // expect(callback.calls.mostRecent().args[0].data).toEqual(true);
2465
- // });
2466
-
2467
- // it("should deserialize json false when response header contains application/json", () => {
2468
- // $httpBackend
2469
- // .expect("GET", "/url")
2470
- // .respond("false", { "Content-Type": "application/json" });
2471
- // await $http({ method: "GET", url: "/url" }).then(callback);
2472
- // $httpBackend.flush();
2473
-
2474
- // expect(callback).toHaveBeenCalled();
2475
- // expect(callback.calls.mostRecent().args[0].data).toEqual(false);
2476
- // });
2477
-
2478
- // it("should deserialize json empty string when response header contains application/json", () => {
2479
- // $httpBackend
2480
- // .expect("GET", "/url")
2481
- // .respond('""', { "Content-Type": "application/json" });
2482
- // await $http({ method: "GET", url: "/url" }).then(callback);
2483
- // $httpBackend.flush();
2484
-
2485
- // expect(callback).toHaveBeenCalled();
2486
- // expect(callback.calls.mostRecent().args[0].data).toEqual("");
2487
- // });
2488
-
2489
- // it("should deserialize json with security prefix", () => {
2490
- // $httpBackend
2491
- // .expect("GET", "/url")
2492
- // .respond(')]}\',\n[1, "abc", {"foo":"bar"}]');
2493
- // await $http({ method: "GET", url: "/url" }).then(callback);
2494
- // $httpBackend.flush();
2495
-
2496
- // expect(callback).toHaveBeenCalled();
2497
- // expect(callback.calls.mostRecent().args[0].data).toEqual([
2498
- // 1,
2499
- // "abc",
2500
- // { foo: "bar" },
2501
- // ]);
2502
- // });
2503
-
2504
- // it('should deserialize json with security prefix ")]}\'"', () => {
2505
- // $httpBackend
2506
- // .expect("GET", "/url")
2507
- // .respond(')]}\'\n\n[1, "abc", {"foo":"bar"}]');
2508
- // await $http({ method: "GET", url: "/url" }).then(callback);
2509
- // $httpBackend.flush();
2510
-
2511
- // expect(callback).toHaveBeenCalled();
2512
- // expect(callback.calls.mostRecent().args[0].data).toEqual([
2513
- // 1,
2514
- // "abc",
2515
- // { foo: "bar" },
2516
- // ]);
2517
- // });
2518
-
2519
- // it("should retain security prefix if response is not json", () => {
2520
- // $httpBackend
2521
- // .expect("GET", "/url")
2522
- // .respond(")]}',\n This is not JSON !");
2523
- // await $http({ method: "GET", url: "/url" }).then(callback);
2524
- // $httpBackend.flush();
2525
-
2526
- // expect(callback).toHaveBeenCalled();
2527
- // expect(callback.calls.mostRecent().args[0].data).toEqual(
2528
- // ")]}',\n This is not JSON !",
2529
- // );
2530
- // });
2531
-
2532
- // it("should not attempt to deserialize json when HEAD request", () => {
2533
- // // per http spec for Content-Type, HEAD request should return a Content-Type header
2534
- // // set to what the content type would have been if a get was sent
2535
- // $httpBackend
2536
- // .expect("HEAD", "/url")
2537
- // .respond("", { "Content-Type": "application/json" });
2538
- // await $http({ method: "HEAD", url: "/url" }).then(callback);
2539
- // $httpBackend.flush();
2540
-
2541
- // expect(callback).toHaveBeenCalled();
2542
- // expect(callback.calls.mostRecent().args[0].data).toEqual("");
2543
- // });
2544
-
2545
- // it("should not attempt to deserialize json for an empty response whose header contains application/json", () => {
2546
- // // per http spec for Content-Type, HEAD request should return a Content-Type header
2547
- // // set to what the content type would have been if a get was sent
2548
- // $httpBackend
2549
- // .expect("GET", "/url")
2550
- // .respond("", { "Content-Type": "application/json" });
2551
- // await $http({ method: "GET", url: "/url" }).then(callback);
2552
- // $httpBackend.flush();
2553
-
2554
- // expect(callback).toHaveBeenCalled();
2555
- // expect(callback.calls.mostRecent().args[0].data).toEqual("");
2556
- // });
2557
-
2558
- // it("should not attempt to deserialize json for a blank response whose header contains application/json", () => {
2559
- // // per http spec for Content-Type, HEAD request should return a Content-Type header
2560
- // // set to what the content type would have been if a get was sent
2561
- // $httpBackend
2562
- // .expect("GET", "/url")
2563
- // .respond(" ", { "Content-Type": "application/json" });
2564
- // await $http({ method: "GET", url: "/url" }).then(callback);
2565
- // $httpBackend.flush();
2566
-
2567
- // expect(callback).toHaveBeenCalled();
2568
- // expect(callback.calls.mostRecent().args[0].data).toEqual(" ");
2569
- // });
2570
-
2571
- // it("should not deserialize tpl beginning with ng expression", () => {
2572
- // $httpBackend.expect("GET", "/url").respond("{{some}}");
2573
- // $http.get("/url").then(callback);
2574
- // $httpBackend.flush();
2575
-
2576
- // expect(callback).toHaveBeenCalled();
2577
- // expect(callback.calls.mostRecent().args[0].data).toEqual(
2578
- // "{{some}}",
2579
- // );
2580
- // });
2581
-
2582
- // it("should not deserialize json when the opening and closing brackets do not match", () => {
2583
- // $httpBackend
2584
- // .expect("GET", "/url1")
2585
- // .respond("[Code](url): () => {}");
2586
- // $httpBackend
2587
- // .expect("GET", "/url2")
2588
- // .respond('{"is": "not"} ["json"]');
2589
- // $http.get("/url1").then(callback);
2590
- // $http.get("/url2").then(callback);
2591
- // $httpBackend.flush();
2592
-
2593
- // expect(callback).toHaveBeenCalledTimes(2);
2594
- // expect(callback.calls.argsFor(0)[0].data).toEqual(
2595
- // "[Code](url): () => {}",
2596
- // );
2597
- // expect(callback.calls.argsFor(1)[0].data).toEqual(
2598
- // '{"is": "not"} ["json"]',
2599
- // );
2600
- // });
2601
-
2602
- // it("should return JSON data with error message if JSON is invalid", () => {
2603
- // const errCallback = jasmine.createSpy("error");
2604
- // $httpBackend
2605
- // .expect("GET", "/url")
2606
- // .respond("{abcd}", { "Content-Type": "application/json" });
2607
- // $http.get("/url").then(callback).catch(errCallback);
2608
- // $httpBackend.flush();
2609
-
2610
- // expect(callback).not.toHaveBeenCalled();
2611
- // expect(errCallback).toHaveBeenCalled();
2612
- // expect(errCallback.calls.mostRecent().args[0]).toEqualMinErr(
2613
- // "$http",
2614
- // "baddata",
2615
- // );
2616
- // });
2617
-
2618
- // it("should not throw an error if JSON is invalid but content-type is not application/json", () => {
2619
- // $httpBackend
2620
- // .expect("GET", "/url")
2621
- // .respond("{abcd}", { "Content-Type": "text/plain" });
2622
-
2623
- // $http.get("/url").then(callback);
2624
- // $httpBackend.flush();
2625
-
2626
- // expect(callback).toHaveBeenCalled();
2627
- // });
2628
-
2629
- // it("should not throw an error if JSON is invalid but content-type is not specified", () => {
2630
- // $httpBackend.expect("GET", "/url").respond("{abcd}");
2631
-
2632
- // $http.get("/url").then(callback);
2633
- // $httpBackend.flush();
2634
-
2635
- // expect(callback).toHaveBeenCalled();
2636
- // });
2637
-
2638
- // it("should return response unprocessed if JSON is invalid but content-type is not application/json", () => {
2639
- // const response = "{abcd}";
2640
- // $httpBackend
2641
- // .expect("GET", "/url")
2642
- // .respond(response, { "Content-Type": "text/plain" });
2643
-
2644
- // $http.get("/url").then(callback);
2645
- // $httpBackend.flush();
2646
-
2647
- // expect(callback.calls.mostRecent().args[0].data).toBe(response);
2648
- // });
2649
-
2650
- // it("should return response unprocessed if JSON is invalid but content-type is not specified", () => {
2651
- // const response = "{abcd}";
2652
- // $httpBackend.expect("GET", "/url").respond(response);
2653
-
2654
- // $http.get("/url").then(callback);
2655
- // $httpBackend.flush();
2656
-
2657
- // expect(callback.calls.mostRecent().args[0].data).toBe(response);
2658
- // });
2659
- // });
2660
-
2661
- // it("should have access to response headers", () => {
2662
- // $httpBackend
2663
- // .expect("GET", "/url")
2664
- // .respond(200, "response", { h1: "header1" });
2665
- // $http
2666
- // .get("/url", {
2667
- // transformResponse(data, headers) {
2668
- // return headers("h1");
2669
- // },
2670
- // })
2671
- // .then(callback);
2672
- // $httpBackend.flush();
2673
-
2674
- // expect(callback).toHaveBeenCalled();
2675
- // expect(callback.calls.mostRecent().args[0].data).toBe("header1");
2676
- // });
2677
-
2678
- // it("should have access to response status", () => {
2679
- // $httpBackend
2680
- // .expect("GET", "/url")
2681
- // .respond(200, "response", { h1: "header1" });
2682
- // $http
2683
- // .get("/url", {
2684
- // transformResponse(data, headers, status) {
2685
- // return status;
2686
- // },
2687
- // })
2688
- // .then(callback);
2689
- // $httpBackend.flush();
2690
-
2691
- // expect(callback).toHaveBeenCalled();
2692
- // expect(callback.calls.mostRecent().args[0].data).toBe(200);
2693
- // });
2694
-
2695
- // it("should pipeline more functions", () => {
2696
- // function first(d, h) {
2697
- // return `${d}-first:${h("h1")}`;
2698
- // }
2699
- // function second(d) {
2700
- // return uppercase(d);
2701
- // }
2702
-
2703
- // $httpBackend
2704
- // .expect("POST", "/url")
2705
- // .respond(200, "resp", { h1: "v1" });
2706
- // $http
2707
- // .post("/url", "", { transformResponse: [first, second] })
2708
- // .then(callback);
2709
- // $httpBackend.flush();
2710
-
2711
- // expect(callback).toHaveBeenCalled();
2712
- // expect(callback.calls.mostRecent().args[0].data).toBe(
2713
- // "RESP-FIRST:V1",
2714
- // );
2715
- // });
2716
-
2717
- // it("should apply `transformResponse` even if the response data is empty", () => {
2718
- // const callback = jasmine.createSpy("transformResponse");
2719
- // const config = { transformResponse: callback };
2720
-
2721
- // $httpBackend.expect("GET", "/url1").respond(200, undefined);
2722
- // $httpBackend.expect("GET", "/url2").respond(200, null);
2723
- // $httpBackend.expect("GET", "/url3").respond(200, "");
2724
- // $http.get("/url1", config);
2725
- // $http.get("/url2", config);
2726
- // $http.get("/url3", config);
2727
- // $httpBackend.flush();
2728
-
2729
- // expect(callback).toHaveBeenCalledTimes(3);
2730
- // expect(callback.calls.argsFor(0)[0]).toBeUndefined();
2731
- // expect(callback.calls.argsFor(1)[0]).toBe(null);
2732
- // expect(callback.calls.argsFor(2)[0]).toBe("");
2733
- // });
2734
- // });
2735
- // });
2736
-
2737
- // describe("cache", () => {
2738
- // let cache;
2739
-
2740
- // beforeEach(inject(($cacheFactory) => {
2741
- // cache = $cacheFactory("testCache");
2742
- // }));
2743
-
2744
- // function doFirstCacheRequest(method, respStatus, headers) {
2745
- // $httpBackend
2746
- // .expect(method || "GET", "/url")
2747
- // .respond(respStatus || 200, "content", headers);
2748
- // await $http({ method: method || "GET", url: "/url", cache }).catch(() => {});
2749
- // $httpBackend.flush();
2750
- // }
2751
-
2752
- // it("should cache GET request when cache is provided", inject((
2753
- // $rootScope,
2754
- // ) => {
2755
- // doFirstCacheRequest();
2756
-
2757
- // await $http({ method: "get", url: "/url", cache }).then(callback);
2758
- // ;
2759
-
2760
- // expect(callback).toHaveBeenCalled();
2761
- // expect(callback.calls.mostRecent().args[0].data).toBe("content");
2762
- // }));
2763
-
2764
- // it("should cache JSONP request when cache is provided", inject((
2765
- // $rootScope,
2766
- // ) => {
2767
- // $httpBackend
2768
- // .expect("JSONP", "/url?callback=JSON_CALLBACK")
2769
- // .respond("content");
2770
- // await $http({ method: "JSONP", url: $sce.trustAsResourceUrl("/url"), cache });
2771
- // $httpBackend.flush();
2772
-
2773
- // await $http({
2774
- // method: "JSONP",
2775
- // url: $sce.trustAsResourceUrl("/url"),
2776
- // cache,
2777
- // }).then(callback);
2778
- // ;
2779
-
2780
- // expect(callback).toHaveBeenCalled();
2781
- // expect(callback.calls.mostRecent().args[0].data).toBe("content");
2782
- // }));
2783
-
2784
- // it("should cache request when cache is provided and no method specified", () => {
2785
- // doFirstCacheRequest();
2786
-
2787
- // await $http({ url: "/url", cache }).then(callback);
2788
- // ;
2789
-
2790
- // expect(callback).toHaveBeenCalled();
2791
- // expect(callback.calls.mostRecent().args[0].data).toBe("content");
2792
- // });
2793
-
2794
- // it("should not cache when cache is not provided", () => {
2795
- // doFirstCacheRequest();
2796
-
2797
- // $httpBackend.expect("GET", "/url").respond();
2798
- // await $http({ method: "GET", url: "/url" });
2799
- // });
2800
-
2801
- // it("should perform request when cache cleared", () => {
2802
- // doFirstCacheRequest();
2803
-
2804
- // cache.removeAll();
2805
- // $httpBackend.expect("GET", "/url").respond();
2806
- // await $http({ method: "GET", url: "/url", cache });
2807
- // });
2808
-
2809
- // it("should always call callback asynchronously", () => {
2810
- // doFirstCacheRequest();
2811
- // await $http({ method: "get", url: "/url", cache }).then(callback);
2812
-
2813
- // expect(callback).not.toHaveBeenCalled();
2814
- // });
2815
-
2816
- // it("should not cache POST request", () => {
2817
- // doFirstCacheRequest("POST");
2818
-
2819
- // $httpBackend.expect("POST", "/url").respond("content2");
2820
- // await $http({ method: "POST", url: "/url", cache }).then(callback);
2821
- // $httpBackend.flush();
2822
-
2823
- // expect(callback).toHaveBeenCalled();
2824
- // expect(callback.calls.mostRecent().args[0].data).toBe("content2");
2825
- // });
2826
-
2827
- // it("should not cache PUT request", () => {
2828
- // doFirstCacheRequest("PUT");
2829
-
2830
- // $httpBackend.expect("PUT", "/url").respond("content2");
2831
- // await $http({ method: "PUT", url: "/url", cache }).then(callback);
2832
- // $httpBackend.flush();
2833
-
2834
- // expect(callback).toHaveBeenCalled();
2835
- // expect(callback.calls.mostRecent().args[0].data).toBe("content2");
2836
- // });
2837
-
2838
- // it("should not cache DELETE request", () => {
2839
- // doFirstCacheRequest("DELETE");
2840
-
2841
- // $httpBackend.expect("DELETE", "/url").respond(206);
2842
- // await $http({ method: "DELETE", url: "/url", cache }).then(callback);
2843
- // $httpBackend.flush();
2844
-
2845
- // expect(callback).toHaveBeenCalled();
2846
- // });
2847
-
2848
- // it("should not cache non 2xx responses", () => {
2849
- // doFirstCacheRequest("GET", 404);
2850
-
2851
- // $httpBackend.expect("GET", "/url").respond("content2");
2852
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2853
- // $httpBackend.flush();
2854
-
2855
- // expect(callback).toHaveBeenCalled();
2856
- // expect(callback.calls.mostRecent().args[0].data).toBe("content2");
2857
- // });
2858
-
2859
- // it("should cache the headers as well", inject(($rootScope) => {
2860
- // doFirstCacheRequest("GET", 200, {
2861
- // "content-encoding": "gzip",
2862
- // server: "Apache",
2863
- // });
2864
- // callback.and.callFake((response) => {
2865
- // expect(response.headers()).toEqual(
2866
- // extend(Object.create(null), {
2867
- // "content-encoding": "gzip",
2868
- // server: "Apache",
2869
- // }),
2870
- // );
2871
- // expect(response.headers("server")).toBe("Apache");
2872
- // });
2873
-
2874
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2875
- // ;
2876
- // expect(callback).toHaveBeenCalled();
2877
- // }));
2878
-
2879
- // it("should not share the cached headers object instance", inject((
2880
- // $rootScope,
2881
- // ) => {
2882
- // doFirstCacheRequest("GET", 200, {
2883
- // "content-encoding": "gzip",
2884
- // server: "Apache",
2885
- // });
2886
- // callback.and.callFake((response) => {
2887
- // expect(response.headers()).toEqual(cache.get("/url")[2]);
2888
- // expect(response.headers()).not.toBe(cache.get("/url")[2]);
2889
- // });
2890
-
2891
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2892
- // ;
2893
- // expect(callback).toHaveBeenCalled();
2894
- // }));
2895
-
2896
- // it("should not share the pending cached headers object instance", inject((
2897
- // $rootScope,
2898
- // ) => {
2899
- // let firstResult;
2900
- // callback.and.callFake((result) => {
2901
- // expect(result.headers()).toEqual(firstResult.headers());
2902
- // expect(result.headers()).not.toBe(firstResult.headers());
2903
- // });
2904
-
2905
- // $httpBackend.expect("GET", "/url").respond(200, "content", {
2906
- // "content-encoding": "gzip",
2907
- // server: "Apache",
2908
- // });
2909
- // await $http({ method: "GET", url: "/url", cache }).then((result) => {
2910
- // firstResult = result;
2911
- // });
2912
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2913
- // $httpBackend.flush();
2914
-
2915
- // expect(callback).toHaveBeenCalled();
2916
- // }));
2917
-
2918
- // it("should cache status code as well", inject(($rootScope) => {
2919
- // doFirstCacheRequest("GET", 201);
2920
- // callback.and.callFake((response) => {
2921
- // expect(response.status).toBe(201);
2922
- // });
2923
-
2924
- // await $http({ method: "get", url: "/url", cache }).then(callback);
2925
- // ;
2926
- // expect(callback).toHaveBeenCalled();
2927
- // }));
2928
-
2929
- // it("should cache xhrStatus as well", inject(($rootScope) => {
2930
- // doFirstCacheRequest("GET", 201, null);
2931
- // callback.and.callFake((response) => {
2932
- // expect(response.xhrStatus).toBe("complete");
2933
- // });
2934
-
2935
- // await $http({ method: "get", url: "/url", cache }).then(callback);
2936
- // ;
2937
- // expect(callback).toHaveBeenCalled();
2938
- // }));
2939
-
2940
- // it("should use cache even if second request was made before the first returned", () => {
2941
- // $httpBackend.expect("GET", "/url").respond(201, "fake-response");
2942
-
2943
- // callback.and.callFake((response) => {
2944
- // expect(response.data).toBe("fake-response");
2945
- // expect(response.status).toBe(201);
2946
- // });
2947
-
2948
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2949
- // await $http({ method: "GET", url: "/url", cache }).then(callback);
2950
-
2951
- // $httpBackend.flush();
2952
- // expect(callback).toHaveBeenCalled();
2953
- // expect(callback).toHaveBeenCalledTimes(2);
2954
- // });
2955
-
2956
- // it("should preserve config object when resolving from cache", () => {
2957
- // $httpBackend.expect("GET", "/url").respond(200, "content");
2958
- // await $http({ method: "GET", url: "/url", cache, headers: { foo: "bar" } });
2959
- // $httpBackend.flush();
2960
-
2961
- // await $http({
2962
- // method: "GET",
2963
- // url: "/url",
2964
- // cache,
2965
- // headers: { foo: "baz" },
2966
- // }).then(callback);
2967
- // ;
2968
-
2969
- // expect(callback.calls.mostRecent().args[0].config.headers.foo).toBe(
2970
- // "baz",
2971
- // );
2972
- // });
2973
-
2974
- // it("should preserve config object when resolving from pending cache", () => {
2975
- // $httpBackend.expect("GET", "/url").respond(200, "content");
2976
- // await $http({ method: "GET", url: "/url", cache, headers: { foo: "bar" } });
2977
-
2978
- // await $http({
2979
- // method: "GET",
2980
- // url: "/url",
2981
- // cache,
2982
- // headers: { foo: "baz" },
2983
- // }).then(callback);
2984
- // $httpBackend.flush();
2985
-
2986
- // expect(callback.calls.mostRecent().args[0].config.headers.foo).toBe(
2987
- // "baz",
2988
- // );
2989
- // });
2990
-
2991
- // it("should preserve config object when rejecting from pending cache", () => {
2992
- // $httpBackend.expect("GET", "/url").respond(404, "content");
2993
- // await $http({
2994
- // method: "GET",
2995
- // url: "/url",
2996
- // cache,
2997
- // headers: { foo: "bar" },
2998
- // }).catch(() => {});
2999
-
3000
- // await $http({
3001
- // method: "GET",
3002
- // url: "/url",
3003
- // cache,
3004
- // headers: { foo: "baz" },
3005
- // }).catch(callback);
3006
- // $httpBackend.flush();
3007
-
3008
- // expect(callback.calls.mostRecent().args[0].config.headers.foo).toBe(
3009
- // "baz",
3010
- // );
3011
- // });
3012
-
3013
- // it("should allow the cached value to be an empty string", () => {
3014
- // cache.put("/abc", "");
3015
-
3016
- // callback.and.callFake((response) => {
3017
- // expect(response.data).toBe("");
3018
- // expect(response.status).toBe(200);
3019
- // });
3020
-
3021
- // await $http({ method: "GET", url: "/abc", cache }).then(callback);
3022
- // ;
3023
- // expect(callback).toHaveBeenCalled();
3024
- // });
3025
-
3026
- // it("should default to status code 200 and empty headers if cache contains a non-array element", inject((
3027
- // $rootScope,
3028
- // ) => {
3029
- // cache.put("/myurl", "simple response");
3030
- // $http.get("/myurl", { cache }).then((response) => {
3031
- // expect(response.data).toBe("simple response");
3032
- // expect(response.status).toBe(200);
3033
- // expect(response.headers()).toEqual(Object.create(null));
3034
- // callback();
3035
- // });
3036
-
3037
- // ;
3038
- // expect(callback).toHaveBeenCalled();
3039
- // }));
3040
-
3041
- // describe("$http.defaults.cache", () => {
3042
- // it("should be undefined by default", () => {
3043
- // expect($http.defaults.cache).toBeUndefined();
3044
- // });
3045
-
3046
- // it("should cache requests when no cache given in request config", () => {
3047
- // $http.defaults.cache = cache;
3048
-
3049
- // // First request fills the cache from server response.
3050
- // $httpBackend.expect("GET", "/url").respond(200, "content");
3051
- // await $http({ method: "GET", url: "/url" }); // Notice no cache given in config.
3052
- // $httpBackend.flush();
3053
-
3054
- // // Second should be served from cache, without sending request to server.
3055
- // await $http({ method: "get", url: "/url" }).then(callback);
3056
- // ;
3057
-
3058
- // expect(callback).toHaveBeenCalled();
3059
- // expect(callback.calls.mostRecent().args[0].data).toBe("content");
3060
-
3061
- // // Invalidate cache entry.
3062
- // $http.defaults.cache.remove("/url");
3063
-
3064
- // // After cache entry removed, a request should be sent to server.
3065
- // $httpBackend.expect("GET", "/url").respond(200, "content");
3066
- // await $http({ method: "GET", url: "/url" });
3067
- // $httpBackend.flush();
3068
- // });
3069
-
3070
- // it("should have less priority than explicitly given cache", inject((
3071
- // $cacheFactory,
3072
- // ) => {
3073
- // const localCache = $cacheFactory("localCache");
3074
- // $http.defaults.cache = cache;
3075
-
3076
- // // Fill local cache.
3077
- // $httpBackend
3078
- // .expect("GET", "/url")
3079
- // .respond(200, "content-local-cache");
3080
- // await $http({ method: "GET", url: "/url", cache: localCache });
3081
- // $httpBackend.flush();
3082
-
3083
- // // Fill default cache.
3084
- // $httpBackend
3085
- // .expect("GET", "/url")
3086
- // .respond(200, "content-default-cache");
3087
- // await $http({ method: "GET", url: "/url" });
3088
- // $httpBackend.flush();
3089
-
3090
- // // Serve request from default cache when no local given.
3091
- // await $http({ method: "get", url: "/url" }).then(callback);
3092
- // ;
3093
- // expect(callback).toHaveBeenCalled();
3094
- // expect(callback.calls.mostRecent().args[0].data).toBe(
3095
- // "content-default-cache",
3096
- // );
3097
- // callback.calls.reset();
3098
-
3099
- // // Serve request from local cache when it is given (but default filled too).
3100
- // await $http({ method: "get", url: "/url", cache: localCache }).then(
3101
- // callback,
3102
- // );
3103
- // ;
3104
- // expect(callback).toHaveBeenCalled();
3105
- // expect(callback.calls.mostRecent().args[0].data).toBe(
3106
- // "content-local-cache",
3107
- // );
3108
- // }));
3109
-
3110
- // it("should be skipped if {cache: false} is passed in request config", () => {
3111
- // $http.defaults.cache = cache;
3112
-
3113
- // $httpBackend.expect("GET", "/url").respond(200, "content");
3114
- // await $http({ method: "GET", url: "/url" });
3115
- // $httpBackend.flush();
3116
-
3117
- // $httpBackend.expect("GET", "/url").respond();
3118
- // await $http({ method: "GET", url: "/url", cache: false });
3119
- // $httpBackend.flush();
3120
- // });
3121
- // });
3122
- // });
3123
-
3124
- // describe("timeout", () => {
3125
- // it("should abort requests when timeout promise resolves", inject(($q) => {
3126
- // const canceler = Promise.withResolvers();
3127
-
3128
- // $httpBackend.expect("GET", "/some").respond(200);
3129
-
3130
- // await $http({ method: "GET", url: "/some", timeout: canceler.promise }).catch(
3131
- // (response) => {
3132
- // expect(response.data).toBeUndefined();
3133
- // expect(response.status).toBe(-1);
3134
- // expect(response.xhrStatus).toBe("abort");
3135
- // expect(response.headers()).toEqual(Object.create(null));
3136
- // expect(response.config.url).toBe("/some");
3137
- // callback();
3138
- // },
3139
- // );
3140
-
3141
- // $rootScope.$apply(() => {
3142
- // canceler.resolve();
3143
- // });
3144
-
3145
- // expect(callback).toHaveBeenCalled();
3146
- // $httpBackend.verifyNoOutstandingExpectation();
3147
- // $httpBackend.verifyNoOutstandingRequest();
3148
- // }));
3149
-
3150
- // it("should timeout request when numerical timeout is exceeded", inject((
3151
- // $timeout,
3152
- // ) => {
3153
- // const onFulfilled = jasmine.createSpy("onFulfilled");
3154
- // const onRejected = jasmine
3155
- // .createSpy("onRejected")
3156
- // .and.callFake((response) => {
3157
- // expect(response.xhrStatus).toBe("timeout");
3158
- // });
3159
-
3160
- // $httpBackend.expect("GET", "/some").respond(200);
3161
-
3162
- // await $http({
3163
- // method: "GET",
3164
- // url: "/some",
3165
- // timeout: 10,
3166
- // }).then(onFulfilled, onRejected);
3167
-
3168
- // $timeout.flush(100);
3169
-
3170
- // expect(onFulfilled).not.toHaveBeenCalled();
3171
- // expect(onRejected).toHaveBeenCalled();
3172
- // }));
3173
-
3174
- // it("should reject promise when timeout promise resolves", inject((
3175
- // $timeout,
3176
- // ) => {
3177
- // const onFulfilled = jasmine.createSpy("onFulfilled");
3178
- // const onRejected = jasmine
3179
- // .createSpy("onRejected")
3180
- // .and.callFake((response) => {
3181
- // expect(response.xhrStatus).toBe("timeout");
3182
- // });
3183
-
3184
- // $httpBackend.expect("GET", "/some").respond(200);
3185
-
3186
- // await $http({
3187
- // method: "GET",
3188
- // url: "/some",
3189
- // timeout: setTimeout(() => {}, 10),
3190
- // }).then(onFulfilled, onRejected);
3191
-
3192
- // $timeout.flush(100);
3193
-
3194
- // expect(onFulfilled).not.toHaveBeenCalled();
3195
- // expect(onRejected).toHaveBeenCalled();
3196
- // }));
3197
- // });
3198
-
3199
- // describe("pendingRequests", () => {
3200
- // it("should be an array of pending requests", () => {
3201
- // $httpBackend.when("GET").respond(200);
3202
- // expect($http.pendingRequests.length).toBe(0);
3203
-
3204
- // await $http({ method: "get", url: "/some" });
3205
- // ;
3206
- // expect($http.pendingRequests.length).toBe(1);
3207
-
3208
- // $httpBackend.flush();
3209
- // expect($http.pendingRequests.length).toBe(0);
3210
- // });
3211
-
3212
- // it("should update pending requests even when served from cache", inject((
3213
- // $rootScope,
3214
- // ) => {
3215
- // $httpBackend.when("GET").respond(200);
3216
-
3217
- // await $http({ method: "get", url: "/cached", cache: true });
3218
- // await $http({ method: "get", url: "/cached", cache: true });
3219
- // ;
3220
- // expect($http.pendingRequests.length).toBe(2);
3221
-
3222
- // $httpBackend.flush();
3223
- // expect($http.pendingRequests.length).toBe(0);
3224
-
3225
- // await $http({ method: "get", url: "/cached", cache: true });
3226
- // spyOn($http.pendingRequests, "push").and.callThrough();
3227
- // ;
3228
- // expect($http.pendingRequests.push).toHaveBeenCalled();
3229
-
3230
- // await wait();
3231
- // expect($http.pendingRequests.length).toBe(0);
3232
- // }));
3233
-
3234
- // it("should remove the request before firing callbacks", () => {
3235
- // $httpBackend.when("GET").respond(200);
3236
- // await $http({ method: "get", url: "/url" }).then(() => {
3237
- // expect($http.pendingRequests.length).toBe(0);
3238
- // });
3239
-
3240
- // ;
3241
- // expect($http.pendingRequests.length).toBe(1);
3242
- // $httpBackend.flush();
3243
- // });
3244
- // });
3245
-
3246
- // describe("defaults", () => {
3247
- // it("should expose the defaults object at runtime", () => {
3248
- // expect($http.defaults).toBeDefined();
3249
-
3250
- // $http.defaults.headers.common.foo = "bar";
3251
- // $httpBackend
3252
- // .expect("GET", "/url", undefined, (headers) => headers.foo === "bar")
3253
- // .respond("");
3254
-
3255
- // $http.get("/url");
3256
- // $httpBackend.flush();
3257
- // });
3258
-
3259
- // it("should have separate objects for defaults PUT and POST", () => {
3260
- // expect($http.defaults.headers.post).not.toBe(
3261
- // $http.defaults.headers.put,
3262
- // );
3263
- // expect($http.defaults.headers.post).not.toBe(
3264
- // $http.defaults.headers.patch,
3265
- // );
3266
- // expect($http.defaults.headers.put).not.toBe(
3267
- // $http.defaults.headers.patch,
3268
- // );
3269
- // });
3270
-
3271
- // it("should expose default param serializer at runtime", () => {
3272
- // const { paramSerializer } = $http.defaults;
3273
- // expect(paramSerializer({ foo: "foo", bar: ["bar", "baz"] })).toEqual(
3274
- // "bar=bar&bar=baz&foo=foo",
3275
- // );
3276
- // });
3277
- // });
3278
- // });
3279
-
3280
- // describe("$browser's outstandingRequestCount", () => {
3281
- // let $http;
3282
- // let $httpBackend;
3283
- // let $rootScope;
3284
- // let incOutstandingRequestCountSpy;
3285
- // let completeOutstandingRequestSpy;
3286
-
3287
- // describe("without interceptors", () => {
3288
- // beforeEach(setupServicesAndSpies);
3289
-
3290
- // it("should immediately call `$browser.$$incOutstandingRequestCount()`", () => {
3291
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3292
- // $http.get("");
3293
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3294
- // });
3295
-
3296
- // it("should call `$browser.$$completeOutstandingRequest()` on success", () => {
3297
- // $httpBackend.when("GET").respond(200);
3298
-
3299
- // $http.get("");
3300
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3301
- // $httpBackend.flush();
3302
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3303
- // () => {},
3304
- // "$http",
3305
- // );
3306
- // });
3307
-
3308
- // it("should call `$browser.$$completeOutstandingRequest()` on error", () => {
3309
- // $httpBackend.when("GET").respond(500);
3310
-
3311
- // $http.get("").catch(() => {});
3312
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3313
- // $httpBackend.flush();
3314
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3315
- // () => {},
3316
- // "$http",
3317
- // );
3318
- // });
3319
-
3320
- // it("should increment/decrement `outstandingRequestCount` on error in `transformRequest`", () => {
3321
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3322
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3323
-
3324
- // $http
3325
- // .get("", {
3326
- // transformRequest() {
3327
- // throw new Error();
3328
- // },
3329
- // })
3330
- // .catch(() => {});
3331
-
3332
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3333
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3334
-
3335
- // ;
3336
-
3337
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3338
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3339
- // () => {},
3340
- // "$http",
3341
- // );
3342
- // });
3343
-
3344
- // it("should increment/decrement `outstandingRequestCount` on error in `transformResponse`", () => {
3345
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3346
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3347
-
3348
- // $httpBackend.when("GET").respond(200);
3349
- // $http
3350
- // .get("", {
3351
- // transformResponse() {
3352
- // throw new Error();
3353
- // },
3354
- // })
3355
- // .catch(() => {});
3356
-
3357
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3358
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3359
-
3360
- // $httpBackend.flush();
3361
-
3362
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3363
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3364
- // () => {},
3365
- // "$http",
3366
- // );
3367
- // });
3368
- // });
3369
-
3370
- // describe("with interceptors", () => {
3371
- // let reqInterceptorDeferred;
3372
- // let resInterceptorDeferred;
3373
- // let reqInterceptorFulfilled;
3374
- // let resInterceptorFulfilled;
3375
-
3376
- // beforeEach(
3377
- // module(($httpProvider) => {
3378
- // reqInterceptorDeferred = null;
3379
- // resInterceptorDeferred = null;
3380
- // reqInterceptorFulfilled = false;
3381
- // resInterceptorFulfilled = false;
3382
-
3383
- // $httpProvider.interceptors.push(($q) => ({
3384
- // request(config) {
3385
- // return (reqInterceptorDeferred = Promise.withResolvers().promise
3386
- // .finally(() => {
3387
- // reqInterceptorFulfilled = true;
3388
- // })
3389
- // .then(() => (config));
3390
- // },
3391
- // response() {
3392
- // return (resInterceptorDeferred = Promise.withResolvers().promise.finally(
3393
- // () => {
3394
- // resInterceptorFulfilled = true;
3395
- // },
3396
- // );
3397
- // },
3398
- // }));
3399
- // }),
3400
- // );
3401
-
3402
- // beforeEach(setupServicesAndSpies);
3403
-
3404
- // beforeEach(() => {
3405
- // $httpBackend.when("GET").respond(200);
3406
- // });
3407
-
3408
- // it("should increment/decrement `outstandingRequestCount` before/after async interceptors", () => {
3409
- // expect(reqInterceptorFulfilled).toBe(false);
3410
- // expect(resInterceptorFulfilled).toBe(false);
3411
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3412
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3413
-
3414
- // $http.get("");
3415
- // ;
3416
-
3417
- // expect(reqInterceptorFulfilled).toBe(false);
3418
- // expect(resInterceptorFulfilled).toBe(false);
3419
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3420
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3421
-
3422
- // reqInterceptorDeferred.resolve();
3423
- // $httpBackend.flush();
3424
-
3425
- // expect(reqInterceptorFulfilled).toBe(true);
3426
- // expect(resInterceptorFulfilled).toBe(false);
3427
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3428
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3429
-
3430
- // resInterceptorDeferred.resolve();
3431
- // ;
3432
-
3433
- // expect(reqInterceptorFulfilled).toBe(true);
3434
- // expect(resInterceptorFulfilled).toBe(true);
3435
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3436
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3437
- // () => {},
3438
- // "$http",
3439
- // );
3440
- // });
3441
-
3442
- // it("should increment/decrement `outstandingRequestCount` on error in request interceptor", () => {
3443
- // expect(reqInterceptorFulfilled).toBe(false);
3444
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3445
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3446
-
3447
- // $http.get("").catch(() => {});
3448
- // ;
3449
-
3450
- // expect(reqInterceptorFulfilled).toBe(false);
3451
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3452
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3453
-
3454
- // reqInterceptorDeferred.reject();
3455
- // ;
3456
-
3457
- // expect(reqInterceptorFulfilled).toBe(true);
3458
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3459
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3460
- // () => {},
3461
- // "$http",
3462
- // );
3463
- // });
3464
-
3465
- // it("should increment/decrement `outstandingRequestCount` on error in response interceptor", () => {
3466
- // expect(reqInterceptorFulfilled).toBe(false);
3467
- // expect(resInterceptorFulfilled).toBe(false);
3468
- // expect(incOutstandingRequestCountSpy).not.toHaveBeenCalled();
3469
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3470
-
3471
- // $http.get("").catch(() => {});
3472
- // ;
3473
-
3474
- // expect(reqInterceptorFulfilled).toBe(false);
3475
- // expect(resInterceptorFulfilled).toBe(false);
3476
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3477
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3478
-
3479
- // reqInterceptorDeferred.resolve();
3480
- // $httpBackend.flush();
3481
-
3482
- // expect(reqInterceptorFulfilled).toBe(true);
3483
- // expect(resInterceptorFulfilled).toBe(false);
3484
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3485
- // expect(completeOutstandingRequestSpy).not.toHaveBeenCalled();
3486
-
3487
- // resInterceptorDeferred.reject();
3488
- // ;
3489
-
3490
- // expect(reqInterceptorFulfilled).toBe(true);
3491
- // expect(resInterceptorFulfilled).toBe(true);
3492
- // expect(incOutstandingRequestCountSpy).toHaveBeenCalledOnceWith("$http");
3493
- // expect(completeOutstandingRequestSpy).toHaveBeenCalledOnceWith(
3494
- // () => {},
3495
- // "$http",
3496
- // );
3497
- // });
3498
- // });
3499
-
3500
- // // Helpers
3501
- // function setupServicesAndSpies() {
3502
- // inject(($browser, _$http_, _$httpBackend_, _$rootScope_) => {
3503
- // $http = _$http_;
3504
- // $httpBackend = _$httpBackend_;
3505
- // $rootScope = _$rootScope_;
3506
-
3507
- // incOutstandingRequestCountSpy = spyOn(
3508
- // $browser,
3509
- // "$$incOutstandingRequestCount",
3510
- // ).and.callThrough();
3511
- // completeOutstandingRequestSpy = spyOn(
3512
- // $browser,
3513
- // "$$completeOutstandingRequest",
3514
- // ).and.callThrough();
3515
- // });
3516
- // }
3517
- // });
3518
-
3519
- // describe("XSRF", () => {
3520
- // let $http;
3521
- // let $httpBackend;
3522
-
3523
- // beforeEach(
3524
- // module(($httpProvider) => {
3525
- // $httpProvider.xsrfTrustedOrigins.push(
3526
- // "https://trusted.example.com",
3527
- // "https://trusted2.example.com:1337/ignored/path",
3528
- // );
3529
- // }),
3530
- // );
3531
-
3532
- // beforeEach(inject((_$http_, _$httpBackend_) => {
3533
- // $http = _$http_;
3534
- // $httpBackend = _$httpBackend_;
3535
- // }));
3536
-
3537
- // it("should set the XSRF cookie into an XSRF header", () => {
3538
- // function checkXsrf(secret, header) {
3539
- // return function checkHeaders(headers) {
3540
- // return headers[header || "X-XSRF-TOKEN"] === secret;
3541
- // };
3542
- // }
3543
-
3544
- // mockedCookies["XSRF-TOKEN"] = "secret";
3545
- // mockedCookies.aCookie = "secret2";
3546
- // $httpBackend
3547
- // .expect("GET", "/url", null, checkXsrf("secret"))
3548
- // .respond(null);
3549
- // $httpBackend
3550
- // .expect("POST", "/url", null, checkXsrf("secret"))
3551
- // .respond(null);
3552
- // $httpBackend
3553
- // .expect("PUT", "/url", null, checkXsrf("secret"))
3554
- // .respond(null);
3555
- // $httpBackend
3556
- // .expect("DELETE", "/url", null, checkXsrf("secret"))
3557
- // .respond(null);
3558
- // $httpBackend
3559
- // .expect("GET", "/url", null, checkXsrf("secret", "aHeader"))
3560
- // .respond(null);
3561
- // $httpBackend
3562
- // .expect("GET", "/url", null, checkXsrf("secret2"))
3563
- // .respond(null);
3564
-
3565
- // await $http({ method: "GET", url: "/url" });
3566
- // await $http({ method: "POST", url: "/url", headers: { "S-ome": "Header" } });
3567
- // await $http({ method: "PUT", url: "/url", headers: { Another: "Header" } });
3568
- // await $http({ method: "DELETE", url: "/url", headers: {} });
3569
- // await $http({ method: "GET", url: "/url", xsrfHeaderName: "aHeader" });
3570
- // await $http({ method: "GET", url: "/url", xsrfCookieName: "aCookie" });
3571
-
3572
- // $httpBackend.flush();
3573
- // });
3574
-
3575
- // it("should support setting a default XSRF cookie/header name", () => {
3576
- // $http.defaults.xsrfCookieName = "aCookie";
3577
- // $http.defaults.xsrfHeaderName = "aHeader";
3578
-
3579
- // function checkHeaders(headers) {
3580
- // return headers.aHeader === "secret";
3581
- // }
3582
-
3583
- // mockedCookies.aCookie = "secret";
3584
- // $httpBackend.expect("GET", "/url", null, checkHeaders).respond(null);
3585
-
3586
- // $http.get("/url");
3587
-
3588
- // $httpBackend.flush();
3589
- // });
3590
-
3591
- // it("should support overriding the default XSRF cookie/header name per request", () => {
3592
- // $http.defaults.xsrfCookieName = "aCookie";
3593
- // $http.defaults.xsrfHeaderName = "aHeader";
3594
-
3595
- // function checkHeaders(headers) {
3596
- // return headers.anotherHeader === "anotherSecret";
3597
- // }
3598
-
3599
- // mockedCookies.anotherCookie = "anotherSecret";
3600
- // $httpBackend.expect("GET", "/url", null, checkHeaders).respond(null);
3601
-
3602
- // $http.get("/url", {
3603
- // xsrfCookieName: "anotherCookie",
3604
- // xsrfHeaderName: "anotherHeader",
3605
- // });
3606
-
3607
- // $httpBackend.flush();
3608
- // });
3609
-
3610
- // it("should check the cache before checking the XSRF cookie", inject((
3611
- // $cacheFactory,
3612
- // ) => {
3613
- // function checkHeaders(headers) {
3614
- // return headers["X-XSRF-TOKEN"] === "foo";
3615
- // }
3616
- // function setCookie() {
3617
- // mockedCookies["XSRF-TOKEN"] = "foo";
3618
- // }
3619
-
3620
- // const testCache = $cacheFactory("testCache");
3621
- // spyOn(testCache, "get").and.callFake(setCookie);
3622
-
3623
- // $httpBackend.expect("GET", "/url", null, checkHeaders).respond(null);
3624
- // $http.get("/url", { cache: testCache });
3625
-
3626
- // $httpBackend.flush();
3627
- // }));
3628
-
3629
- // it("should not set an XSRF header for cross-domain requests", () => {
3630
- // function checkHeaders(headers) {
3631
- // return isUndefined(headers["X-XSRF-TOKEN"]);
3632
- // }
3633
- // const requestUrls = [
3634
- // "https://api.example.com/path",
3635
- // "http://trusted.example.com",
3636
- // "https://trusted2.example.com:1338",
3637
- // ];
3638
-
3639
- // mockedCookies["XSRF-TOKEN"] = "secret";
3640
-
3641
- // requestUrls.forEach((url) => {
3642
- // $httpBackend.expect("GET", url, null, checkHeaders).respond(null);
3643
- // $http.get(url);
3644
- // $httpBackend.flush();
3645
- // });
3646
- // });
3647
-
3648
- // it("should set an XSRF header for cross-domain requests to trusted origins", inject((
3649
- // $browser,
3650
- // ) => {
3651
- // function checkHeaders(headers) {
3652
- // return headers["X-XSRF-TOKEN"] === "secret";
3653
- // }
3654
- // const currentUrl = "https://example.com/path";
3655
- // const requestUrls = [
3656
- // "https://trusted.example.com/path",
3657
- // "https://trusted2.example.com:1337/path",
3658
- // ];
3659
-
3660
- // $browser.url(currentUrl);
3661
- // mockedCookies["XSRF-TOKEN"] = "secret";
3662
-
3663
- // requestUrls.forEach((url) => {
3664
- // $httpBackend.expect("GET", url, null, checkHeaders).respond(null);
3665
- // $http.get(url);
3666
- // $httpBackend.flush();
3667
- // });
3668
- // }));
3669
- // });
3670
-
3671
- // it("should pass timeout, withCredentials and responseType", () => {
3672
- // const $httpBackend = jasmine.createSpy("$httpBackend");
3673
-
3674
- // $httpBackend.and.callFake(
3675
- // (m, u, d, c, h, timeout, withCredentials, responseType) => {
3676
- // expect(timeout).toBe(12345);
3677
- // expect(withCredentials).toBe(true);
3678
- // expect(responseType).toBe("json");
3679
- // },
3680
- // );
3681
-
3682
- // module(($provide) => {
3683
- // $provide.value("$httpBackend", $httpBackend);
3684
- // });
3685
-
3686
- // inject(($http, $rootScope) => {
3687
- // await $http({
3688
- // method: "GET",
3689
- // url: "some.html",
3690
- // timeout: 12345,
3691
- // withCredentials: true,
3692
- // responseType: "json",
3693
- // });
3694
- // ;
3695
- // expect($httpBackend).toHaveBeenCalled();
3696
- // });
3697
-
3698
- // $httpBackend.verifyNoOutstandingExpectation = () => {};
3699
- // });
3700
-
3701
- // it("should use withCredentials from default", () => {
3702
- // const $httpBackend = jasmine.createSpy("$httpBackend");
3703
-
3704
- // $httpBackend.and.callFake(
3705
- // (m, u, d, c, h, timeout, withCredentials, responseType) => {
3706
- // expect(withCredentials).toBe(true);
3707
- // },
3708
- // );
3709
-
3710
- // module(($provide) => {
3711
- // $provide.value("$httpBackend", $httpBackend);
3712
- // });
3713
-
3714
- // inject(($http, $rootScope) => {
3715
- // $http.defaults.withCredentials = true;
3716
- // await $http({
3717
- // method: "GET",
3718
- // url: "some.html",
3719
- // timeout: 12345,
3720
- // responseType: "json",
3721
- // });
3722
- // ;
3723
- // expect($httpBackend).toHaveBeenCalled();
3724
- // });
3725
-
3726
- // $httpBackend.verifyNoOutstandingExpectation = () => {};
3727
- // });
3728
- // });
3729
-
3730
- // describe("$http with $applyAsync", () => {
3731
- // let $http;
3732
- // let $httpBackend;
3733
- // let $rootScope;
3734
- // let $browser;
3735
- // let log;
3736
-
3737
- // beforeEach(inject([
3738
- // "$http",
3739
- // "$httpBackend",
3740
- // "$rootScope",
3741
- // "$browser",
3742
- // "log",
3743
- // function (http, backend, scope, browser, logger) {
3744
- // $http = http;
3745
- // $httpBackend = backend;
3746
- // $rootScope = scope;
3747
- // $browser = browser;
3748
- // spyOn($rootScope, "$apply").and.callThrough();
3749
- // spyOn($rootScope, "$applyAsync").and.callThrough();
3750
- // spyOn($rootScope, "$digest").and.callThrough();
3751
- // spyOn($browser.defer, "cancel").and.callThrough();
3752
- // log = logger;
3753
- // },
3754
- // ]));
3755
-
3756
- // it("should schedule coalesced apply on response", () => {
3757
- // const handler = jasmine.createSpy("handler");
3758
- // $httpBackend
3759
- // .expect("GET", "/template1.html")
3760
- // .respond(200, "<h1>Header!</h1>", {});
3761
- // $http.get("/template1.html").then(handler);
3762
- // // Ensure requests are sent
3763
- // ;
3764
-
3765
- // $httpBackend.flush(null, null, false);
3766
- // expect($rootScope.$applyAsync).toHaveBeenCalled();
3767
- // expect(handler).not.toHaveBeenCalled();
3768
-
3769
- // $browser.defer.flush();
3770
- // expect(handler).toHaveBeenCalled();
3771
- // });
3772
-
3773
- // it("should combine multiple responses within short time frame into a single $apply", () => {
3774
- // $httpBackend
3775
- // .expect("GET", "/template1.html")
3776
- // .respond(200, "<h1>Header!</h1>", {});
3777
- // $httpBackend
3778
- // .expect("GET", "/template2.html")
3779
- // .respond(200, "<p>Body!</p>", {});
3780
-
3781
- // $http.get("/template1.html").then(log.fn("response 1"));
3782
- // $http.get("/template2.html").then(log.fn("response 2"));
3783
- // // Ensure requests are sent
3784
- // ;
3785
-
3786
- // $httpBackend.flush(null, null, false);
3787
- // expect(log).toEqual([]);
3788
-
3789
- // $browser.defer.flush();
3790
- // expect(log).toEqual(["response 1", "response 2"]);
3791
- // });
3792
-
3793
- // it("should handle pending responses immediately if a digest occurs on $rootScope", () => {
3794
- // $httpBackend
3795
- // .expect("GET", "/template1.html")
3796
- // .respond(200, "<h1>Header!</h1>", {});
3797
- // $httpBackend
3798
- // .expect("GET", "/template2.html")
3799
- // .respond(200, "<p>Body!</p>", {});
3800
- // $httpBackend
3801
- // .expect("GET", "/template3.html")
3802
- // .respond(200, "<p>Body!</p>", {});
3803
-
3804
- // $http.get("/template1.html").then(log.fn("response 1"));
3805
- // $http.get("/template2.html").then(log.fn("response 2"));
3806
- // $http.get("/template3.html").then(log.fn("response 3"));
3807
- // // Ensure requests are sent
3808
- // ;
3809
-
3810
- // // Intermediate $digest occurs before 3rd response is received, assert that pending responses
3811
- // /// are handled
3812
- // $httpBackend.flush(2);
3813
- // expect(log).toEqual(["response 1", "response 2"]);
3814
-
3815
- // // Finally, third response is received, and a second coalesced $apply is started
3816
- // $httpBackend.flush(null, null, false);
3817
- // $browser.defer.flush();
3818
- // expect(log).toEqual(["response 1", "response 2", "response 3"]);
3819
- // });
3820
- // });
3821
-
3822
- // describe("$http param serializers", () => {
3823
- // let defSer;
3824
- // let jqrSer;
3825
- // beforeEach(inject(($httpParamSerializer, $httpParamSerializerJQLike) => {
3826
- // defSer = $httpParamSerializer;
3827
- // jqrSer = $httpParamSerializerJQLike;
3828
- // }));
3829
-
3830
- // describe("common functionality", () => {
3831
- // it("should return empty string for null or undefined params", () => {
3832
- // expect(defSer(undefined)).toEqual("");
3833
- // expect(jqrSer(undefined)).toEqual("");
3834
- // expect(defSer(null)).toEqual("");
3835
- // expect(jqrSer(null)).toEqual("");
3836
- // });
3837
-
3838
- // it("should serialize objects", () => {
3839
- // expect(defSer({ foo: "foov", bar: "barv" })).toEqual("bar=barv&foo=foov");
3840
- // expect(jqrSer({ foo: "foov", bar: "barv" })).toEqual("bar=barv&foo=foov");
3841
- // expect(
3842
- // defSer({ someDate: new Date("2014-07-15T17:30:00.000Z") }),
3843
- // ).toEqual("someDate=2014-07-15T17:30:00.000Z");
3844
- // expect(
3845
- // jqrSer({ someDate: new Date("2014-07-15T17:30:00.000Z") }),
3846
- // ).toEqual("someDate=2014-07-15T17:30:00.000Z");
3847
- // });
3848
- // });
3849
-
3850
- // describe("default array serialization", () => {
3851
- // it("should serialize arrays by repeating param name", () => {
3852
- // expect(defSer({ a: "b", foo: ["bar", "baz"] })).toEqual(
3853
- // "a=b&foo=bar&foo=baz",
3854
- // );
3855
- // });
3856
-
3857
- // it("should NOT serialize functions", () => {
3858
- // expect(defSer({ foo: "foov", bar() {} })).toEqual("foo=foov");
3859
- // });
3860
- // });
3861
-
3862
- // describe("jquery array and objects serialization", () => {
3863
- // it("should serialize arrays by repeating param name with [] suffix", () => {
3864
- // expect(jqrSer({ a: "b", foo: ["bar", "baz"] })).toEqual(
3865
- // "a=b&foo%5B%5D=bar&foo%5B%5D=baz",
3866
- // );
3867
- // expect(
3868
- // decodeURIComponent(jqrSer({ a: "b", foo: ["bar", "baz"] })),
3869
- // ).toEqual("a=b&foo[]=bar&foo[]=baz");
3870
- // });
3871
-
3872
- // it("should serialize arrays with functions", () => {
3873
- // expect(jqrSer({ foo: [() => ("bar")] })).toEqual("foo%5B%5D=bar"); // foo[]=bar
3874
- // });
3875
-
3876
- // it("should serialize arrays with functions inside objects", () => {
3877
- // expect(jqrSer({ foo: { bar: [() => ("baz")] } })).toEqual(
3878
- // "foo%5Bbar%5D%5B%5D=baz",
3879
- // ); // foo[bar][]=baz
3880
- // });
3881
-
3882
- // it("should serialize objects by repeating param name with [key] suffix", () => {
3883
- // expect(jqrSer({ a: "b", foo: { bar: "barv", baz: "bazv" } })).toEqual(
3884
- // "a=b&foo%5Bbar%5D=barv&foo%5Bbaz%5D=bazv",
3885
- // );
3886
- // // a=b&foo[bar]=barv&foo[baz]=bazv
3887
- // });
3888
-
3889
- // it("should serialize objects with function properties", () => {
3890
- // expect(jqrSer({ a: () => ("b") })).toEqual("a=b");
3891
- // });
3892
-
3893
- // it("should serialize objects with function properties returning an object", () => {
3894
- // expect(jqrSer({ a: () => ({ b: "c" }) })).toEqual(
3895
- // "a=%7B%22b%22:%22c%22%7D",
3896
- // ); // a={"b":"c"}
3897
- // });
3898
-
3899
- // it("should serialize nested objects by repeating param name with [key] suffix", () => {
3900
- // expect(
3901
- // jqrSer({ a: ["b", { c: "d" }], e: { f: "g", h: ["i", "j"] } }),
3902
- // ).toEqual(
3903
- // "a%5B%5D=b&a%5B1%5D%5Bc%5D=d&e%5Bf%5D=g&e%5Bh%5D%5B%5D=i&e%5Bh%5D%5B%5D=j",
3904
- // );
3905
- // // a[]=b&a[1][c]=d&e[f]=g&e[h][]=i&e[h][]=j
3906
- // });
3907
-
3908
- // it("should serialize nested objects with function properties", () => {
3909
- // expect(jqrSer({ foo: { bar: () => ("barv") } })).toEqual(
3910
- // "foo%5Bbar%5D=barv",
3911
- // ); // foo[bar]=barv
3912
- // });
3913
-
3914
- // it("should serialize nested objects with function properties returning an object", () => {
3915
- // expect(jqrSer({ foo: { bar: () => ({ bav: "barv" }) } })).toEqual(
3916
- // "foo%5Bbar%5D=%7B%22bav%22:%22barv%22%7D",
3917
- // ); // foo[bar]={"bav":"barv"}
3918
- // });
3919
-
3920
- // it("should serialize objects inside array elements using their index", () => {
3921
- // expect(
3922
- // jqrSer({ a: ["b", "c"], d: [{ e: "f", g: "h" }, "i", { j: "k" }] }),
3923
- // ).toEqual(
3924
- // "a%5B%5D=b&a%5B%5D=c&d%5B0%5D%5Be%5D=f&d%5B0%5D%5Bg%5D=h&d%5B%5D=i&d%5B2%5D%5Bj%5D=k",
3925
- // );
3926
- // // a[]=b&a[]=c&d[0][e]=f&d[0][g]=h&d[]=i&d[2][j]=k
3927
- // });
3928
- // it("should serialize `null` and `undefined` elements as empty", () => {
3929
- // expect(
3930
- // jqrSer({
3931
- // items: ["foo", "bar", null, undefined, "baz"],
3932
- // x: null,
3933
- // y: undefined,
3934
- // }),
3935
- // ).toEqual(
3936
- // "items%5B%5D=foo&items%5B%5D=bar&items%5B%5D=&items%5B%5D=&items%5B%5D=baz&x=&y=",
3937
- // );
3938
- // // items[]=foo&items[]=bar&items[]=&items[]=&items[]=baz&x=&y=
3939
- // });
3940
- // });
3941
- // });