angular-cn/packages/language-service/ivy/test
Keen Yee Liau 4985267211 test(language-service): [Ivy] return cursor position in overwritten template (#38552)
In many testing scenarios, there is a common pattern:

1. Overwrite template (inline or external)
2. Find cursor position
3. Call one of language service APIs
4. Inspect spans in result

In order to faciliate this pattern, this commit refactors
`MockHost.overwrite()` and `MockHost.overwriteInlineTemplate()` to
allow a faux cursor symbol `¦` to be injected into the template, and
the methods will automatically remove it before updating the script snapshot.
Both methods will return the cursor position and the new text without
the cursor symbol.

This makes testing very convenient. Here's a typical example:

```ts
const {position, text} = mockHost.overwrite('template.html', `{{ ti¦tle }}`);
const quickInfo = ngLS.getQuickInfoAtPosition('template.html', position);
const {start, length} = quickInfo!.textSpan;
expect(text.substring(start, start + length)).toBe('title');
```

PR Close #38552
2020-08-24 09:25:04 -07:00
..
BUILD.bazel feat(language-service): introduce hybrid visitor to locate AST node (#38540) 2020-08-24 09:24:18 -07:00
diagnostic_spec.ts test(language-service): [Ivy] return cursor position in overwritten template (#38552) 2020-08-24 09:25:04 -07:00
hybrid_visitor_spec.ts feat(language-service): introduce hybrid visitor to locate AST node (#38540) 2020-08-24 09:24:18 -07:00
language_service_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
mock_host.ts test(language-service): [Ivy] return cursor position in overwritten template (#38552) 2020-08-24 09:25:04 -07:00
mock_host_spec.ts test(language-service): [Ivy] return cursor position in overwritten template (#38552) 2020-08-24 09:25:04 -07:00