@anglr/datetime 9.0.2 → 9.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/angular-developer/SKILL.md +130 -0
- package/.claude/skills/angular-developer/references/angular-animations.md +160 -0
- package/.claude/skills/angular-developer/references/angular-aria.md +410 -0
- package/.claude/skills/angular-developer/references/cli.md +86 -0
- package/.claude/skills/angular-developer/references/component-harnesses.md +59 -0
- package/.claude/skills/angular-developer/references/component-styling.md +91 -0
- package/.claude/skills/angular-developer/references/components.md +117 -0
- package/.claude/skills/angular-developer/references/creating-services.md +97 -0
- package/.claude/skills/angular-developer/references/data-resolvers.md +69 -0
- package/.claude/skills/angular-developer/references/define-routes.md +67 -0
- package/.claude/skills/angular-developer/references/defining-providers.md +72 -0
- package/.claude/skills/angular-developer/references/di-fundamentals.md +120 -0
- package/.claude/skills/angular-developer/references/e2e-testing.md +66 -0
- package/.claude/skills/angular-developer/references/effects.md +83 -0
- package/.claude/skills/angular-developer/references/hierarchical-injectors.md +43 -0
- package/.claude/skills/angular-developer/references/host-elements.md +80 -0
- package/.claude/skills/angular-developer/references/injection-context.md +63 -0
- package/.claude/skills/angular-developer/references/inputs.md +101 -0
- package/.claude/skills/angular-developer/references/linked-signal.md +59 -0
- package/.claude/skills/angular-developer/references/loading-strategies.md +61 -0
- package/.claude/skills/angular-developer/references/mcp.md +106 -0
- package/.claude/skills/angular-developer/references/migrations.md +30 -0
- package/.claude/skills/angular-developer/references/navigate-to-routes.md +69 -0
- package/.claude/skills/angular-developer/references/outputs.md +86 -0
- package/.claude/skills/angular-developer/references/reactive-forms.md +122 -0
- package/.claude/skills/angular-developer/references/rendering-strategies.md +44 -0
- package/.claude/skills/angular-developer/references/resource.md +77 -0
- package/.claude/skills/angular-developer/references/route-animations.md +56 -0
- package/.claude/skills/angular-developer/references/route-guards.md +52 -0
- package/.claude/skills/angular-developer/references/router-lifecycle.md +45 -0
- package/.claude/skills/angular-developer/references/router-testing.md +87 -0
- package/.claude/skills/angular-developer/references/show-routes-with-outlets.md +68 -0
- package/.claude/skills/angular-developer/references/signal-forms.md +897 -0
- package/.claude/skills/angular-developer/references/signals-overview.md +94 -0
- package/.claude/skills/angular-developer/references/tailwind-css.md +69 -0
- package/.claude/skills/angular-developer/references/template-driven-forms.md +114 -0
- package/.claude/skills/angular-developer/references/testing-fundamentals.md +66 -0
- package/.github/instructions/typescript/code-conventions.md +8 -0
- package/.github/instructions/typescript/comments.md +41 -0
- package/.github/instructions/typescript/formatting.md +43 -0
- package/.github/instructions/typescript/naming-conventions.md +7 -0
- package/.github/instructions/typescript.instructions.md +26 -0
- package/changelog.md +6 -0
- package/es2022/src/services/dateValueProvider/dateValueProvider.service.js +1 -1
- package/es2022/src/services/dateValueProvider/dateValueProvider.service.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +1453 -4
- package/version.bak +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Testing with the RouterTestingHarness
|
|
2
|
+
|
|
3
|
+
When testing components that involve routing, it is crucial **not to mock the Router or related services**. Instead, use the `RouterTestingHarness`, which provides a robust and reliable way to test routing logic in an environment that closely mirrors a real application.
|
|
4
|
+
|
|
5
|
+
Using the harness ensures you are testing the actual router configuration, guards, and resolvers, leading to more meaningful tests.
|
|
6
|
+
|
|
7
|
+
## Setting Up for Router Testing
|
|
8
|
+
|
|
9
|
+
The `RouterTestingHarness` is the primary tool for testing routing scenarios. You also need to provide your test routes using the `provideRouter` function in your `TestBed` configuration.
|
|
10
|
+
|
|
11
|
+
### Example Setup
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {TestBed} from '@angular/core/testing';
|
|
15
|
+
import {provideRouter} from '@angular/router';
|
|
16
|
+
import {RouterTestingHarness} from '@angular/router/testing';
|
|
17
|
+
import {Dashboard} from './dashboard.component';
|
|
18
|
+
import {HeroDetail} from './hero-detail.component';
|
|
19
|
+
|
|
20
|
+
describe('Dashboard Component Routing', () => {
|
|
21
|
+
let harness: RouterTestingHarness;
|
|
22
|
+
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
// 1. Configure TestBed with test routes
|
|
25
|
+
await TestBed.configureTestingModule({
|
|
26
|
+
providers: [
|
|
27
|
+
// Use provideRouter with your test-specific routes
|
|
28
|
+
provideRouter([
|
|
29
|
+
{path: '', component: Dashboard},
|
|
30
|
+
{path: 'heroes/:id', component: HeroDetail},
|
|
31
|
+
]),
|
|
32
|
+
],
|
|
33
|
+
}).compileComponents();
|
|
34
|
+
|
|
35
|
+
// 2. Create the RouterTestingHarness
|
|
36
|
+
harness = await RouterTestingHarness.create();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Key Concepts
|
|
42
|
+
|
|
43
|
+
1. **`provideRouter([...])`**: Provide a test-specific routing configuration. This should include the routes necessary for the component-under-test to function correctly.
|
|
44
|
+
2. **`RouterTestingHarness.create()`**: Asynchronously creates and initializes the harness and performs an initial navigation to the root URL (`/`).
|
|
45
|
+
|
|
46
|
+
## Writing Router Tests
|
|
47
|
+
|
|
48
|
+
Once the harness is created, you can use it to drive navigation and make assertions on the state of the router and the activated components.
|
|
49
|
+
|
|
50
|
+
### Example: Testing Navigation
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
it('should navigate to a hero detail when a hero is selected', async () => {
|
|
54
|
+
// 1. Navigate to the initial component and get its instance
|
|
55
|
+
const dashboard = await harness.navigateByUrl('/', Dashboard);
|
|
56
|
+
|
|
57
|
+
// Suppose the dashboard has a method to select a hero
|
|
58
|
+
const heroToSelect = {id: 42, name: 'Test Hero'};
|
|
59
|
+
dashboard.selectHero(heroToSelect);
|
|
60
|
+
|
|
61
|
+
// Wait for stability after the action that triggers navigation
|
|
62
|
+
await harness.fixture.whenStable();
|
|
63
|
+
|
|
64
|
+
// 2. Assert on the URL
|
|
65
|
+
expect(harness.router.url).toEqual('/heroes/42');
|
|
66
|
+
|
|
67
|
+
// 3. Get the activated component after navigation
|
|
68
|
+
const heroDetail = await harness.getHarness(HeroDetail);
|
|
69
|
+
|
|
70
|
+
// 4. Assert on the state of the new component
|
|
71
|
+
expect(await heroDetail.componentInstance.hero.name).toBe('Test Hero');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should get the activated component directly', async () => {
|
|
75
|
+
// Navigate and get the component instance in one step
|
|
76
|
+
const dashboardInstance = await harness.navigateByUrl('/', Dashboard);
|
|
77
|
+
|
|
78
|
+
expect(dashboardInstance).toBeInstanceOf(Dashboard);
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Best Practices
|
|
83
|
+
|
|
84
|
+
- **Navigate with the Harness:** Always use `harness.navigateByUrl()` to simulate navigation. This method returns a promise that resolves with the instance of the activated component.
|
|
85
|
+
- **Access the Router State:** Use `harness.router` to access the live router instance and assert on its state (e.g., `harness.router.url`).
|
|
86
|
+
- **Get Activated Components:** Use `harness.getHarness(ComponentType)` to get an instance of a component harness for the currently activated routed component, or `harness.routeDebugElement` to get the `DebugElement`.
|
|
87
|
+
- **Wait for Stability:** After performing an action that causes navigation, always `await harness.fixture.whenStable()` to ensure the routing is complete before making assertions.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Show Routes with Outlets
|
|
2
|
+
|
|
3
|
+
The `RouterOutlet` directive is a placeholder where Angular renders the component for the current URL.
|
|
4
|
+
|
|
5
|
+
## Basic Usage
|
|
6
|
+
|
|
7
|
+
Include `<router-outlet />` in your template. Angular inserts the routed component as a sibling immediately following the outlet.
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<app-header /> <router-outlet />
|
|
11
|
+
<!-- Route content appears here -->
|
|
12
|
+
<app-footer />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Nested Outlets
|
|
16
|
+
|
|
17
|
+
Child routes require their own `<router-outlet />` within the parent component's template.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// Parent component template
|
|
21
|
+
<h1>Settings</h1>
|
|
22
|
+
<router-outlet /> <!-- Child components like Profile or Security render here -->
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Named Outlets (Secondary Routes)
|
|
26
|
+
|
|
27
|
+
Pages can have multiple outlets. Assign a `name` to an outlet to target it specifically. The default name is `'primary'`.
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<router-outlet />
|
|
31
|
+
<!-- Primary -->
|
|
32
|
+
<router-outlet name="sidebar" />
|
|
33
|
+
<!-- Secondary -->
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Define the `outlet` in the route config:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
{
|
|
40
|
+
path: 'chat',
|
|
41
|
+
component: Chat,
|
|
42
|
+
outlet: 'sidebar'
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Outlet Lifecycle Events
|
|
47
|
+
|
|
48
|
+
`RouterOutlet` emits events when components are changed:
|
|
49
|
+
|
|
50
|
+
- `activate`: New component instantiated.
|
|
51
|
+
- `deactivate`: Component destroyed.
|
|
52
|
+
- `attach` / `detach`: Used with `RouteReuseStrategy`.
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<router-outlet (activate)="onActivate($event)" />
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Passing Data via `routerOutletData`
|
|
59
|
+
|
|
60
|
+
You can pass contextual data to the routed component using the `routerOutletData` input. The component accesses this via the `ROUTER_OUTLET_DATA` injection token as a signal.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// In Parent
|
|
64
|
+
<router-outlet [routerOutletData]="{ theme: 'dark' }" />
|
|
65
|
+
|
|
66
|
+
// In Routed Component
|
|
67
|
+
outletData = inject(ROUTER_OUTLET_DATA) as Signal<{ theme: string }>;
|
|
68
|
+
```
|