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