@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.
Files changed (645) hide show
  1. package/@types/index.d.ts +1 -84
  2. package/{src/index.ts → @types/namespace.d.ts} +4 -24
  3. package/@types/router/template-factory.d.ts +2 -2
  4. package/dist/angular-ts.esm.js +3 -3
  5. package/dist/angular-ts.umd.js +3 -3
  6. package/dist/angular-ts.umd.min.js +1 -1
  7. package/package.json +9 -2
  8. package/.github/workflows/ci.yml +0 -104
  9. package/.github/workflows/gh-pages.yml +0 -75
  10. package/.husky/pre-commit +0 -5
  11. package/.prettierignore +0 -9
  12. package/CHANGELOG.md +0 -17667
  13. package/CODE_OF_CONDUCT.md +0 -3
  14. package/CONTRIBUTING.md +0 -247
  15. package/DEVELOPERS.md +0 -499
  16. package/Makefile +0 -60
  17. package/RELEASE.md +0 -86
  18. package/TRIAGING.md +0 -127
  19. package/docs/.cspell.yml +0 -8
  20. package/docs/.github/dependabot.yml +0 -14
  21. package/docs/.nvmrc +0 -1
  22. package/docs/CONTRIBUTING.md +0 -28
  23. package/docs/Dockerfile +0 -4
  24. package/docs/LICENSE +0 -201
  25. package/docs/README.md +0 -217
  26. package/docs/assets/icons/logo.svg +0 -1
  27. package/docs/assets/scss/_variables_project.scss +0 -12
  28. package/docs/assets/scss/_variables_project_after_bs.scss +0 -8
  29. package/docs/assets/scss/index.scss +0 -48
  30. package/docs/config.yaml +0 -15
  31. package/docs/content/_index.md +0 -28
  32. package/docs/content/docs/_index.md +0 -61
  33. package/docs/content/docs/directive/_index.md +0 -4
  34. package/docs/content/docs/directive/app.md +0 -11
  35. package/docs/content/docs/directive/aria.md +0 -0
  36. package/docs/content/docs/directive/bind.md +0 -72
  37. package/docs/content/docs/directive/blur.md +0 -38
  38. package/docs/content/docs/directive/channel.md +0 -37
  39. package/docs/content/docs/directive/class-even.md +0 -47
  40. package/docs/content/docs/directive/class-odd.md +0 -48
  41. package/docs/content/docs/directive/class.md +0 -64
  42. package/docs/content/docs/directive/click.md +0 -41
  43. package/docs/content/docs/directive/cloak.md +0 -74
  44. package/docs/content/docs/directive/copy.md +0 -38
  45. package/docs/content/docs/directive/cut.md +0 -40
  46. package/docs/content/docs/directive/dblclick.md +0 -41
  47. package/docs/content/docs/directive/focus.md +0 -38
  48. package/docs/content/docs/directive/get.md +0 -203
  49. package/docs/content/docs/directive/include.md +0 -7
  50. package/docs/content/docs/directive/keydown.md +0 -38
  51. package/docs/content/docs/directive/keyup.md +0 -38
  52. package/docs/content/docs/directive/load.md +0 -43
  53. package/docs/content/docs/directive/mousedown.md +0 -38
  54. package/docs/content/docs/directive/mouseenter.md +0 -38
  55. package/docs/content/docs/directive/mouseleave.md +0 -38
  56. package/docs/content/docs/directive/mousemove.md +0 -38
  57. package/docs/content/docs/directive/mouseout.md +0 -38
  58. package/docs/content/docs/directive/mouseover.md +0 -38
  59. package/docs/content/docs/directive/mouseup.md +0 -38
  60. package/docs/content/docs/directive/non-bindable.md +0 -28
  61. package/docs/content/docs/filter/_index.md +0 -4
  62. package/docs/content/docs/filter/filter.md +0 -78
  63. package/docs/content/docs/filter/json.md +0 -19
  64. package/docs/content/docs/filter/limit-to.md +0 -30
  65. package/docs/content/docs/filter/order-by.md +0 -123
  66. package/docs/content/docs/provider/_index.md +0 -4
  67. package/docs/content/docs/provider/eventBusProvider.md +0 -35
  68. package/docs/content/docs/provider/locationProvider.md +0 -26
  69. package/docs/content/docs/provider/logProvider.md +0 -59
  70. package/docs/content/docs/provider/sceProvider.md +0 -194
  71. package/docs/content/docs/provider/templateCacheProvider.md +0 -100
  72. package/docs/content/docs/provider/templateRequestProvider.md +0 -5
  73. package/docs/content/docs/service/_index.md +0 -4
  74. package/docs/content/docs/service/compile.md +0 -5
  75. package/docs/content/docs/service/controller.md +0 -5
  76. package/docs/content/docs/service/eventBus.md +0 -56
  77. package/docs/content/docs/service/http.md +0 -161
  78. package/docs/content/docs/service/interpolation.md +0 -5
  79. package/docs/content/docs/service/location.md +0 -57
  80. package/docs/content/docs/service/log.md +0 -113
  81. package/docs/content/docs/service/parse.md +0 -5
  82. package/docs/content/docs/service/rootElement.md +0 -5
  83. package/docs/content/docs/service/rootScope.md +0 -5
  84. package/docs/content/docs/service/sce.md +0 -194
  85. package/docs/content/docs/service/templateCache.md +0 -64
  86. package/docs/content/docs/service/templateRequest.md +0 -5
  87. package/docs/content/docs/service/url.md +0 -5
  88. package/docs/content/docs/values/_index.md +0 -4
  89. package/docs/content/docs/values/document.md +0 -29
  90. package/docs/content/docs/values/window.md +0 -29
  91. package/docs/docker-compose.yaml +0 -12
  92. package/docs/docsy.work +0 -5
  93. package/docs/docsy.work.sum +0 -0
  94. package/docs/go.mod +0 -5
  95. package/docs/go.sum +0 -6
  96. package/docs/hugo-disabled.toml +0 -220
  97. package/docs/hugo.yaml +0 -200
  98. package/docs/layouts/404.html +0 -13
  99. package/docs/layouts/_markup/render-heading.html +0 -1
  100. package/docs/layouts/partials/hooks/head-end.html +0 -3
  101. package/docs/layouts/shortcodes/showcss.html +0 -2
  102. package/docs/layouts/shortcodes/showhtml.html +0 -2
  103. package/docs/layouts/shortcodes/showjs.html +0 -2
  104. package/docs/layouts/shortcodes/showraw.html +0 -1
  105. package/docs/layouts/shortcodes/version.html +0 -1
  106. package/docs/package-lock.json +0 -2293
  107. package/docs/package.json +0 -53
  108. package/docs/static/examples/counter/counter-test.html +0 -13
  109. package/docs/static/examples/counter/counter.html +0 -5
  110. package/docs/static/examples/counter/counter.test.js +0 -28
  111. package/docs/static/examples/document/document.html +0 -3
  112. package/docs/static/examples/eventbus/eventbus-test.html +0 -15
  113. package/docs/static/examples/eventbus/eventbus.html +0 -13
  114. package/docs/static/examples/eventbus/eventbus.js +0 -15
  115. package/docs/static/examples/eventbus/eventbus.test.js +0 -19
  116. package/docs/static/examples/i18n/i18n.html +0 -77
  117. package/docs/static/examples/ng-bind/ng-bind.html +0 -9
  118. package/docs/static/examples/ng-blur/ng-blur.html +0 -9
  119. package/docs/static/examples/ng-channel/ng-channel-test.html +0 -17
  120. package/docs/static/examples/ng-channel/ng-channel.html +0 -24
  121. package/docs/static/examples/ng-channel/ng-channel.test.js +0 -31
  122. package/docs/static/examples/ng-class/ng-class.html +0 -71
  123. package/docs/static/examples/ng-class-even/ng-class-even.html +0 -8
  124. package/docs/static/examples/ng-class-odd/ng-class-odd.html +0 -8
  125. package/docs/static/examples/ng-click/ng-click.html +0 -6
  126. package/docs/static/examples/ng-copy/ng-copy.html +0 -6
  127. package/docs/static/examples/ng-cut/ng-cut.html +0 -6
  128. package/docs/static/examples/ng-dblclick/ng-dblclick.html +0 -10
  129. package/docs/static/examples/ng-focus/ng-focus.html +0 -9
  130. package/docs/static/examples/ng-keydown/ng-keydown.html +0 -9
  131. package/docs/static/examples/ng-keyup/ng-keyup.html +0 -9
  132. package/docs/static/examples/ng-load/ng-load.html +0 -8
  133. package/docs/static/examples/ng-mousedown/ng-mousedown.html +0 -6
  134. package/docs/static/examples/ng-mouseenter/ng-mouseenter.html +0 -4
  135. package/docs/static/examples/ng-mouseleave/ng-mouseleave.html +0 -4
  136. package/docs/static/examples/ng-mousemove/ng-mousemove.html +0 -4
  137. package/docs/static/examples/ng-mouseout/ng-mouseout.html +0 -4
  138. package/docs/static/examples/ng-mouseover/ng-mouseover.html +0 -4
  139. package/docs/static/examples/ng-mouseup/ng-mouseup.html +0 -4
  140. package/docs/static/examples/ng-non-bindable/ng-non-bindable-test.html +0 -13
  141. package/docs/static/examples/ng-non-bindable/ng-non-bindable.html +0 -3
  142. package/docs/static/examples/ng-non-bindable/ng-non-bindable.test.js +0 -11
  143. package/docs/static/examples/window/window.html +0 -4
  144. package/docs/static/typedoc/.nojekyll +0 -1
  145. package/docs/static/typedoc/assets/hierarchy.js +0 -1
  146. package/docs/static/typedoc/assets/highlight.css +0 -29
  147. package/docs/static/typedoc/assets/icons.js +0 -18
  148. package/docs/static/typedoc/assets/icons.svg +0 -1
  149. package/docs/static/typedoc/assets/main.js +0 -60
  150. package/docs/static/typedoc/assets/navigation.js +0 -1
  151. package/docs/static/typedoc/assets/search.js +0 -1
  152. package/docs/static/typedoc/assets/style.css +0 -1633
  153. package/docs/static/typedoc/classes/Location.html +0 -55
  154. package/docs/static/typedoc/classes/LocationProvider.html +0 -20
  155. package/docs/static/typedoc/classes/LogProvider.html +0 -6
  156. package/docs/static/typedoc/classes/PubSub.html +0 -71
  157. package/docs/static/typedoc/classes/PubSubProvider.html +0 -4
  158. package/docs/static/typedoc/classes/TemplateCacheProvider.html +0 -5
  159. package/docs/static/typedoc/hierarchy.html +0 -1
  160. package/docs/static/typedoc/index.html +0 -1
  161. package/docs/static/typedoc/interfaces/DefaultPorts.html +0 -5
  162. package/docs/static/typedoc/interfaces/Html5Mode.html +0 -23
  163. package/docs/static/typedoc/interfaces/HttpHeadersGetter.html +0 -1
  164. package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +0 -31
  165. package/docs/static/typedoc/interfaces/HttpRequestConfigHeaders.html +0 -6
  166. package/docs/static/typedoc/interfaces/HttpRequestTransformer.html +0 -1
  167. package/docs/static/typedoc/interfaces/HttpResponse.html +0 -7
  168. package/docs/static/typedoc/interfaces/HttpResponseTransformer.html +0 -1
  169. package/docs/static/typedoc/interfaces/HttpService.html +0 -38
  170. package/docs/static/typedoc/interfaces/LogService.html +0 -12
  171. package/docs/static/typedoc/interfaces/RequestConfig.html +0 -48
  172. package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +0 -38
  173. package/docs/static/typedoc/interfaces/ServiceProvider.html +0 -5
  174. package/docs/static/typedoc/interfaces/UrlParts.html +0 -9
  175. package/docs/static/typedoc/types/HttpParamSerializer.html +0 -2
  176. package/docs/static/typedoc/types/HttpParams.html +0 -2
  177. package/docs/static/typedoc/types/HttpPromise.html +0 -1
  178. package/docs/static/typedoc/types/HttpResponseStatus.html +0 -1
  179. package/docs/static/typedoc/types/LogCall.html +0 -2
  180. package/docs/static/typedoc/types/LogServiceFactory.html +0 -2
  181. package/docs/static/typedoc/types/UrlChangeListener.html +0 -5
  182. package/docs/static/typedoc/variables/EventBus.html +0 -1
  183. package/docs/static/version.js +0 -13
  184. package/docs/test-results/.last-run.json +0 -4
  185. package/docs/test-results/static-examples-counter-counter-counter-example/error-context.md +0 -50
  186. package/eslint.config.js +0 -26
  187. package/images/android-chrome-192x192.png +0 -0
  188. package/images/android-chrome-512x512.png +0 -0
  189. package/images/apple-touch-icon.png +0 -0
  190. package/images/favicon-16x16.png +0 -0
  191. package/images/favicon-32x32.png +0 -0
  192. package/images/favicon.ico +0 -0
  193. package/images/site.webmanifest +0 -19
  194. package/index.html +0 -86
  195. package/legacy.d.ts +0 -1678
  196. package/playwright.config.ts +0 -81
  197. package/public/jasmine/boot0.js +0 -66
  198. package/public/jasmine/boot1.js +0 -134
  199. package/public/jasmine/jasmine-html.js +0 -970
  200. package/public/jasmine/jasmine.css +0 -323
  201. package/public/jasmine/jasmine.js +0 -11406
  202. package/public/public/README.md +0 -1
  203. package/public/public/circle.html +0 -1
  204. package/public/public/jasmine-helper.css +0 -9
  205. package/public/public/my_child_directive.html +0 -1
  206. package/public/public/my_directive.html +0 -1
  207. package/public/public/my_other_directive.html +0 -1
  208. package/public/public/test.html +0 -1
  209. package/rollup.config.js +0 -51
  210. package/src/angular.js +0 -286
  211. package/src/angular.spec.js +0 -1191
  212. package/src/animations/animate-cache.js +0 -80
  213. package/src/animations/animate-children-directive.js +0 -32
  214. package/src/animations/animate-children-directive.md +0 -80
  215. package/src/animations/animate-css-driver.js +0 -284
  216. package/src/animations/animate-css.html +0 -58
  217. package/src/animations/animate-css.js +0 -915
  218. package/src/animations/animate-css.md +0 -263
  219. package/src/animations/animate-js-driver.js +0 -60
  220. package/src/animations/animate-js.html +0 -47
  221. package/src/animations/animate-js.js +0 -371
  222. package/src/animations/animate-queue.js +0 -859
  223. package/src/animations/animate-runner.js +0 -193
  224. package/src/animations/animate-swap.js +0 -33
  225. package/src/animations/animate-swap.md +0 -88
  226. package/src/animations/animate.html +0 -19
  227. package/src/animations/animate.js +0 -546
  228. package/src/animations/animate.md +0 -933
  229. package/src/animations/animate.spec.js +0 -490
  230. package/src/animations/animation.js +0 -519
  231. package/src/animations/animations.test.js +0 -10
  232. package/src/animations/interface.ts +0 -19
  233. package/src/animations/raf-scheduler.html +0 -19
  234. package/src/animations/raf-scheduler.js +0 -92
  235. package/src/animations/raf-scheduler.spec.js +0 -98
  236. package/src/animations/shared.js +0 -341
  237. package/src/binding.html +0 -19
  238. package/src/binding.spec.js +0 -474
  239. package/src/binding.test.js +0 -10
  240. package/src/core/compile/attributes.js +0 -337
  241. package/src/core/compile/compile.html +0 -19
  242. package/src/core/compile/compile.js +0 -3271
  243. package/src/core/compile/compile.md +0 -1128
  244. package/src/core/compile/compile.spec.js +0 -15574
  245. package/src/core/compile/compile.test.js +0 -12
  246. package/src/core/controller/controller.html +0 -22
  247. package/src/core/controller/controller.js +0 -193
  248. package/src/core/controller/controller.spec.js +0 -334
  249. package/src/core/controller/controller.test.js +0 -12
  250. package/src/core/controller/interface.ts +0 -6
  251. package/src/core/core.html +0 -20
  252. package/src/core/core.test.js +0 -12
  253. package/src/core/di/injector.html +0 -19
  254. package/src/core/di/injector.js +0 -307
  255. package/src/core/di/injector.md +0 -740
  256. package/src/core/di/injector.spec.js +0 -2310
  257. package/src/core/di/injector.test.js +0 -12
  258. package/src/core/di/internal-injector.js +0 -286
  259. package/src/core/di/ng-module.html +0 -19
  260. package/src/core/di/ng-module.js +0 -229
  261. package/src/core/di/ng-module.spec.js +0 -263
  262. package/src/core/di/ng-module.test.js +0 -12
  263. package/src/core/filter/filter.html +0 -19
  264. package/src/core/filter/filter.js +0 -55
  265. package/src/core/filter/filter.md +0 -132
  266. package/src/core/filter/filter.spec.js +0 -149
  267. package/src/core/filter/filter.test.js +0 -12
  268. package/src/core/interpolate/interface.ts +0 -14
  269. package/src/core/interpolate/interpolate.html +0 -22
  270. package/src/core/interpolate/interpolate.js +0 -410
  271. package/src/core/interpolate/interpolate.spec.js +0 -601
  272. package/src/core/interpolate/interpolate.test.js +0 -12
  273. package/src/core/parse/ast/ast-node.ts +0 -81
  274. package/src/core/parse/ast/ast.html +0 -19
  275. package/src/core/parse/ast/ast.js +0 -574
  276. package/src/core/parse/ast/ast.spec.js +0 -1453
  277. package/src/core/parse/ast/ast.test.js +0 -10
  278. package/src/core/parse/ast-type.js +0 -23
  279. package/src/core/parse/interface.ts +0 -84
  280. package/src/core/parse/interpreter.js +0 -915
  281. package/src/core/parse/lexer/lexer.html +0 -19
  282. package/src/core/parse/lexer/lexer.js +0 -338
  283. package/src/core/parse/lexer/lexer.spec.js +0 -303
  284. package/src/core/parse/lexer/lexer.test.js +0 -10
  285. package/src/core/parse/lexer/token.ts +0 -22
  286. package/src/core/parse/parse.html +0 -19
  287. package/src/core/parse/parse.js +0 -337
  288. package/src/core/parse/parse.md +0 -57
  289. package/src/core/parse/parse.spec.js +0 -2107
  290. package/src/core/parse/parse.test.js +0 -10
  291. package/src/core/parse/parser/parser.html +0 -19
  292. package/src/core/parse/parser/parser.js +0 -64
  293. package/src/core/parse/parser/parser.spec.js +0 -8
  294. package/src/core/parse/parser/parser.test.js +0 -10
  295. package/src/core/prop.spec.js +0 -775
  296. package/src/core/root-element.spec.js +0 -14
  297. package/src/core/sanitize/interface.ts +0 -10
  298. package/src/core/sanitize/sanitize-uri.js +0 -75
  299. package/src/core/sanitize/sanitize-uri.spec.js +0 -249
  300. package/src/core/sanitize/sanitize-uri.test.js +0 -12
  301. package/src/core/sanitize/sanitize.html +0 -22
  302. package/src/core/scope/scope.html +0 -19
  303. package/src/core/scope/scope.js +0 -1252
  304. package/src/core/scope/scope.spec.js +0 -3000
  305. package/src/core/scope/scope.test.js +0 -12
  306. package/src/directive/aria/aria.html +0 -19
  307. package/src/directive/aria/aria.js +0 -382
  308. package/src/directive/aria/aria.md +0 -145
  309. package/src/directive/aria/aria.spec.js +0 -1241
  310. package/src/directive/aria/aria.test.js +0 -12
  311. package/src/directive/attrs/attrs.html +0 -19
  312. package/src/directive/attrs/attrs.js +0 -106
  313. package/src/directive/attrs/attrs.md +0 -224
  314. package/src/directive/attrs/attrs.spec.js +0 -71
  315. package/src/directive/attrs/attrs.test.js +0 -12
  316. package/src/directive/attrs/boolean.html +0 -19
  317. package/src/directive/attrs/boolean.spec.js +0 -137
  318. package/src/directive/attrs/boolean.test.js +0 -12
  319. package/src/directive/attrs/element-style.html +0 -22
  320. package/src/directive/attrs/element-style.spec.js +0 -85
  321. package/src/directive/attrs/element-style.test.js +0 -12
  322. package/src/directive/attrs/src.html +0 -19
  323. package/src/directive/attrs/src.spec.js +0 -163
  324. package/src/directive/attrs/src.test.js +0 -12
  325. package/src/directive/bind/bind-html.spec.js +0 -36
  326. package/src/directive/bind/bind.html +0 -20
  327. package/src/directive/bind/bind.js +0 -78
  328. package/src/directive/bind/bind.md +0 -142
  329. package/src/directive/bind/bind.spec.js +0 -314
  330. package/src/directive/bind/bind.test.js +0 -12
  331. package/src/directive/channel/channel.html +0 -19
  332. package/src/directive/channel/channel.js +0 -30
  333. package/src/directive/channel/channel.spec.js +0 -67
  334. package/src/directive/channel/channel.test.js +0 -10
  335. package/src/directive/class/class-test.html +0 -23
  336. package/src/directive/class/class.html +0 -19
  337. package/src/directive/class/class.js +0 -184
  338. package/src/directive/class/class.spec.js +0 -704
  339. package/src/directive/class/class.test.js +0 -12
  340. package/src/directive/cloak/cloak.html +0 -19
  341. package/src/directive/cloak/cloak.js +0 -11
  342. package/src/directive/cloak/cloak.spec.js +0 -44
  343. package/src/directive/cloak/cloak.test.js +0 -12
  344. package/src/directive/controller/controller.html +0 -22
  345. package/src/directive/controller/controller.js +0 -11
  346. package/src/directive/controller/controller.md +0 -46
  347. package/src/directive/controller/controller.spec.js +0 -175
  348. package/src/directive/controller/controller.test.js +0 -12
  349. package/src/directive/events/click.spec.js +0 -35
  350. package/src/directive/events/event.spec.js +0 -267
  351. package/src/directive/events/events-test.html +0 -36
  352. package/src/directive/events/events.html +0 -20
  353. package/src/directive/events/events.js +0 -65
  354. package/src/directive/events/events.md +0 -125
  355. package/src/directive/events/events.test.js +0 -12
  356. package/src/directive/form/form.html +0 -19
  357. package/src/directive/form/form.js +0 -669
  358. package/src/directive/form/form.spec.js +0 -1515
  359. package/src/directive/form/form.test.js +0 -12
  360. package/src/directive/http/delete.spec.js +0 -23
  361. package/src/directive/http/form-router-test.html +0 -44
  362. package/src/directive/http/form-test.html +0 -18
  363. package/src/directive/http/get.spec.js +0 -488
  364. package/src/directive/http/http.html +0 -22
  365. package/src/directive/http/http.js +0 -342
  366. package/src/directive/http/http.test.js +0 -12
  367. package/src/directive/http/interface.ts +0 -36
  368. package/src/directive/http/post-example.html +0 -30
  369. package/src/directive/http/post.spec.js +0 -521
  370. package/src/directive/http/put.spec.js +0 -23
  371. package/src/directive/if/if-animate-css.html +0 -57
  372. package/src/directive/if/if-animate-svg.html +0 -25
  373. package/src/directive/if/if.html +0 -19
  374. package/src/directive/if/if.js +0 -72
  375. package/src/directive/if/if.md +0 -76
  376. package/src/directive/if/if.spec.js +0 -293
  377. package/src/directive/if/if.test.js +0 -114
  378. package/src/directive/include/include.html +0 -19
  379. package/src/directive/include/include.js +0 -151
  380. package/src/directive/include/include.md +0 -87
  381. package/src/directive/include/include.spec.js +0 -734
  382. package/src/directive/include/include.test.js +0 -12
  383. package/src/directive/init/init.html +0 -19
  384. package/src/directive/init/init.js +0 -22
  385. package/src/directive/init/init.md +0 -41
  386. package/src/directive/init/init.spec.js +0 -68
  387. package/src/directive/init/init.test.js +0 -12
  388. package/src/directive/inject/inject.html +0 -19
  389. package/src/directive/inject/inject.js +0 -35
  390. package/src/directive/inject/inject.spec.js +0 -108
  391. package/src/directive/inject/inject.test.js +0 -12
  392. package/src/directive/input/input-example.html +0 -15
  393. package/src/directive/input/input.html +0 -19
  394. package/src/directive/input/input.js +0 -1078
  395. package/src/directive/input/input.md +0 -706
  396. package/src/directive/input/input.spec.js +0 -3700
  397. package/src/directive/input/input.test.js +0 -12
  398. package/src/directive/messages/messages.html +0 -22
  399. package/src/directive/messages/messages.js +0 -349
  400. package/src/directive/messages/messages.md +0 -543
  401. package/src/directive/messages/messages.spec.js +0 -1083
  402. package/src/directive/messages/messages.test.js +0 -12
  403. package/src/directive/model/change.md +0 -25
  404. package/src/directive/model/model.html +0 -19
  405. package/src/directive/model/model.js +0 -1170
  406. package/src/directive/model/model.spec.js +0 -1976
  407. package/src/directive/model/model.test.js +0 -12
  408. package/src/directive/model-options/model-option.test.js +0 -12
  409. package/src/directive/model-options/model-options.html +0 -22
  410. package/src/directive/model-options/model-options.js +0 -142
  411. package/src/directive/model-options/model-options.md +0 -407
  412. package/src/directive/model-options/model-options.spec.js +0 -1022
  413. package/src/directive/non-bindable/non-bindable.html +0 -22
  414. package/src/directive/non-bindable/non-bindable.js +0 -9
  415. package/src/directive/non-bindable/non-bindable.spec.js +0 -59
  416. package/src/directive/non-bindable/non-bindable.test.js +0 -12
  417. package/src/directive/observe/observe-demo.html +0 -184
  418. package/src/directive/observe/observe.html +0 -19
  419. package/src/directive/observe/observe.js +0 -41
  420. package/src/directive/observe/observe.spec.js +0 -106
  421. package/src/directive/observe/observe.test.js +0 -10
  422. package/src/directive/on/on.html +0 -19
  423. package/src/directive/on/on.spec.js +0 -215
  424. package/src/directive/on/on.test.js +0 -12
  425. package/src/directive/options/options-example.html +0 -17
  426. package/src/directive/options/options.html +0 -22
  427. package/src/directive/options/options.js +0 -542
  428. package/src/directive/options/options.md +0 -179
  429. package/src/directive/options/options.spec.js +0 -3554
  430. package/src/directive/options/options.test.js +0 -12
  431. package/src/directive/ref/href.html +0 -19
  432. package/src/directive/ref/href.spec.js +0 -141
  433. package/src/directive/ref/href.test.js +0 -19
  434. package/src/directive/ref/ref.html +0 -19
  435. package/src/directive/ref/ref.js +0 -89
  436. package/src/directive/ref/ref.spec.js +0 -546
  437. package/src/directive/repeat/repeat.html +0 -19
  438. package/src/directive/repeat/repeat.js +0 -333
  439. package/src/directive/repeat/repeat.md +0 -330
  440. package/src/directive/repeat/repeat.spec.js +0 -1209
  441. package/src/directive/repeat/repeat.test.js +0 -12
  442. package/src/directive/script/script.html +0 -19
  443. package/src/directive/script/script.js +0 -17
  444. package/src/directive/script/script.md +0 -11
  445. package/src/directive/script/script.spec.js +0 -47
  446. package/src/directive/script/script.test.js +0 -12
  447. package/src/directive/select/select.html +0 -19
  448. package/src/directive/select/select.js +0 -594
  449. package/src/directive/select/select.md +0 -74
  450. package/src/directive/select/select.spec.js +0 -2566
  451. package/src/directive/select/select.test.js +0 -12
  452. package/src/directive/setter/setter.html +0 -19
  453. package/src/directive/setter/setter.js +0 -59
  454. package/src/directive/setter/setter.spec.js +0 -100
  455. package/src/directive/setter/setter.test.js +0 -12
  456. package/src/directive/show-hide/show-hide.html +0 -22
  457. package/src/directive/show-hide/show-hide.js +0 -65
  458. package/src/directive/show-hide/show-hide.md +0 -255
  459. package/src/directive/show-hide/show-hide.spec.js +0 -268
  460. package/src/directive/show-hide/show-hide.test.js +0 -12
  461. package/src/directive/style/style.html +0 -19
  462. package/src/directive/style/style.js +0 -27
  463. package/src/directive/style/style.md +0 -23
  464. package/src/directive/style/style.spec.js +0 -183
  465. package/src/directive/style/style.test.js +0 -12
  466. package/src/directive/switch/switch.html +0 -19
  467. package/src/directive/switch/switch.js +0 -133
  468. package/src/directive/switch/switch.md +0 -66
  469. package/src/directive/switch/switch.spec.js +0 -509
  470. package/src/directive/switch/switch.test.js +0 -12
  471. package/src/directive/transclude/transclude.js +0 -122
  472. package/src/directive/validators/validators.html +0 -22
  473. package/src/directive/validators/validators.js +0 -346
  474. package/src/directive/validators/validators.spec.js +0 -740
  475. package/src/directive/validators/validators.test.js +0 -12
  476. package/src/filters/filter.js +0 -213
  477. package/src/filters/filter.spec.js +0 -719
  478. package/src/filters/filters.html +0 -22
  479. package/src/filters/filters.js +0 -239
  480. package/src/filters/filters.spec.js +0 -36
  481. package/src/filters/filters.test.js +0 -12
  482. package/src/filters/interface.ts +0 -9
  483. package/src/filters/limit-to.js +0 -55
  484. package/src/filters/limit-to.spec.js +0 -252
  485. package/src/filters/order-by.js +0 -181
  486. package/src/filters/order-by.spec.js +0 -883
  487. package/src/index.js +0 -6
  488. package/src/index.spec.js +0 -11
  489. package/src/injection-tokens.js +0 -81
  490. package/src/interface.ts +0 -430
  491. package/src/ng.js +0 -291
  492. package/src/ng.spec.js +0 -45
  493. package/src/router/common/trace.js +0 -240
  494. package/src/router/directives/component-example.html +0 -37
  495. package/src/router/directives/state-directives.html +0 -22
  496. package/src/router/directives/state-directives.js +0 -393
  497. package/src/router/directives/state-directives.md +0 -435
  498. package/src/router/directives/state-directives.spec.js +0 -1091
  499. package/src/router/directives/state-directives.test.js +0 -10
  500. package/src/router/directives/view-directive.js +0 -489
  501. package/src/router/directives/view-directive.spec.js +0 -1921
  502. package/src/router/directives/view-directive.test.js +0 -10
  503. package/src/router/directives/view-directives.html +0 -22
  504. package/src/router/glob/glob.html +0 -19
  505. package/src/router/glob/glob.js +0 -102
  506. package/src/router/glob/glob.spec.js +0 -108
  507. package/src/router/glob/glob.test.js +0 -12
  508. package/src/router/hooks/core-resolvables.js +0 -38
  509. package/src/router/hooks/ignored-transition.js +0 -25
  510. package/src/router/hooks/invalid-transition.js +0 -14
  511. package/src/router/hooks/lazy-load.js +0 -104
  512. package/src/router/hooks/on-enter-exit-retain.js +0 -55
  513. package/src/router/hooks/redirect-to.js +0 -38
  514. package/src/router/hooks/resolve.js +0 -57
  515. package/src/router/hooks/update-globals.js +0 -34
  516. package/src/router/hooks/url.js +0 -34
  517. package/src/router/hooks/views.js +0 -41
  518. package/src/router/params/interface.ts +0 -626
  519. package/src/router/params/param-factory.js +0 -23
  520. package/src/router/params/param-type.js +0 -133
  521. package/src/router/params/param-types.js +0 -153
  522. package/src/router/params/param.js +0 -243
  523. package/src/router/params/state-params.js +0 -36
  524. package/src/router/path/path-node.js +0 -78
  525. package/src/router/path/path-utils.js +0 -207
  526. package/src/router/resolve/interface.ts +0 -208
  527. package/src/router/resolve/resolvable.js +0 -123
  528. package/src/router/resolve/resolve-context.js +0 -190
  529. package/src/router/router-test-hashbang.html +0 -45
  530. package/src/router/router-test.html +0 -41
  531. package/src/router/router.html +0 -22
  532. package/src/router/router.js +0 -54
  533. package/src/router/router.test.js +0 -12
  534. package/src/router/services.spec.js +0 -52
  535. package/src/router/state/interface.ts +0 -1007
  536. package/src/router/state/state-builder.js +0 -376
  537. package/src/router/state/state-builder.spec.js +0 -86
  538. package/src/router/state/state-matcher.js +0 -64
  539. package/src/router/state/state-object.js +0 -118
  540. package/src/router/state/state-queue-manager.js +0 -95
  541. package/src/router/state/state-registry.js +0 -262
  542. package/src/router/state/state-service.js +0 -687
  543. package/src/router/state/state.html +0 -23
  544. package/src/router/state/state.spec.js +0 -1002
  545. package/src/router/state/state.test.js +0 -12
  546. package/src/router/state/target-state.js +0 -162
  547. package/src/router/state/views.js +0 -195
  548. package/src/router/state-filter.spec.js +0 -139
  549. package/src/router/state-filters.js +0 -46
  550. package/src/router/template-factory.html +0 -19
  551. package/src/router/template-factory.js +0 -249
  552. package/src/router/template-factory.spec.js +0 -146
  553. package/src/router/template-factory.test.js +0 -12
  554. package/src/router/transition/hook-builder.js +0 -137
  555. package/src/router/transition/hook-registry.js +0 -181
  556. package/src/router/transition/interface.js +0 -18
  557. package/src/router/transition/interface.ts +0 -922
  558. package/src/router/transition/reject-factory.js +0 -122
  559. package/src/router/transition/transition-event-type.js +0 -26
  560. package/src/router/transition/transition-hook.js +0 -199
  561. package/src/router/transition/transition-service.js +0 -297
  562. package/src/router/transition/transition.js +0 -653
  563. package/src/router/url/url-config.js +0 -155
  564. package/src/router/url/url-matcher.js +0 -532
  565. package/src/router/url/url-rule.js +0 -231
  566. package/src/router/url/url-rules.js +0 -350
  567. package/src/router/url/url-service.js +0 -446
  568. package/src/router/url/url-service.spec.js +0 -1288
  569. package/src/router/url/url.html +0 -19
  570. package/src/router/url/url.test.js +0 -12
  571. package/src/router/view/interface.ts +0 -51
  572. package/src/router/view/view.html +0 -19
  573. package/src/router/view/view.js +0 -262
  574. package/src/router/view/view.spec.js +0 -100
  575. package/src/router/view/view.test.js +0 -12
  576. package/src/router/view-hook.spec.js +0 -215
  577. package/src/router/view-scroll.js +0 -33
  578. package/src/router/view-scroll.spec.js +0 -72
  579. package/src/services/anchor-scroll/anchor-scroll.html +0 -76
  580. package/src/services/anchor-scroll/anchor-scroll.js +0 -147
  581. package/src/services/exception/exception-handler.js +0 -75
  582. package/src/services/exception/interface.ts +0 -7
  583. package/src/services/http/http.html +0 -23
  584. package/src/services/http/http.js +0 -1109
  585. package/src/services/http/http.spec.js +0 -4320
  586. package/src/services/http/http.test.js +0 -11
  587. package/src/services/http/interface.ts +0 -256
  588. package/src/services/http/template-request.spec.js +0 -220
  589. package/src/services/location/interface.ts +0 -70
  590. package/src/services/location/location.html +0 -22
  591. package/src/services/location/location.js +0 -1006
  592. package/src/services/location/location.spec.js +0 -3792
  593. package/src/services/location/location.test.js +0 -12
  594. package/src/services/log/interface.ts +0 -39
  595. package/src/services/log/log.html +0 -19
  596. package/src/services/log/log.js +0 -74
  597. package/src/services/log/log.spec.js +0 -64
  598. package/src/services/log/log.test.js +0 -12
  599. package/src/services/pubsub/pubsub.html +0 -19
  600. package/src/services/pubsub/pubsub.js +0 -349
  601. package/src/services/pubsub/pubsub.spec.js +0 -400
  602. package/src/services/pubsub/pubsub.test.js +0 -12
  603. package/src/services/sce/sce.html +0 -19
  604. package/src/services/sce/sce.js +0 -852
  605. package/src/services/sce/sce.spec.js +0 -617
  606. package/src/services/sce/sce.test.js +0 -12
  607. package/src/services/template-cache/template-cache.html +0 -22
  608. package/src/services/template-cache/template-cache.js +0 -15
  609. package/src/services/template-cache/template-cache.spec.js +0 -134
  610. package/src/services/template-cache/template-cache.test.js +0 -12
  611. package/src/services/template-request/interface.ts +0 -23
  612. package/src/services/template-request/template-request.js +0 -142
  613. package/src/shared/cache.js +0 -7
  614. package/src/shared/common.js +0 -365
  615. package/src/shared/common.spec.js +0 -294
  616. package/src/shared/constants.js +0 -21
  617. package/src/shared/dom.js +0 -716
  618. package/src/shared/hof.js +0 -157
  619. package/src/shared/hof.spec.js +0 -60
  620. package/src/shared/interface.ts +0 -21
  621. package/src/shared/min-err.spec.js +0 -178
  622. package/src/shared/noderef.js +0 -225
  623. package/src/shared/predicates.js +0 -34
  624. package/src/shared/queue.js +0 -105
  625. package/src/shared/queue.spec.js +0 -80
  626. package/src/shared/shared.html +0 -24
  627. package/src/shared/shared.test.js +0 -12
  628. package/src/shared/strings.js +0 -142
  629. package/src/shared/strings.spec.js +0 -40
  630. package/src/shared/test-utils.js +0 -47
  631. package/src/shared/url-utils/interface.ts +0 -54
  632. package/src/shared/url-utils/url-utils.html +0 -22
  633. package/src/shared/url-utils/url-utils.js +0 -122
  634. package/src/shared/url-utils/url-utils.spec.js +0 -148
  635. package/src/shared/url-utils/url-utils.test.js +0 -12
  636. package/src/shared/utils.js +0 -1255
  637. package/src/shared/utils.spec.js +0 -178
  638. package/src/src.html +0 -21
  639. package/src/src.test.js +0 -10
  640. package/tsconfig.json +0 -19
  641. package/tsconfig.types.json +0 -14
  642. package/typedoc.json +0 -8
  643. package/utils/express.js +0 -203
  644. package/utils/version.cjs +0 -23
  645. package/vite.config.js +0 -14
@@ -1,2310 +0,0 @@
1
- import { Angular } from "../../angular.js";
2
- import { createInjector, annotate } from "./injector.js";
3
- import { extend } from "../../shared/utils.js";
4
-
5
- describe("injector.modules", () => {
6
- beforeEach(() => {
7
- window.angular = new Angular();
8
- });
9
-
10
- it("can be created", () => {
11
- const injector = createInjector([]);
12
- expect(injector).toBeDefined();
13
- });
14
-
15
- it("should have $injector", () => {
16
- const $injector = createInjector([]);
17
- expect($injector.get("$injector")).toBe($injector);
18
- });
19
-
20
- it("should have modules property", () => {
21
- const $injector = createInjector([]);
22
- expect($injector.modules).toEqual({});
23
- });
24
-
25
- it("should have methods", () => {
26
- const $injector = createInjector([]);
27
- expect($injector.has).toBeDefined();
28
- expect($injector.invoke).toBeDefined();
29
- expect($injector.instantiate).toBeDefined();
30
- expect($injector.get).toBeDefined();
31
- });
32
-
33
- it("should have a false strictDi property", () => {
34
- const injector = createInjector([]);
35
- expect(injector.strictDi).toBe(false);
36
- });
37
-
38
- it("should check its modulesToLoad argument", () => {
39
- expect(() => {
40
- createInjector(["test"]);
41
- }).toThrow();
42
- });
43
-
44
- it("should provide useful message if no provider", () => {
45
- expect(() => {
46
- const injector = createInjector([]);
47
- injector.get("idontexist");
48
- }).toThrowError(/Unknown provider/);
49
- });
50
-
51
- it("has a constant that has been registered to a module", () => {
52
- const module = angular.module("myModule", []);
53
- module.constant("aConstant", 42);
54
-
55
- const injector = createInjector(["myModule"]);
56
- expect(injector.has("aConstant")).toBe(true);
57
- });
58
-
59
- it("does not have a non-registered constant", () => {
60
- angular.module("myModule", []);
61
- const injector = createInjector(["myModule"]);
62
- expect(injector.has("aConstant")).toBe(false);
63
- });
64
-
65
- it("does not allow a constant called hasOwnProperty", () => {
66
- const module = angular.module("myModule", []);
67
- module.constant("hasOwnProperty", false);
68
- expect(() => {
69
- createInjector(["myModule"]);
70
- }).toThrow();
71
- });
72
-
73
- it("can return a registered constant", () => {
74
- const module = angular.module("myModule", []);
75
- module.constant("aConstant", 42);
76
- const injector = createInjector(["myModule"]);
77
- expect(injector.get("aConstant")).toBe(42);
78
- });
79
-
80
- it("loads multiple modules", () => {
81
- const module1 = angular.module("myModule", []);
82
- const module2 = angular.module("myOtherModule", []);
83
- module1.constant("aConstant", 42);
84
- module2.constant("anotherConstant", 43);
85
- const injector = createInjector(["myModule", "myOtherModule"]);
86
- expect(injector.has("aConstant")).toBe(true);
87
- expect(injector.has("anotherConstant")).toBe(true);
88
- });
89
-
90
- it("loadNewModules should be defined on $injector", () => {
91
- const injector = createInjector([]);
92
- expect(injector.loadNewModules).toEqual(jasmine.any(Function));
93
- });
94
-
95
- it("should allow new modules to be added after injector creation", () => {
96
- angular.module("initial", []);
97
- const injector = createInjector(["initial"]);
98
- expect(injector.modules.initial).toBeDefined();
99
- expect(injector.modules.lazy).toBeUndefined();
100
- angular.module("lazy", []);
101
- injector.loadNewModules(["lazy"]);
102
- expect(injector.modules.lazy).toBeDefined();
103
- });
104
-
105
- it("should execute runBlocks of new modules", () => {
106
- const log = [];
107
- angular.module("initial", []).run(() => {
108
- log.push("initial");
109
- });
110
- const injector = createInjector(["initial"]);
111
- log.push("created");
112
-
113
- angular.module("a", []).run(() => {
114
- log.push("a");
115
- });
116
- injector.loadNewModules(["a"]);
117
- expect(log).toEqual(["initial", "created", "a"]);
118
- });
119
-
120
- it("should execute configBlocks of new modules", () => {
121
- const log = [];
122
- angular.module("initial", []).config(() => {
123
- log.push("initial");
124
- });
125
- const injector = createInjector(["initial"]);
126
- expect(log).toEqual(["initial"]);
127
- log.push("created");
128
-
129
- angular
130
- .module("a", [], () => {
131
- log.push("config1");
132
- })
133
- .config(() => {
134
- log.push("config2");
135
- });
136
- injector.loadNewModules(["a"]);
137
- expect(log).toEqual(["initial", "created", "config1", "config2"]);
138
- });
139
-
140
- it("should execute runBlocks and configBlocks in the correct order", () => {
141
- const log = [];
142
- angular
143
- .module("initial", [], () => {
144
- log.push(1);
145
- })
146
- .config(() => {
147
- log.push(2);
148
- })
149
- .run(() => {
150
- log.push(3);
151
- });
152
- const injector = createInjector(["initial"]);
153
- log.push("created");
154
-
155
- angular
156
- .module("a", [], () => {
157
- log.push(4);
158
- })
159
- .config(() => {
160
- log.push(5);
161
- })
162
- .run(() => {
163
- log.push(6);
164
- });
165
- injector.loadNewModules(["a"]);
166
- expect(log).toEqual([1, 2, 3, "created", 4, 5, 6]);
167
- });
168
-
169
- it("should load dependent modules", () => {
170
- angular.module("initial", []);
171
- const injector = createInjector(["initial"]);
172
- expect(injector.modules.initial).toBeDefined();
173
- expect(injector.modules.lazy1).toBeUndefined();
174
- expect(injector.modules.lazy2).toBeUndefined();
175
- angular.module("lazy1", ["lazy2"]);
176
- angular.module("lazy2", []);
177
- injector.loadNewModules(["lazy1"]);
178
- expect(injector.modules.lazy1).toBeDefined();
179
- expect(injector.modules.lazy2).toBeDefined();
180
- });
181
-
182
- it("should execute blocks of new modules in the correct order", () => {
183
- const log = [];
184
- angular.module("initial", []);
185
- const injector = createInjector(["initial"]);
186
-
187
- angular
188
- .module("lazy1", ["lazy2"], () => {
189
- log.push("lazy1-1");
190
- })
191
- .config(() => {
192
- log.push("lazy1-2");
193
- })
194
- .run(() => {
195
- log.push("lazy1-3");
196
- });
197
- angular
198
- .module("lazy2", [], () => {
199
- log.push("lazy2-1");
200
- })
201
- .config(() => {
202
- log.push("lazy2-2");
203
- })
204
- .run(() => {
205
- log.push("lazy2-3");
206
- });
207
-
208
- injector.loadNewModules(["lazy1"]);
209
- expect(log).toEqual([
210
- "lazy2-1",
211
- "lazy2-2",
212
- "lazy1-1",
213
- "lazy1-2",
214
- "lazy2-3",
215
- "lazy1-3",
216
- ]);
217
- });
218
-
219
- it("should not reload a module that is already loaded", () => {
220
- const log = [];
221
- angular.module("initial", []).run(() => {
222
- log.push("initial");
223
- });
224
- const injector = createInjector(["initial"]);
225
- expect(log).toEqual(["initial"]);
226
-
227
- injector.loadNewModules(["initial"]);
228
- expect(log).toEqual(["initial"]);
229
-
230
- angular.module("a", []).run(() => {
231
- log.push("a");
232
- });
233
- injector.loadNewModules(["a"]);
234
- expect(log).toEqual(["initial", "a"]);
235
- injector.loadNewModules(["a"]);
236
- expect(log).toEqual(["initial", "a"]);
237
-
238
- angular.module("b", ["a"]).run(() => {
239
- log.push("b");
240
- });
241
- angular.module("c", []).run(() => {
242
- log.push("c");
243
- });
244
- angular.module("d", ["b", "c"]).run(() => {
245
- log.push("d");
246
- });
247
- injector.loadNewModules(["d"]);
248
- expect(log).toEqual(["initial", "a", "b", "c", "d"]);
249
- });
250
-
251
- it("loads the required modules of a module", () => {
252
- const module1 = angular.module("myModule", []);
253
- const module2 = angular.module("myOtherModule", ["myModule"]);
254
- module1.constant("aConstant", 42);
255
- module2.constant("anotherConstant", 43);
256
- const injector = createInjector(["myOtherModule"]);
257
- expect(injector.has("aConstant")).toBe(true);
258
- expect(injector.has("anotherConstant")).toBe(true);
259
- });
260
-
261
- it("loads the transitively required modules of a module", () => {
262
- const module1 = angular.module("myModule", []);
263
- const module2 = angular.module("myOtherModule", ["myModule"]);
264
- const module3 = angular.module("myThirdModule", ["myOtherModule"]);
265
- module1.constant("aConstant", 42);
266
- module2.constant("anotherConstant", 43);
267
- module3.constant("aThirdConstant", 44);
268
- const injector = createInjector(["myThirdModule"]);
269
- expect(injector.has("aConstant")).toBe(true);
270
- expect(injector.has("anotherConstant")).toBe(true);
271
- expect(injector.has("aThirdConstant")).toBe(true);
272
- });
273
-
274
- it("loads each module only once", () => {
275
- angular.module("myModule", ["myOtherModule"]);
276
- angular.module("myOtherModule", ["myModule"]);
277
- let injector = createInjector(["myModule"]);
278
- expect(Object.keys(injector.modules).length).toEqual(2);
279
- });
280
-
281
- it("invokes an annotated function with dependency injection", () => {
282
- const module = angular.module("myModule", []);
283
- module.constant("a", 1);
284
- module.constant("b", 2);
285
- const injector = createInjector(["myModule"]);
286
- const fn = (one, two) => {
287
- return one + two;
288
- };
289
- fn.$inject = ["a", "b"];
290
- expect(injector.invoke(fn)).toBe(3);
291
- });
292
-
293
- it("invokes a class with static property with dependency injection", () => {
294
- const module = angular.module("myModule", []);
295
- module.constant("a", 1);
296
- module.constant("b", 2);
297
- const injector = createInjector(["myModule"]);
298
- class Foo {
299
- /* @ignore */ static $inject = ["a", "b"];
300
- constructor(a, b) {
301
- this.c = a + b;
302
- }
303
- }
304
- expect(injector.invoke(Foo).c).toBe(3);
305
- });
306
-
307
- it("invokes an annotated class with dependency injection", () => {
308
- const module = angular.module("myModule", []);
309
- module.constant("a", 1);
310
- module.constant("b", 2);
311
- const injector = createInjector(["myModule"]);
312
- class Foo {
313
- constructor(a, b) {
314
- this.c = a + b;
315
- }
316
- }
317
- Foo.$inject = ["a", "b"];
318
- expect(injector.invoke(Foo).c).toBe(3);
319
- });
320
-
321
- it("does not accept non-strings as injection tokens", () => {
322
- const module = angular.module("myModule", []);
323
- module.constant("a", 1);
324
- const injector = createInjector(["myModule"]);
325
- const fn = function (one, two) {
326
- return one + two;
327
- };
328
- fn.$inject = ["a", 2];
329
- expect(() => {
330
- injector.invoke(fn);
331
- }).toThrow();
332
- });
333
-
334
- it("invokes a function with the given this context", () => {
335
- const module = angular.module("myModule", []);
336
- module.constant("a", 1);
337
- const injector = createInjector(["myModule"]);
338
- const obj = {
339
- two: 2,
340
- fn: function (one) {
341
- return one + this.two;
342
- },
343
- };
344
- obj.fn.$inject = ["a"];
345
- expect(injector.invoke(obj.fn, obj)).toBe(3);
346
- });
347
-
348
- it("invokes a function with array of injection tokens", () => {
349
- const module = angular.module("myModule", []);
350
- module.constant("a", 1);
351
- const injector = createInjector(["myModule"]);
352
- const obj = {
353
- two: 2,
354
- fn: function (one) {
355
- return one + this.two;
356
- },
357
- };
358
- expect(injector.invoke(["a", obj.fn], obj)).toBe(3);
359
- });
360
-
361
- it("overrides dependencies with locals when invoking", () => {
362
- const module = angular.module("myModule", []);
363
- module.constant("a", 1);
364
- module.constant("b", 2);
365
- const injector = createInjector(["myModule"]);
366
- const fn = function (one, two) {
367
- return one + two;
368
- };
369
- fn.$inject = ["a", "b"];
370
- expect(injector.invoke(fn, undefined, { b: 3 })).toBe(4);
371
- });
372
- });
373
-
374
- describe("annotate", () => {
375
- let injector;
376
- beforeEach(() => {
377
- window.angular = new Angular();
378
- injector = createInjector([]);
379
- });
380
-
381
- it("should return $inject", () => {
382
- function fn() {}
383
- fn.$inject = ["a"];
384
- expect(annotate(fn)).toBe(fn.$inject);
385
- expect(annotate(() => {})).toEqual([]);
386
- expect(annotate(() => {})).toEqual([]);
387
- expect(annotate(() => {})).toEqual([]);
388
- expect(annotate(/* */ () => {})).toEqual([]);
389
- });
390
-
391
- it("should create $inject", () => {
392
- const extraParams = () => {};
393
- // keep the multi-line to make sure we can handle it
394
- function $f_n0 /*
395
- */(
396
- $a, // x, <-- looks like an arg but it is a comment
397
- b_ /* z, <-- looks like an arg but it is a
398
- multi-line comment
399
- function(a, b) {}
400
- */,
401
- _c,
402
- /* {some type} */ d,
403
- ) {
404
- extraParams();
405
- }
406
-
407
- expect(annotate($f_n0)).toEqual(["$a", "b_", "_c", "d"]);
408
- expect($f_n0.$inject).toEqual(["$a", "b_", "_c", "d"]);
409
- });
410
-
411
- it("should strip leading and trailing underscores from arg name during inference", () => {
412
- function beforeEachFn(_foo_) {
413
- /* foo = _foo_ */
414
- }
415
- expect(annotate(beforeEachFn)).toEqual(["foo"]);
416
- });
417
-
418
- it("should not strip service names with a single underscore", () => {
419
- function beforeEachFn(_) {
420
- /* _ = _ */
421
- }
422
- expect(annotate(beforeEachFn)).toEqual(["_"]);
423
- });
424
-
425
- it("should handle no arg functions", () => {
426
- function $f_n0() {}
427
- expect(annotate($f_n0)).toEqual([]);
428
- expect($f_n0.$inject).toEqual([]);
429
- });
430
-
431
- it("should handle no arg functions with spaces in the arguments list", () => {
432
- function fn() {}
433
- expect(annotate(fn)).toEqual([]);
434
- expect(fn.$inject).toEqual([]);
435
- });
436
-
437
- it("should handle args with both $ and _", () => {
438
- function $f_n0($a_) {}
439
- expect(annotate($f_n0)).toEqual(["$a_"]);
440
- expect($f_n0.$inject).toEqual(["$a_"]);
441
- });
442
-
443
- it("should handle functions with overridden toString", () => {
444
- function fn(a) {}
445
- fn.toString = () => {
446
- return "fn";
447
- };
448
- expect(annotate(fn)).toEqual(["a"]);
449
- expect(fn.$inject).toEqual(["a"]);
450
- });
451
-
452
- it("should throw on non function arg", () => {
453
- expect(() => {
454
- annotate({});
455
- }).toThrow();
456
- });
457
-
458
- describe("es6", () => {
459
- it("should be possible to annotate shorthand methods", () => {
460
- expect(annotate(eval("({ fn(x) { return; } })").fn)).toEqual(["x"]);
461
- });
462
-
463
- it("should create $inject for arrow functions", () => {
464
- expect(annotate(eval("(a, b) => a"))).toEqual(["a", "b"]);
465
- });
466
- it("should create $inject for arrow functions with no parenthesis", () => {
467
- expect(annotate(eval("a => a"))).toEqual(["a"]);
468
- });
469
-
470
- it("should take args before first arrow", () => {
471
- expect(annotate(eval("a => b => b"))).toEqual(["a"]);
472
- });
473
-
474
- it("should detect ES6 classes regardless of whitespace/comments ($prop)", () =>
475
- [
476
- "class Test {}",
477
- "class Test{}",
478
- "class //<--ES6 stuff\nTest {}",
479
- "class//<--ES6 stuff\nTest {}",
480
- "class {}",
481
- "class{}",
482
- "class //<--ES6 stuff\n {}",
483
- "class//<--ES6 stuff\n {}",
484
- "class/* Test */{}",
485
- "class /* Test */ {}",
486
- ].forEach((classDefinition) => {
487
- const Clazz = eval(`(${classDefinition})`);
488
- const instance = injector.invoke(Clazz);
489
-
490
- expect(instance).toEqual(jasmine.any(Clazz));
491
- }));
492
- });
493
-
494
- it("returns the $inject annotation of a function when it has one", () => {
495
- const injector = createInjector([]);
496
- const fn = () => {};
497
- fn.$inject = ["a", "b"];
498
- expect(annotate(fn)).toEqual(["a", "b"]);
499
- });
500
-
501
- it("returns the array-style annotations of a function", () => {
502
- const injector = createInjector([]);
503
- const fn = ["a", "b", () => {}];
504
- expect(annotate(fn)).toEqual(["a", "b"]);
505
- });
506
-
507
- it("returns the array-style annotations of a function", () => {
508
- const injector = createInjector([]);
509
- const fn = ["a", "b", () => {}];
510
- expect(annotate(fn)).toEqual(["a", "b"]);
511
- });
512
-
513
- it("returns annotations parsed from function args when not annotated", () => {
514
- const injector = createInjector([]);
515
- const fn = function (a, b) {};
516
- expect(annotate(fn)).toEqual(["a", "b"]);
517
- });
518
-
519
- it("returns annotations parsed from arrow args when not annotated", () => {
520
- const injector = createInjector([]);
521
- const fn = (a, b) => {};
522
- expect(annotate(fn)).toEqual(["a", "b"]);
523
- });
524
-
525
- it("strips comments from argument lists when parsing", () => {
526
- const injector = createInjector([]);
527
- const fn = function (a, /*b,*/ c) {};
528
- expect(annotate(fn)).toEqual(["a", "c"]);
529
- });
530
-
531
- it("strips several comments from argument lists when parsing", () => {
532
- const injector = createInjector([]);
533
- const fn = function (a, /*b,*/ c /*, d*/) {};
534
- expect(annotate(fn)).toEqual(["a", "c"]);
535
- });
536
-
537
- it("strips // comments from argument lists when parsing", () => {
538
- const injector = createInjector([]);
539
- const fn = function (
540
- a, //b,
541
- c,
542
- ) {};
543
- expect(annotate(fn)).toEqual(["a", "c"]);
544
- });
545
-
546
- it("strips surrounding underscores from argument names when parsing", () => {
547
- const injector = createInjector([]);
548
- const fn = function (a, _b_, c_, _d, an_argument) {};
549
- expect(annotate(fn)).toEqual(["a", "b", "c_", "_d", "an_argument"]);
550
- });
551
-
552
- it("throws when using a non-annotated fn in strict mode", () => {
553
- const injector = createInjector([], true);
554
- const fn = function (a, b, c) {};
555
-
556
- expect(() => {
557
- injector.annotate(fn, true);
558
- }).toThrow();
559
- });
560
-
561
- it("invokes an array-annotated function with dependency injection", () => {
562
- const module = angular.module("myModule", []);
563
- module.constant("a", 1);
564
- module.constant("b", 2);
565
- const injector = createInjector(["myModule"]);
566
- const fn = [
567
- "a",
568
- "b",
569
- function (one, two) {
570
- return one + two;
571
- },
572
- ];
573
- expect(injector.invoke(fn)).toBe(3);
574
- });
575
-
576
- it("invokes a non-annotated function with dependency injection", () => {
577
- const module = angular.module("myModule", []);
578
- module.constant("a", 1);
579
- module.constant("b", 2);
580
- const injector = createInjector(["myModule"]);
581
- const fn = function (a, b) {
582
- return a + b;
583
- };
584
- expect(injector.invoke(fn)).toBe(3);
585
- });
586
-
587
- it("instantiates an annotated constructor function", () => {
588
- const module = angular.module("myModule", []);
589
- module.constant("a", 1);
590
- module.constant("b", 2);
591
- const injector = createInjector(["myModule"]);
592
- function Type(one, two) {
593
- this.result = one + two;
594
- }
595
- Type.$inject = ["a", "b"];
596
- const instance = injector.instantiate(Type);
597
- expect(instance.result).toBe(3);
598
- });
599
-
600
- it("instantiates an array-annotated constructor function", () => {
601
- const module = angular.module("myModule", []);
602
- module.constant("a", 1);
603
- module.constant("b", 2);
604
- const injector = createInjector(["myModule"]);
605
- function Type(one, two) {
606
- this.result = one + two;
607
- }
608
- const instance = injector.instantiate(["a", "b", Type]);
609
- expect(instance.result).toBe(3);
610
- });
611
-
612
- it("instantiates a non-annotated constructor function", () => {
613
- const module = angular.module("myModule", []);
614
- module.constant("a", 1);
615
- module.constant("b", 2);
616
- const injector = createInjector(["myModule"]);
617
- function Type(a, b) {
618
- this.result = a + b;
619
- }
620
- const instance = injector.instantiate(Type);
621
- expect(instance.result).toBe(3);
622
- });
623
-
624
- it("uses the prototype of the constructor when instantiating", () => {
625
- function BaseType() {}
626
- BaseType.prototype.getValue = () => 42;
627
- function Type() {
628
- this.v = this.getValue();
629
- }
630
- Type.prototype = BaseType.prototype;
631
- const module = angular.module("myModule", []);
632
- const injector = createInjector(["myModule"]);
633
- const instance = injector.instantiate(Type);
634
- expect(instance.v).toBe(42);
635
- });
636
-
637
- it("supports locals when instantiating", () => {
638
- const module = angular.module("myModule", []);
639
- module.constant("a", 1);
640
- module.constant("b", 2);
641
- const injector = createInjector(["myModule"]);
642
- function Type(a, b) {
643
- this.result = a + b;
644
- }
645
- const instance = injector.instantiate(Type, { b: 3 });
646
- expect(instance.result).toBe(4);
647
- });
648
-
649
- it("supports es6", () => {
650
- const module = angular.module("myModule", []);
651
- module.constant("a", 1);
652
- module.constant("b", 2);
653
- const injector = createInjector(["myModule"]);
654
- class Type {
655
- constructor(a, b) {
656
- this.result = a + b;
657
- }
658
- }
659
- const instance = injector.instantiate(Type, { b: 3 });
660
- expect(instance.result).toBe(4);
661
- });
662
- });
663
-
664
- describe("provider", () => {
665
- beforeEach(() => (window.angular = new Angular()));
666
-
667
- it("allows registering a provider and uses its $get", () => {
668
- const module = angular.module("myModule", []);
669
- module.provider("a", {
670
- $get: () => {
671
- return 42;
672
- },
673
- });
674
- const injector = createInjector(["myModule"]);
675
- expect(injector.has("a")).toBe(true);
676
- expect(injector.get("a")).toBe(42);
677
- });
678
-
679
- it("injects the $get method of a provider", () => {
680
- const module = angular.module("myModule", []);
681
- module.constant("a", 1);
682
- module.provider("b", {
683
- $get: function (a) {
684
- return a + 2;
685
- },
686
- });
687
- const injector = createInjector(["myModule"]);
688
- expect(injector.get("b")).toBe(3);
689
- });
690
-
691
- it("injects the $get method of a provider lazily", () => {
692
- const module = angular.module("myModule", []);
693
- module.provider("b", {
694
- $get: (a) => {
695
- return a + 2;
696
- },
697
- });
698
- module.provider("a", { $get: () => 1 });
699
- const injector = createInjector(["myModule"]);
700
- expect(injector.get("b")).toBe(3);
701
- });
702
-
703
- it("instantiates a dependency only once", () => {
704
- const module = angular.module("myModule", []);
705
- module.provider(
706
- "a",
707
- class {
708
- $get() {
709
- return {};
710
- }
711
- },
712
- );
713
- const injector = createInjector(["myModule"]);
714
- expect(injector.get("a")).toBe(injector.get("a"));
715
- });
716
-
717
- it("should resolve dependency graph and instantiate all services just once", () => {
718
- const log = [];
719
-
720
- // s1
721
- // / | \
722
- // / s2 \
723
- // / / | \ \
724
- // /s3 < s4 > s5
725
- // //
726
- // s6
727
- angular
728
- .module("myModule", [])
729
- .provider("s1", {
730
- $get: (s6, s5) => {
731
- log.push("s1");
732
- return {};
733
- },
734
- })
735
- .provider("s2", {
736
- $get: (s3, s4, s5) => {
737
- log.push("s2");
738
- return {};
739
- },
740
- })
741
-
742
- .provider("s3", {
743
- $get: (s6) => {
744
- log.push("s3");
745
- return {};
746
- },
747
- })
748
- .provider("s4", {
749
- $get: (s3, s5) => {
750
- log.push("s4");
751
- return {};
752
- },
753
- })
754
- .provider("s5", {
755
- $get: () => {
756
- log.push("s5");
757
- return {};
758
- },
759
- })
760
- .provider("s6", {
761
- $get: () => {
762
- log.push("s6");
763
- return {};
764
- },
765
- });
766
-
767
- const injector = createInjector(["myModule"]);
768
- injector.get("s1");
769
- injector.get("s2");
770
- injector.get("s3");
771
- injector.get("s4");
772
- injector.get("s5");
773
- injector.get("s6");
774
- injector.get("s6");
775
-
776
- expect(log.length).toEqual(6);
777
- });
778
-
779
- it("should return same instance from calling provider", () => {
780
- const module = angular.module("myModule", []);
781
- let instance = "initial";
782
- const original = instance;
783
- module.provider("instance", {
784
- $get: () => {
785
- return instance;
786
- },
787
- });
788
- const injector = createInjector(["myModule"]);
789
- expect(injector.get("instance")).toEqual(instance);
790
- instance = "deleted";
791
- expect(injector.get("instance")).toEqual(original);
792
- });
793
-
794
- it("notifies the user about a circular dependency", () => {
795
- const module = angular.module("myModule", []);
796
- module.provider("a", { $get: function (b) {} });
797
- module.provider("b", { $get: function (c) {} });
798
- module.provider("c", { $get: function (a) {} });
799
- const injector = createInjector(["myModule"]);
800
- expect(() => {
801
- injector.get("a");
802
- }).toThrowError(/Circular dependency found/);
803
- });
804
-
805
- it("cleans up the circular marker when instantiation fails", () => {
806
- const module = angular.module("myModule", []);
807
- module.provider("a", {
808
- $get: () => {
809
- throw "Failing instantiation!";
810
- },
811
- });
812
- const injector = createInjector(["myModule"]);
813
- expect(() => {
814
- injector.get("a");
815
- }).toThrow("Failing instantiation!");
816
- expect(() => {
817
- injector.get("a");
818
- }).toThrow("Failing instantiation!");
819
- });
820
-
821
- it("notifies the user about a circular dependency", () => {
822
- const module = angular.module("myModule", []);
823
- module.provider("a", { $get: function (b) {} });
824
- module.provider("b", { $get: function (c) {} });
825
- module.provider("c", { $get: function (a) {} });
826
- const injector = createInjector(["myModule"]);
827
- expect(() => {
828
- injector.get("a");
829
- }).toThrowError(/Circular dependency found: a <- c <- b <- a/);
830
- });
831
-
832
- it("instantiates a provider if given as a constructor function", () => {
833
- const module = angular.module("myModule", []);
834
- module.provider("a", function AProvider() {
835
- this.$get = () => {
836
- return 42;
837
- };
838
- });
839
- const injector = createInjector(["myModule"]);
840
- expect(injector.get("a")).toBe(42);
841
- });
842
-
843
- it("injects the given provider constructor function", () => {
844
- const module = angular.module("myModule", []);
845
- module.constant("b", 2);
846
- module.provider("a", function AProvider(b) {
847
- this.$get = () => {
848
- return 1 + b;
849
- };
850
- });
851
- const injector = createInjector(["myModule"]);
852
- expect(injector.get("a")).toBe(3);
853
- });
854
-
855
- it("injects another provider to a provider constructor function", () => {
856
- const module = angular.module("myModule", []);
857
- module.provider("a", function AProvider() {
858
- let value = 1;
859
- this.setValue = function (v) {
860
- value = v;
861
- };
862
- this.$get = () => {
863
- return value;
864
- };
865
- });
866
- module.provider("b", function BProvider(aProvider) {
867
- aProvider.setValue(2);
868
- this.$get = () => {};
869
- });
870
- const injector = createInjector(["myModule"]);
871
- expect(injector.get("a")).toBe(2);
872
- });
873
-
874
- it("does not inject an instance to a provider constructor function", () => {
875
- const module = angular.module("myModule", []);
876
- module.provider("a", function AProvider() {
877
- this.$get = () => {
878
- return 1;
879
- };
880
- });
881
- module.provider("b", function BProvider(a) {
882
- this.$get = () => {
883
- return a;
884
- };
885
- });
886
- expect(() => {
887
- createInjector(["myModule"]);
888
- }).toThrow();
889
- });
890
-
891
- it("does not inject a provider to a $get function", () => {
892
- const module = angular.module("myModule", []);
893
- module.provider("a", function AProvider() {
894
- this.$get = () => {
895
- return 1;
896
- };
897
- });
898
- module.provider("b", function BProvider() {
899
- this.$get = function (aProvider) {
900
- return aProvider.$get();
901
- };
902
- });
903
- const injector = createInjector(["myModule"]);
904
- expect(() => {
905
- injector.get("b");
906
- }).toThrow();
907
- });
908
-
909
- it("does not inject a provider to invoke", () => {
910
- const module = angular.module("myModule", []);
911
- module.provider("a", function AProvider() {
912
- this.$get = () => {
913
- return 1;
914
- };
915
- });
916
- const injector = createInjector(["myModule"]);
917
- expect(() => {
918
- injector.invoke(function (aProvider) {});
919
- }).toThrow();
920
- });
921
-
922
- it("does not give access to providers through get", () => {
923
- const module = angular.module("myModule", []);
924
- module.provider("a", function AProvider() {
925
- this.$get = () => {
926
- return 1;
927
- };
928
- });
929
- const injector = createInjector(["myModule"]);
930
- expect(() => {
931
- injector.get("aProvider");
932
- }).toThrow();
933
- });
934
-
935
- it("registers constants first to make them available to providers", () => {
936
- const module = angular.module("myModule", []);
937
- module.provider("a", function AProvider(b) {
938
- this.$get = () => {
939
- return b;
940
- };
941
- });
942
- module.constant("b", 42);
943
- const injector = createInjector(["myModule"]);
944
- expect(injector.get("a")).toBe(42);
945
- });
946
-
947
- it("allows injecting the provider injector to provider", () => {
948
- const module = angular.module("myModule", []);
949
- module.provider("a", function AProvider() {
950
- this.value = 42;
951
- this.$get = () => {
952
- return this.value;
953
- };
954
- });
955
- module.provider("b", function BProvider($injector) {
956
- const aProvider = $injector.get("aProvider");
957
- this.$get = () => {
958
- return aProvider.value;
959
- };
960
- });
961
- const injector = createInjector(["myModule"]);
962
- expect(injector.get("b")).toBe(42);
963
- });
964
- });
965
-
966
- describe("$provide", () => {
967
- beforeEach(() => (window.angular = new Angular()));
968
-
969
- it("should inject providers", () => {
970
- const module = angular.module("myModule", []);
971
- module.provider("a", function () {
972
- this.$get = function () {
973
- return "Father";
974
- };
975
- });
976
-
977
- module.provider("b", function (aProvider) {
978
- this.$get = function () {
979
- return `${aProvider.$get()} child`;
980
- };
981
- });
982
- const injector = createInjector(["myModule"]);
983
- expect(injector.get("b")).toEqual("Father child");
984
- });
985
-
986
- it("allows injecting the $provide service to providers", () => {
987
- const module = angular.module("myModule", []);
988
- module.provider("a", function AProvider($provide) {
989
- $provide.constant("b", 2);
990
- this.$get = function (b) {
991
- return 1 + b;
992
- };
993
- });
994
- const injector = createInjector(["myModule"]);
995
- expect(injector.get("a")).toBe(3);
996
- });
997
-
998
- it("does not allow injecting the $provide service to $get", () => {
999
- const module = angular.module("myModule", []);
1000
- module.provider("a", function AProvider() {
1001
- this.$get = function ($provide) {};
1002
- });
1003
- const injector = createInjector(["myModule"]);
1004
- expect(() => {
1005
- injector.get("a");
1006
- }).toThrow();
1007
- });
1008
- });
1009
-
1010
- describe("config/run", () => {
1011
- beforeEach(() => (window.angular = new Angular()));
1012
-
1013
- it("runs config blocks when the injector is created", () => {
1014
- const module = angular.module("myModule", []);
1015
- let hasRun = false;
1016
- module.config(() => {
1017
- hasRun = true;
1018
- });
1019
- createInjector(["myModule"]);
1020
- expect(hasRun).toBe(true);
1021
- });
1022
-
1023
- it("injects config blocks with provider injector", () => {
1024
- const module = angular.module("myModule", []);
1025
- module.config(function ($provide) {
1026
- $provide.constant("a", 42);
1027
- });
1028
- const injector = createInjector(["myModule"]);
1029
- expect(injector.get("a")).toBe(42);
1030
- });
1031
-
1032
- it("allows registering config blocks before providers", () => {
1033
- const module = angular.module("myModule", []);
1034
- module.config(function (aProvider) {});
1035
- module.provider("a", function () {
1036
- this.$get = () => 42;
1037
- });
1038
- const injector = createInjector(["myModule"]);
1039
- expect(injector.get("a")).toBe(42);
1040
- });
1041
-
1042
- it("runs a config block added during module registration", () => {
1043
- angular.module("myModule", [], function ($provide) {
1044
- $provide.constant("a", 42);
1045
- });
1046
- const injector = createInjector(["myModule"]);
1047
- expect(injector.get("a")).toBe(42);
1048
- });
1049
-
1050
- it("runs run blocks when the injector is created", () => {
1051
- const module = angular.module("myModule", []);
1052
- let hasRun = false;
1053
- module.run(() => {
1054
- hasRun = true;
1055
- });
1056
- createInjector(["myModule"]);
1057
- expect(hasRun).toBe(true);
1058
- });
1059
-
1060
- it("injects run blocks with the instance injector", () => {
1061
- const module = angular.module("myModule", []);
1062
- module.provider("a", { $get: () => 42 });
1063
- let gotA;
1064
- module.run(function (a) {
1065
- gotA = a;
1066
- });
1067
- createInjector(["myModule"]);
1068
- expect(gotA).toBe(42);
1069
- });
1070
-
1071
- it("configures all modules before running any run blocks", () => {
1072
- const module1 = angular.module("myModule", []);
1073
- module1.provider("a", { $get: () => 1 });
1074
- let result;
1075
- module1.run((a, b) => {
1076
- result = a + b;
1077
- });
1078
- const module2 = angular.module("myOtherModule", []);
1079
- module2.provider("b", { $get: () => 2 });
1080
- createInjector(["myModule", "myOtherModule"]);
1081
- expect(result).toBe(3);
1082
- });
1083
- });
1084
-
1085
- describe("function modules", () => {
1086
- beforeEach(() => (window.angular = new Angular()));
1087
-
1088
- it("runs a function module dependency as a config block", () => {
1089
- const functionModule = ($provide) => {
1090
- $provide.constant("a", 42);
1091
- };
1092
- angular.module("myModule", [functionModule]);
1093
- const injector = createInjector(["myModule"]);
1094
- expect(injector.get("a")).toBe(42);
1095
- });
1096
-
1097
- it("runs a function module with array injection as a config block", () => {
1098
- const functionModule = [
1099
- "$provide",
1100
- function ($provide) {
1101
- $provide.constant("a", 42);
1102
- },
1103
- ];
1104
- angular.module("myModule", [functionModule]);
1105
- const injector = createInjector(["myModule"]);
1106
- expect(injector.get("a")).toBe(42);
1107
- });
1108
-
1109
- it("supports returning a run block from a function module", () => {
1110
- let result;
1111
- const functionModule = function ($provide) {
1112
- $provide.constant("a", 42);
1113
- return function (a) {
1114
- result = a;
1115
- };
1116
- };
1117
- angular.module("myModule", [functionModule]);
1118
- createInjector(["myModule"]);
1119
- expect(result).toBe(42);
1120
- });
1121
-
1122
- it("only loads function modules once", () => {
1123
- let loadedTimes = 0;
1124
- const functionModule = () => {
1125
- loadedTimes++;
1126
- };
1127
- angular.module("myModule", [functionModule, functionModule]);
1128
- createInjector(["myModule"]);
1129
- expect(loadedTimes).toBe(1);
1130
- });
1131
- });
1132
-
1133
- describe("factories", () => {
1134
- beforeEach(() => (window.angular = new Angular()));
1135
-
1136
- it("allows registering a factory", function () {
1137
- const module = angular.module("myModule", []);
1138
- module.factory("a", function () {
1139
- return 42;
1140
- });
1141
- const injector = createInjector(["myModule"]);
1142
- expect(injector.get("a")).toBe(42);
1143
- });
1144
-
1145
- it("injects a factory function with instances", function () {
1146
- const module = angular.module("myModule", []);
1147
- module.factory("a", function () {
1148
- return 1;
1149
- });
1150
- module.factory("b", function (a) {
1151
- return a + 2;
1152
- });
1153
- const injector = createInjector(["myModule"]);
1154
- expect(injector.get("b")).toBe(3);
1155
- });
1156
-
1157
- it("only calls a factory function once", function () {
1158
- const module = angular.module("myModule", []);
1159
- module.factory("a", function () {
1160
- return {};
1161
- });
1162
- const injector = createInjector(["myModule"]);
1163
- expect(injector.get("a")).toBe(injector.get("a"));
1164
- });
1165
-
1166
- it("forces a factory to return a value", function () {
1167
- const module = angular.module("myModule", []);
1168
- module.factory("a", function () {});
1169
- module.factory("b", function () {
1170
- return null;
1171
- });
1172
- const injector = createInjector(["myModule"]);
1173
- expect(function () {
1174
- injector.get("a");
1175
- }).toThrow();
1176
- expect(injector.get("b")).toBeNull();
1177
- });
1178
-
1179
- it("should be able to register a service from a new module", () => {
1180
- const injector = createInjector([]);
1181
- angular.module("a", []).factory("aService", () => ({
1182
- sayHello() {
1183
- return "Hello";
1184
- },
1185
- }));
1186
- injector.loadNewModules(["a"]);
1187
- injector.invoke((aService) => {
1188
- expect(aService.sayHello()).toEqual("Hello");
1189
- });
1190
- });
1191
- });
1192
-
1193
- describe("values", () => {
1194
- beforeEach(() => (window.angular = new Angular()));
1195
-
1196
- it("allows registering a value", function () {
1197
- const module = angular.module("myModule", []);
1198
- module.value("a", 42);
1199
- const injector = createInjector(["myModule"]);
1200
- expect(injector.get("a")).toBe(42);
1201
- });
1202
-
1203
- it("does not make values available to config blocks", function () {
1204
- const module = angular.module("myModule", []);
1205
- module.value("a", 42);
1206
- module.config(function (a) {});
1207
- expect(function () {
1208
- createInjector(["myModule"]);
1209
- }).toThrow();
1210
- });
1211
-
1212
- it("allows an undefined value", function () {
1213
- const module = angular.module("myModule", []);
1214
- module.value("a", undefined);
1215
- const injector = createInjector(["myModule"]);
1216
- expect(injector.get("a")).toBeUndefined();
1217
- });
1218
- });
1219
-
1220
- describe("services", () => {
1221
- beforeEach(() => (window.angular = new Angular()));
1222
-
1223
- it("allows registering a service", function () {
1224
- const module = angular.module("myModule", []);
1225
- module.service("aService", function MyService() {
1226
- this.getValue = function () {
1227
- return 42;
1228
- };
1229
- });
1230
- const injector = createInjector(["myModule"]);
1231
- expect(injector.get("aService").getValue()).toBe(42);
1232
- });
1233
-
1234
- it("injects service constructors with instances", function () {
1235
- const module = angular.module("myModule", []);
1236
- module.value("theValue", 42);
1237
- module.service("aService", function MyService(theValue) {
1238
- this.getValue = function () {
1239
- return theValue;
1240
- };
1241
- });
1242
- const injector = createInjector(["myModule"]);
1243
- expect(injector.get("aService").getValue()).toBe(42);
1244
- });
1245
-
1246
- it("injects service ES6 constructors with instances", function () {
1247
- const module = angular.module("myModule", []);
1248
- module.value("theValue", 42);
1249
- module.service(
1250
- "aService",
1251
- class MyService {
1252
- constructor(theValue) {
1253
- this.theValue = theValue;
1254
- }
1255
- getValue() {
1256
- return this.theValue;
1257
- }
1258
- },
1259
- );
1260
- const injector = createInjector(["myModule"]);
1261
- expect(injector.get("aService").getValue()).toBe(42);
1262
- });
1263
-
1264
- it("only instantiates services once", function () {
1265
- const module = angular.module("myModule", []);
1266
- module.service("aService", function MyService() {});
1267
- const injector = createInjector(["myModule"]);
1268
- expect(injector.get("aService")).toBe(injector.get("aService"));
1269
- });
1270
- });
1271
-
1272
- describe("decorators", () => {
1273
- beforeEach(() => (window.angular = new Angular()));
1274
-
1275
- it("allows changing an instance using a decorator", function () {
1276
- const module = angular.module("myModule", []);
1277
- module.factory("aValue", function () {
1278
- return { aKey: 42 };
1279
- });
1280
- module.decorator("aValue", function ($delegate) {
1281
- $delegate.decoratedKey = 43;
1282
- return $delegate;
1283
- });
1284
- const injector = createInjector(["myModule"]);
1285
-
1286
- expect(injector.get("aValue").aKey).toBe(42);
1287
- expect(injector.get("aValue").decoratedKey).toBe(43);
1288
- });
1289
-
1290
- it("allows multiple decorators per service", function () {
1291
- const module = angular.module("myModule", []);
1292
- module.factory("aValue", function () {
1293
- return {};
1294
- });
1295
- module.decorator("aValue", function ($delegate) {
1296
- $delegate.decoratedKey = 42;
1297
- return $delegate;
1298
- });
1299
- module.decorator("aValue", function ($delegate) {
1300
- $delegate.otherDecoratedKey = 43;
1301
- return $delegate;
1302
- });
1303
- const injector = createInjector(["myModule"]);
1304
- expect(injector.get("aValue").decoratedKey).toBe(42);
1305
- expect(injector.get("aValue").otherDecoratedKey).toBe(43);
1306
- });
1307
-
1308
- it("uses dependency injection with decorators", function () {
1309
- const module = angular.module("myModule", []);
1310
- module.factory("aValue", function () {
1311
- return {};
1312
- });
1313
- module.constant("a", 42);
1314
- module.decorator("aValue", function (a, $delegate) {
1315
- $delegate.decoratedKey = a;
1316
- return $delegate;
1317
- });
1318
- const injector = createInjector(["myModule"]);
1319
- expect(injector.get("aValue").decoratedKey).toBe(42);
1320
- });
1321
- });
1322
-
1323
- describe("controllers", () => {
1324
- beforeEach(() => (window.angular = new Angular()));
1325
-
1326
- it("should provide the caller name for controllers", () => {
1327
- window.angular
1328
- .module("myModule", [])
1329
- .controller("myCtrl", (idontexist) => {});
1330
- expect(() => {
1331
- createInjector(["myModule"]).get("$controller");
1332
- }).toThrowError(/Unknown provider/);
1333
- });
1334
-
1335
- it("should be able to register a controller from a new module", () => {
1336
- const injector = createInjector(["ng"]);
1337
- window.angular
1338
- .module("a", [])
1339
- .controller("aController", function Controller($scope) {
1340
- $scope.test = "b";
1341
- });
1342
- injector.loadNewModules(["a"]);
1343
- injector.invoke(($controller) => {
1344
- const scope = {};
1345
- $controller("aController", { $scope: scope });
1346
- expect(scope.test).toEqual("b");
1347
- });
1348
- });
1349
- });
1350
-
1351
- describe("filters", () => {
1352
- beforeEach(() => (window.angular = new Angular()));
1353
-
1354
- it("should be able to register a filter from a new module", () => {
1355
- const injector = createInjector(["ng"]);
1356
- window.angular.module("a", []).filter(
1357
- "aFilter",
1358
- () =>
1359
- function (input) {
1360
- return `${input} filtered`;
1361
- },
1362
- );
1363
- injector.loadNewModules(["a"]);
1364
- injector.invoke((aFilterFilter) => {
1365
- expect(aFilterFilter("test")).toEqual("test filtered");
1366
- });
1367
- });
1368
- });
1369
-
1370
- describe("directive", () => {
1371
- beforeEach(() => {
1372
- window.angular = new Angular();
1373
- });
1374
-
1375
- it("should be able to register a directive from a new module", () => {
1376
- const injector = createInjector(["ng"]);
1377
- window.angular
1378
- .module("a", [])
1379
- .directive("aDirective", () => ({ template: "test directive" }));
1380
- injector.loadNewModules(["a"]);
1381
- injector.invoke(($compile, $rootScope) => {
1382
- const elem = $compile("<div a-directive></div>")($rootScope); // compile and link
1383
- expect(elem.textContent).toEqual("test directive");
1384
- elem.remove();
1385
- });
1386
- });
1387
-
1388
- it("should be able to register a directive from a new module", () => {
1389
- const injector = createInjector(["ng"]);
1390
- window.angular
1391
- .module("a", [])
1392
- .directive("aDirective", () => ({ template: "test directive" }));
1393
- injector.loadNewModules(["a"]);
1394
- injector.invoke(($compile, $rootScope) => {
1395
- const elem = $compile("<div a-directive></div>")($rootScope); // compile and link
1396
- expect(elem.textContent).toEqual("test directive");
1397
- elem.remove();
1398
- });
1399
- });
1400
- });
1401
-
1402
- it("should define module", () => {
1403
- let log = "";
1404
- createInjector([
1405
- function ($provide) {
1406
- $provide.value("value", "value;");
1407
- $provide.factory("fn", () => "function;");
1408
- $provide.provider("service", function Provider() {
1409
- this.$get = () => "service;";
1410
- });
1411
- },
1412
- function (valueProvider, fnProvider, serviceProvider) {
1413
- log += valueProvider.$get() + fnProvider.$get() + serviceProvider.$get();
1414
- },
1415
- ]).invoke((value, fn, service) => {
1416
- log += `->${value}${fn}${service}`;
1417
- });
1418
- expect(log).toEqual("value;function;service;->value;function;service;");
1419
- });
1420
-
1421
- describe("module", () => {
1422
- beforeEach(() => {
1423
- window.angular = new Angular();
1424
- });
1425
-
1426
- it("should provide $injector even when no module is requested", () => {
1427
- let $provide;
1428
- const $injector = createInjector([
1429
- extend(
1430
- (p) => {
1431
- $provide = p;
1432
- },
1433
- { $inject: ["$provide"] },
1434
- ),
1435
- ]);
1436
- expect($injector.get("$injector")).toBe($injector);
1437
- });
1438
-
1439
- it("should load multiple function modules and infer inject them", () => {
1440
- let a = "junk";
1441
- const $injector = createInjector([
1442
- () => {
1443
- a = "A"; // reset to prove we ran
1444
- },
1445
- function ($provide) {
1446
- $provide.value("a", a);
1447
- },
1448
- extend(
1449
- (p, serviceA) => {
1450
- p.value("b", `${serviceA.$get()}B`);
1451
- },
1452
- { $inject: ["$provide", "aProvider"] },
1453
- ),
1454
- [
1455
- "$provide",
1456
- "bProvider",
1457
- function (p, serviceB) {
1458
- p.value("c", `${serviceB.$get()}C`);
1459
- },
1460
- ],
1461
- ]);
1462
- expect($injector.get("a")).toEqual("A");
1463
- expect($injector.get("b")).toEqual("AB");
1464
- expect($injector.get("c")).toEqual("ABC");
1465
- });
1466
-
1467
- it("should run symbolic modules", () => {
1468
- angular.module("myModule", []).value("a", "abc");
1469
- const $injector = createInjector(["myModule"]);
1470
- expect($injector.get("a")).toEqual("abc");
1471
- });
1472
-
1473
- it("should error on invalid module name", () => {
1474
- expect(() => {
1475
- createInjector(["IDontExist"], true);
1476
- }).toThrowError(/nomod/);
1477
- });
1478
-
1479
- it("should load dependant modules only once", () => {
1480
- let log = "";
1481
- angular.module("a", [], () => {
1482
- log += "a";
1483
- });
1484
- angular.module("b", ["a"], () => {
1485
- log += "b";
1486
- });
1487
- angular.module("c", ["a", "b"], () => {
1488
- log += "c";
1489
- });
1490
- createInjector(["c", "c"]);
1491
- expect(log).toEqual("abc");
1492
- });
1493
-
1494
- it("should load different instances of dependent functions", () => {
1495
- function generateValueModule(name, value) {
1496
- return function ($provide) {
1497
- $provide.value(name, value);
1498
- };
1499
- }
1500
- const injector = createInjector([
1501
- generateValueModule("name1", "value1"),
1502
- generateValueModule("name2", "value2"),
1503
- ]);
1504
- expect(injector.get("name2")).toBe("value2");
1505
- });
1506
-
1507
- it("should load same instance of dependent function only once", () => {
1508
- let count = 0;
1509
- function valueModule($provide) {
1510
- count++;
1511
- $provide.value("name", "value");
1512
- }
1513
-
1514
- const injector = createInjector([valueModule, valueModule]);
1515
- expect(injector.get("name")).toBe("value");
1516
- expect(count).toBe(1);
1517
- });
1518
-
1519
- it("should execute runBlocks after injector creation", () => {
1520
- let log = "";
1521
- angular
1522
- .module("a", [], () => {
1523
- log += "a";
1524
- })
1525
- .run(() => {
1526
- log += "A";
1527
- });
1528
- angular
1529
- .module("b", ["a"], () => {
1530
- log += "b";
1531
- })
1532
- .run(() => {
1533
- log += "B";
1534
- });
1535
- createInjector([
1536
- "b",
1537
- () => () => {
1538
- log += "C";
1539
- },
1540
- [
1541
- () => () => {
1542
- log += "D";
1543
- },
1544
- ],
1545
- ]);
1546
- expect(log).toEqual("abABCD");
1547
- });
1548
-
1549
- it("should execute own config blocks after all own providers are invoked", () => {
1550
- let log = "";
1551
- angular
1552
- .module("a", ["b"])
1553
- .config(($aProvider) => {
1554
- log += "aConfig;";
1555
- })
1556
- .provider("$a", function Provider$a() {
1557
- log += "$aProvider;";
1558
- this.$get = () => {};
1559
- });
1560
- angular
1561
- .module("b", [])
1562
- .config(($bProvider) => {
1563
- log += "bConfig;";
1564
- })
1565
- .provider("$b", function Provider$b() {
1566
- log += "$bProvider;";
1567
- this.$get = () => {};
1568
- });
1569
-
1570
- createInjector(["a"]);
1571
- expect(log).toBe("$bProvider;bConfig;$aProvider;aConfig;");
1572
- });
1573
- });
1574
-
1575
- describe("$provide", () => {
1576
- it('should throw an exception if we try to register a service called "hasOwnProperty"', () => {
1577
- createInjector([
1578
- function ($provide) {
1579
- expect(() => {
1580
- $provide.provider("hasOwnProperty", () => {});
1581
- }).toThrowError(/badname/);
1582
- },
1583
- ]);
1584
- });
1585
-
1586
- it('should throw an exception if we try to register a constant called "hasOwnProperty"', () => {
1587
- createInjector([
1588
- function ($provide) {
1589
- expect(() => {
1590
- $provide.constant("hasOwnProperty", {});
1591
- }).toThrowError(/badname/);
1592
- },
1593
- ]);
1594
- });
1595
- });
1596
-
1597
- describe("constant", () => {
1598
- it("should create configuration injectable constants", () => {
1599
- const log = [];
1600
- createInjector([
1601
- function ($provide) {
1602
- $provide.constant("abc", 123);
1603
- $provide.constant({ a: "A", b: "B" });
1604
- return function (a) {
1605
- log.push(a);
1606
- };
1607
- },
1608
- function (abc) {
1609
- log.push(abc);
1610
- return function (b) {
1611
- log.push(b);
1612
- };
1613
- },
1614
- ]).get("abc");
1615
- expect(log).toEqual([123, "A", "B"]);
1616
- });
1617
- });
1618
-
1619
- describe("value", () => {
1620
- it("should configure $provide values", () => {
1621
- expect(
1622
- createInjector([
1623
- function ($provide) {
1624
- $provide.value("value", "abc");
1625
- },
1626
- ]).get("value"),
1627
- ).toEqual("abc");
1628
- });
1629
-
1630
- it("should configure a set of values", () => {
1631
- expect(
1632
- createInjector([
1633
- function ($provide) {
1634
- $provide.value({ value: Array });
1635
- },
1636
- ]).get("value"),
1637
- ).toEqual(Array);
1638
- });
1639
- });
1640
-
1641
- describe("factory", () => {
1642
- it("should configure $provide factory function", () => {
1643
- expect(
1644
- createInjector([
1645
- function ($provide) {
1646
- $provide.factory("value", () => "abc");
1647
- },
1648
- ]).get("value"),
1649
- ).toEqual("abc");
1650
- });
1651
-
1652
- it("should configure a set of factories", () => {
1653
- expect(
1654
- createInjector([
1655
- function ($provide) {
1656
- $provide.factory({ value: Array });
1657
- },
1658
- ]).get("value"),
1659
- ).toEqual([]);
1660
- });
1661
- });
1662
-
1663
- describe("service", () => {
1664
- it("should register a class", () => {
1665
- function Type(value) {
1666
- this.value = value;
1667
- }
1668
-
1669
- const instance = createInjector([
1670
- function ($provide) {
1671
- $provide.value("value", 123);
1672
- $provide.service("foo", Type);
1673
- },
1674
- ]).get("foo");
1675
-
1676
- expect(instance instanceof Type).toBe(true);
1677
- expect(instance.value).toBe(123);
1678
- });
1679
-
1680
- it("should register a set of classes", () => {
1681
- const Type = function () {};
1682
-
1683
- const injector = createInjector([
1684
- function ($provide) {
1685
- $provide.service({
1686
- foo: Type,
1687
- bar: Type,
1688
- });
1689
- },
1690
- ]);
1691
-
1692
- expect(injector.get("foo") instanceof Type).toBe(true);
1693
- expect(injector.get("bar") instanceof Type).toBe(true);
1694
- });
1695
- });
1696
-
1697
- describe("provider", () => {
1698
- it("should configure $provide provider object", () => {
1699
- expect(
1700
- createInjector([
1701
- function ($provide) {
1702
- $provide.provider("value", {
1703
- $get: () => "abc",
1704
- });
1705
- },
1706
- ]).get("value"),
1707
- ).toEqual("abc");
1708
- });
1709
-
1710
- it("should configure $provide provider type", () => {
1711
- function Type() {}
1712
- Type.prototype.$get = function () {
1713
- expect(this instanceof Type).toBe(true);
1714
- return "abc";
1715
- };
1716
- expect(
1717
- createInjector([
1718
- function ($provide) {
1719
- $provide.provider("value", Type);
1720
- },
1721
- ]).get("value"),
1722
- ).toEqual("abc");
1723
- });
1724
-
1725
- it("should configure $provide using an array", () => {
1726
- function Type(PREFIX) {
1727
- this.prefix = PREFIX;
1728
- }
1729
- Type.prototype.$get = function () {
1730
- return `${this.prefix}def`;
1731
- };
1732
- expect(
1733
- createInjector([
1734
- function ($provide) {
1735
- $provide.constant("PREFIX", "abc");
1736
- $provide.provider("value", ["PREFIX", Type]);
1737
- },
1738
- ]).get("value"),
1739
- ).toEqual("abcdef");
1740
- });
1741
-
1742
- it("should configure a set of providers", () => {
1743
- expect(
1744
- createInjector([
1745
- function ($provide) {
1746
- $provide.provider({
1747
- value: function () {
1748
- return { $get: Array };
1749
- },
1750
- });
1751
- },
1752
- ]).get("value"),
1753
- ).toEqual([]);
1754
- });
1755
- });
1756
-
1757
- describe("decorator", () => {
1758
- let log;
1759
- let injector;
1760
-
1761
- beforeEach(() => {
1762
- log = [];
1763
- window.angular = new Angular();
1764
- });
1765
-
1766
- it("should be called with the original instance", () => {
1767
- injector = createInjector([
1768
- function ($provide) {
1769
- $provide.value("myService", (val) => {
1770
- log.push(`myService:${val}`);
1771
- return "origReturn";
1772
- });
1773
-
1774
- $provide.decorator(
1775
- "myService",
1776
- ($delegate) =>
1777
- function (val) {
1778
- log.push(`myDecoratedService:${val}`);
1779
- const origVal = $delegate("decInput");
1780
- return `dec+${origVal}`;
1781
- },
1782
- );
1783
- },
1784
- ]);
1785
-
1786
- const out = injector.get("myService")("input");
1787
- log.push(out);
1788
- expect(log.join("; ")).toBe(
1789
- "myDecoratedService:input; myService:decInput; dec+origReturn",
1790
- );
1791
- });
1792
-
1793
- it("should allow multiple decorators to be applied to a service", () => {
1794
- injector = createInjector([
1795
- function ($provide) {
1796
- $provide.value("myService", (val) => {
1797
- log.push(`myService:${val}`);
1798
- return "origReturn";
1799
- });
1800
-
1801
- $provide.decorator(
1802
- "myService",
1803
- ($delegate) =>
1804
- function (val) {
1805
- log.push(`myDecoratedService1:${val}`);
1806
- const origVal = $delegate("decInput1");
1807
- return `dec1+${origVal}`;
1808
- },
1809
- );
1810
-
1811
- $provide.decorator(
1812
- "myService",
1813
- ($delegate) =>
1814
- function (val) {
1815
- log.push(`myDecoratedService2:${val}`);
1816
- const origVal = $delegate("decInput2");
1817
- return `dec2+${origVal}`;
1818
- },
1819
- );
1820
- },
1821
- ]);
1822
-
1823
- const out = injector.get("myService")("input");
1824
- log.push(out);
1825
- expect(log).toEqual([
1826
- "myDecoratedService2:input",
1827
- "myDecoratedService1:decInput2",
1828
- "myService:decInput1",
1829
- "dec2+dec1+origReturn",
1830
- ]);
1831
- });
1832
-
1833
- it("should decorate services with dependencies", () => {
1834
- injector = createInjector([
1835
- function ($provide) {
1836
- $provide.value("dep1", "dependency1");
1837
-
1838
- $provide.factory("myService", [
1839
- "dep1",
1840
- function (dep1) {
1841
- return function (val) {
1842
- log.push(`myService:${val},${dep1}`);
1843
- return "origReturn";
1844
- };
1845
- },
1846
- ]);
1847
-
1848
- $provide.decorator(
1849
- "myService",
1850
- ($delegate) =>
1851
- function (val) {
1852
- log.push(`myDecoratedService:${val}`);
1853
- const origVal = $delegate("decInput");
1854
- return `dec+${origVal}`;
1855
- },
1856
- );
1857
- },
1858
- ]);
1859
-
1860
- const out = injector.get("myService")("input");
1861
- log.push(out);
1862
- expect(log.join("; ")).toBe(
1863
- "myDecoratedService:input; myService:decInput,dependency1; dec+origReturn",
1864
- );
1865
- });
1866
-
1867
- it("should allow for decorators to be injectable", () => {
1868
- injector = createInjector([
1869
- function ($provide) {
1870
- $provide.value("dep1", "dependency1");
1871
-
1872
- $provide.factory(
1873
- "myService",
1874
- () =>
1875
- function (val) {
1876
- log.push(`myService:${val}`);
1877
- return "origReturn";
1878
- },
1879
- );
1880
-
1881
- $provide.decorator(
1882
- "myService",
1883
- ($delegate, dep1) =>
1884
- function (val) {
1885
- log.push(`myDecoratedService:${val},${dep1}`);
1886
- const origVal = $delegate("decInput");
1887
- return `dec+${origVal}`;
1888
- },
1889
- );
1890
- },
1891
- ]);
1892
-
1893
- const out = injector.get("myService")("input");
1894
- log.push(out);
1895
- expect(log.join("; ")).toBe(
1896
- "myDecoratedService:input,dependency1; myService:decInput; dec+origReturn",
1897
- );
1898
- });
1899
-
1900
- it("should allow for decorators to $injector", function () {
1901
- injector = createInjector([
1902
- "ng",
1903
- function ($provide) {
1904
- $provide.decorator("$injector", function ($delegate) {
1905
- // Don't forget the prototype
1906
- return extend(Object.create($delegate), $delegate, {
1907
- get: function (val) {
1908
- if (val === "key") {
1909
- return "value";
1910
- }
1911
- return $delegate.get(val);
1912
- },
1913
- });
1914
- });
1915
- },
1916
- ]);
1917
- expect(injector.get("key")).toBe("value");
1918
- expect(injector.get("$http")).not.toBeUndefined();
1919
- });
1920
- });
1921
-
1922
- describe("error handling", () => {
1923
- it("should handle wrong argument type", () => {
1924
- expect(() => {
1925
- createInjector([{}], true);
1926
- }).toThrowError(
1927
- /Failed to instantiate module \{\} due to:\n.*\[ng:areq] Argument 'module' is not a function, got Object/,
1928
- );
1929
- });
1930
-
1931
- it("should handle exceptions", () => {
1932
- expect(function () {
1933
- createInjector(
1934
- [
1935
- function () {
1936
- throw new Error("MyError");
1937
- },
1938
- ],
1939
- true,
1940
- );
1941
- }).toThrowError(/Failed to instantiate module/);
1942
- });
1943
-
1944
- it("should decorate the missing service error with module name", () => {
1945
- angular.module("TestModule", [], (xyzzy) => {});
1946
- expect(() => {
1947
- createInjector(["TestModule"]);
1948
- }).toThrowError(
1949
- /Failed to instantiate module TestModule due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/,
1950
- );
1951
- });
1952
-
1953
- it("should decorate the missing service error with module function", () => {
1954
- function myModule(xyzzy) {}
1955
- expect(() => {
1956
- createInjector([myModule]);
1957
- }).toThrowError(
1958
- /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/,
1959
- );
1960
- });
1961
-
1962
- it("should decorate the missing service error with module array function", () => {
1963
- function myModule(xyzzy) {}
1964
- expect(() => {
1965
- createInjector([["xyzzy", myModule]]);
1966
- }).toThrowError(
1967
- /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/,
1968
- );
1969
- });
1970
-
1971
- it("should throw error when trying to inject oneself", () => {
1972
- expect(() => {
1973
- createInjector([
1974
- function ($provide) {
1975
- $provide.factory("service", (service) => {});
1976
- return function (service) {};
1977
- },
1978
- ]);
1979
- }).toThrowError(/Circular dependency found: service <- service/);
1980
- });
1981
-
1982
- it("should throw error when trying to inject circular dependency", () => {
1983
- expect(() => {
1984
- createInjector([
1985
- function ($provide) {
1986
- $provide.factory("a", (b) => {});
1987
- $provide.factory("b", (a) => {});
1988
- return function (a) {};
1989
- },
1990
- ]);
1991
- }).toThrowError(/Circular dependency found: a <- b <- a/);
1992
- });
1993
- });
1994
-
1995
- describe("retrieval", () => {
1996
- const instance = { name: "angular" };
1997
- function Instance() {
1998
- this.name = "loader";
1999
- }
2000
-
2001
- function createInjectorWithValue(instanceName, instance) {
2002
- return createInjector([
2003
- [
2004
- "$provide",
2005
- function (provide) {
2006
- provide.value(instanceName, instance);
2007
- },
2008
- ],
2009
- ]);
2010
- }
2011
- function createInjectorWithFactory(serviceName, serviceDef) {
2012
- return createInjector([
2013
- [
2014
- "$provide",
2015
- function (provide) {
2016
- provide.factory(serviceName, serviceDef);
2017
- },
2018
- ],
2019
- ]);
2020
- }
2021
-
2022
- it("should retrieve by name", () => {
2023
- const $injector = createInjectorWithValue("instance", instance);
2024
- const retrievedInstance = $injector.get("instance");
2025
- expect(retrievedInstance).toBe(instance);
2026
- });
2027
-
2028
- it("should cache instance", () => {
2029
- const $injector = createInjectorWithFactory(
2030
- "instance",
2031
- () => new Instance(),
2032
- );
2033
- const instance = $injector.get("instance");
2034
- expect($injector.get("instance")).toBe(instance);
2035
- expect($injector.get("instance")).toBe(instance);
2036
- });
2037
-
2038
- it("should call functions and infer arguments", () => {
2039
- const $injector = createInjectorWithValue("instance", instance);
2040
- expect($injector.invoke((instance) => instance)).toBe(instance);
2041
- });
2042
- });
2043
-
2044
- describe("method invoking", () => {
2045
- let $injector;
2046
-
2047
- beforeEach(() => {
2048
- $injector = createInjector([
2049
- function ($provide) {
2050
- $provide.value("book", "moby");
2051
- $provide.value("author", "melville");
2052
- },
2053
- ]);
2054
- });
2055
-
2056
- it("should invoke method", () => {
2057
- expect($injector.invoke((book, author) => `${author}:${book}`)).toEqual(
2058
- "melville:moby",
2059
- );
2060
- expect(
2061
- $injector.invoke(function (book, author) {
2062
- expect(this).toEqual($injector);
2063
- return `${author}:${book}`;
2064
- }, $injector),
2065
- ).toEqual("melville:moby");
2066
- });
2067
-
2068
- it("should invoke method with locals", () => {
2069
- expect($injector.invoke((book, author) => `${author}:${book}`)).toEqual(
2070
- "melville:moby",
2071
- );
2072
- expect(
2073
- $injector.invoke(
2074
- function (book, author, chapter) {
2075
- expect(this).toEqual($injector);
2076
- return `${author}:${book}-${chapter}`;
2077
- },
2078
- $injector,
2079
- { author: "m", chapter: "ch1" },
2080
- ),
2081
- ).toEqual("m:moby-ch1");
2082
- });
2083
-
2084
- it("should invoke method which is annotated", () => {
2085
- expect(
2086
- $injector.invoke(
2087
- extend((b, a) => `${a}:${b}`, { $inject: ["book", "author"] }),
2088
- ),
2089
- ).toEqual("melville:moby");
2090
- expect(
2091
- $injector.invoke(
2092
- extend(
2093
- function (b, a) {
2094
- expect(this).toEqual($injector);
2095
- return `${a}:${b}`;
2096
- },
2097
- { $inject: ["book", "author"] },
2098
- ),
2099
- $injector,
2100
- ),
2101
- ).toEqual("melville:moby");
2102
- });
2103
-
2104
- it("should invoke method which is an array of annotation", () => {
2105
- expect($injector.invoke((book, author) => `${author}:${book}`)).toEqual(
2106
- "melville:moby",
2107
- );
2108
- expect(
2109
- $injector.invoke(function (book, author) {
2110
- expect(this).toEqual($injector);
2111
- return `${author}:${book}`;
2112
- }, $injector),
2113
- ).toEqual("melville:moby");
2114
- });
2115
-
2116
- it("should throw useful error on wrong argument type]", () => {
2117
- expect(() => {
2118
- $injector.invoke({});
2119
- }).toThrowError(/Argument 'fn' is not a function, got Object/);
2120
- });
2121
- });
2122
-
2123
- describe("service instantiation", () => {
2124
- let $injector;
2125
-
2126
- beforeEach(() => {
2127
- $injector = createInjector([
2128
- function ($provide) {
2129
- $provide.value("book", "moby");
2130
- $provide.value("author", "melville");
2131
- },
2132
- ]);
2133
- });
2134
-
2135
- function Type(book, author) {
2136
- this.book = book;
2137
- this.author = author;
2138
- }
2139
- Type.prototype.title = function () {
2140
- return this.author + ": " + this.book;
2141
- };
2142
-
2143
- it("should instantiate object and preserve constructor property and be instanceof", () => {
2144
- const t = $injector.instantiate(Type);
2145
- expect(t.book).toEqual("moby");
2146
- expect(t.author).toEqual("melville");
2147
- expect(t.title()).toEqual("melville: moby");
2148
- expect(t instanceof Type).toBe(true);
2149
- });
2150
-
2151
- it(
2152
- "should instantiate object and preserve constructor property and be instanceof " +
2153
- "with the array annotated type",
2154
- () => {
2155
- const t = $injector.instantiate(["book", "author", Type]);
2156
- expect(t.book).toEqual("moby");
2157
- expect(t.author).toEqual("melville");
2158
- expect(t.title()).toEqual("melville: moby");
2159
- expect(t instanceof Type).toBe(true);
2160
- },
2161
- );
2162
-
2163
- it("should allow constructor to return different object", () => {
2164
- const obj = {};
2165
- const Class = function () {
2166
- return obj;
2167
- };
2168
-
2169
- expect($injector.instantiate(Class)).toBe(obj);
2170
- });
2171
-
2172
- it("should allow constructor to return a function", () => {
2173
- const fn = function () {};
2174
- const Class = function () {
2175
- return fn;
2176
- };
2177
-
2178
- expect($injector.instantiate(Class)).toBe(fn);
2179
- });
2180
-
2181
- it("should handle constructor exception", () => {
2182
- expect(function () {
2183
- $injector.instantiate(function () {
2184
- throw "MyError";
2185
- });
2186
- }).toThrow("MyError");
2187
- });
2188
-
2189
- it("should return instance if constructor returns non-object value", () => {
2190
- const A = function () {
2191
- return 10;
2192
- };
2193
-
2194
- const B = function () {
2195
- return "some-string";
2196
- };
2197
-
2198
- const C = function () {
2199
- return undefined;
2200
- };
2201
-
2202
- expect($injector.instantiate(A) instanceof A).toBe(true);
2203
- expect($injector.instantiate(B) instanceof B).toBe(true);
2204
- expect($injector.instantiate(C) instanceof C).toBe(true);
2205
- });
2206
- });
2207
-
2208
- describe("protection modes", () => {
2209
- it("should prevent provider lookup in app", () => {
2210
- const $injector = createInjector([
2211
- function ($provide) {
2212
- $provide.value("name", "angular");
2213
- },
2214
- ]);
2215
- expect(() => {
2216
- $injector.get("nameProvider");
2217
- }).toThrowError(/Unknown provider/);
2218
- });
2219
-
2220
- it("should prevent provider configuration in app", () => {
2221
- const $injector = createInjector([]);
2222
- expect(() => {
2223
- $injector.get("$provide").value("a", "b");
2224
- }).toThrowError(/Unknown provider/);
2225
- });
2226
-
2227
- it("should prevent instance lookup in module", () => {
2228
- function instanceLookupInModule(name) {}
2229
- expect(() => {
2230
- createInjector([
2231
- function ($provide) {
2232
- $provide.value("name", "angular");
2233
- },
2234
- instanceLookupInModule,
2235
- ]);
2236
- }).toThrowError(/Unknown provider: name/);
2237
- });
2238
- });
2239
-
2240
- describe("strict-di injector", () => {
2241
- let module;
2242
- let $injector;
2243
- beforeEach(() => {
2244
- window.angular = new Angular();
2245
- module = angular.module("test1", []);
2246
- $injector = createInjector(["test1"], true);
2247
- });
2248
-
2249
- it("should throw if magic annotation is used by service", () => {
2250
- module.provider(($provide) => {
2251
- $provide.service({
2252
- $test: () => {
2253
- return this;
2254
- },
2255
- $test2: function ($test) {
2256
- return this;
2257
- },
2258
- });
2259
- });
2260
- expect(() => {
2261
- $injector.invoke(($test2) => {});
2262
- }).toThrowError(/strictdi/);
2263
- });
2264
-
2265
- it("should throw if magic annotation is used by provider", () => {
2266
- module.provider(($provide) => {
2267
- $provide.provider({
2268
- $test: () => {
2269
- this.$get = function ($rootScope) {
2270
- return $rootScope;
2271
- };
2272
- },
2273
- });
2274
- });
2275
- expect(() => {
2276
- $injector.invoke(function ($test) {});
2277
- }).toThrowError(/strictdi/);
2278
- });
2279
-
2280
- it("should throw if magic annotation is used by factory", () => {
2281
- module.provider(($provide) => {
2282
- $provide.factory({
2283
- $test: function ($rootScope) {
2284
- return function () {};
2285
- },
2286
- });
2287
- });
2288
- expect(() => {
2289
- $injector.invoke(function (test) {});
2290
- }).toThrowError(/strictdi/);
2291
- });
2292
-
2293
- it("should throw if factory does not return a value", () => {
2294
- module.provider(($provide) => {
2295
- $provide.factory("$test", () => {});
2296
- });
2297
- expect(() => {
2298
- $injector.invoke("$test");
2299
- }).toThrowError(/is not a function/);
2300
- });
2301
-
2302
- it("should set strictDi property on the injector instance", () => {
2303
- angular.module("test1", []);
2304
- let $injector = createInjector(["test1"], true);
2305
- expect($injector.strictDi).toBe(true);
2306
-
2307
- $injector = createInjector(["test1"]);
2308
- expect($injector.strictDi).toBe(false);
2309
- });
2310
- });