Title: Schematics: Unit testing a rule that uses mergeWith/apply fails due to missing context · Issue #17205 · angular/angular-cli · GitHub
Open Graph Title: Schematics: Unit testing a rule that uses mergeWith/apply fails due to missing context · Issue #17205 · angular/angular-cli
X Title: Schematics: Unit testing a rule that uses mergeWith/apply fails due to missing context · Issue #17205 · angular/angular-cli
Description: Addendum In creating the test case I've realised that I'm not passing a partialContext to callRule, so it is definitely missing context, however, it is not at all clear what context is necessary for mergeWith to succeed and the error doe...
Open Graph Description: Addendum In creating the test case I've realised that I'm not passing a partialContext to callRule, so it is definitely missing context, however, it is not at all clear what context is necessary fo...
X Description: Addendum In creating the test case I've realised that I'm not passing a partialContext to callRule, so it is definitely missing context, however, it is not at all clear what context is nece...
Opengraph URL: https://github.com/angular/angular-cli/issues/17205
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Schematics: Unit testing a rule that uses mergeWith/apply fails due to missing context","articleBody":"## Addendum\r\n\r\nIn creating the test case I've realised that I'm not passing a `partialContext` to `callRule`, so it is definitely missing context, however, it is not at all clear _what_ context is necessary for `mergeWith` to succeed and the error does not indicate that context is actually missing.\r\n\r\nHappy for this to be marked as a question instead. Guidance on _how_ to provide the context and _what_ context to provide would be amazingly useful.\r\n\r\n# 🐞 Bug report\r\n\r\n### Description\r\n\r\nUsing `callRule` to unit test rules within a schematic fails when it comes to rules which return `mergeWith`\r\n\r\n## 🔬 Minimal Reproduction\r\n\r\nSee: https://github.com/jdpearce/schematics-apply-problem\r\n\r\nGiven a rule which applies template files to the tree, this unit test will fail with `TypeError: Cannot read property 'path' of undefined`:\r\n\r\n```ts\r\ndescribe('applyTemplateFiles Rule', () =\u003e {\r\n let tree: UnitTestTree;\r\n\r\n beforeEach(async () =\u003e {\r\n tree = new UnitTestTree(Tree.empty());\r\n });\r\n\r\n it('should apply the files to the tree', async () =\u003e {\r\n const schema = {};\r\n\r\n tree = (await callRule(applyTemplateFiles(schema), tree)) as UnitTestTree;\r\n\r\n expect(tree.files).toEqual(jasmine.arrayContaining(['/libs/destination/test.txt']));\r\n });\r\n});\r\n```\r\n\r\n## 🔥 Exception or Error\r\n\r\n```bash\r\nFailures:\r\n1) applyTemplateFiles Rule should apply the files to the tree\r\n Message:\r\n TypeError: Cannot read property 'path' of undefined\r\n Stack:\r\n at \u003cJasmine\u003e\r\n at ./apply-problem/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:216:96\r\n at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/url.js:13:73\r\n at Object.callSource (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:55:20)\r\n at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/base.js:45:60\r\n at Object.callSource (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:55:20)\r\n at ./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/base.js:53:23\r\n at MergeMapSubscriber.project (./tmp/apply-problem/node_modules/@angular-devkit/schematics/src/rules/call.js:74:24)\r\n at MergeMapSubscriber._tryNext (./tmp/apply-problem/node_modules/rxjs/internal/operators/mergeMap.js:69:27)\r\n at MergeMapSubscriber._next (./tmp/apply-problem/node_modules/rxjs/internal/operators/mergeMap.js:59:18)\r\n at MergeMapSubscriber.Subscriber.next (./tmp/apply-problem/node_modules/rxjs/internal/Subscriber.js:66:18)\r\n\r\n2 specs, 1 failure\r\n```\r\n\r\n## 🌍 Your Environment\r\n\r\n \"@angular-devkit/core\": \"^9.0.6\",\r\n \"@angular-devkit/schematics\": \"^9.0.6\",\r\n \"@types/jasmine\": \"^3.3.9\",\r\n \"@types/node\": \"^8.0.31\",\r\n \"jasmine\": \"^3.3.1\",\r\n \"typescript\": \"~3.5.3\"\r\n","author":{"url":"https://github.com/catfireparty","@type":"Person","name":"catfireparty"},"datePublished":"2020-03-12T12:00:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/17205/angular-cli/issues/17205"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4ead09aa-7f37-72ad-1214-2057e5bfe3da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D502:3CDF6F:1A7DA0E:243FF2B:6964C027 |
| html-safe-nonce | 3aa945518585b8273bc88d9838a54fbf00b18e67f656ab0257e8cef26c26a8b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTAyOjNDREY2RjoxQTdEQTBFOjI0M0ZGMkI6Njk2NEMwMjciLCJ2aXNpdG9yX2lkIjoiMjM0OTUzNjIxMTUwMDMxODc2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3e3dfae85b8a86c93a7f34290e3f40e9515d30eee03ced14370ebe251280e5b3 |
| hovercard-subject-tag | issue:579889600 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/17205/issue_layout |
| twitter:image | https://opengraph.githubassets.com/50439b2ce8009e99f0492f7dbdce7d9576bb9ab9d96e39bb8440eef0a2a60676/angular/angular-cli/issues/17205 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/50439b2ce8009e99f0492f7dbdce7d9576bb9ab9d96e39bb8440eef0a2a60676/angular/angular-cli/issues/17205 |
| og:image:alt | Addendum In creating the test case I've realised that I'm not passing a partialContext to callRule, so it is definitely missing context, however, it is not at all clear what context is necessary fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | catfireparty |
| hostname | github.com |
| expected-hostname | github.com |
| None | 21df671ce2c9f1a16940ccbd3af6cb4f3f12a856929ca7eb1b4aea8e384ea442 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5707c685ac172d50a0bdd7533dde4f8aabcf8eef |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width