Skip to content

Commit

Permalink
test: update example apps with extra tests for downlevel constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Jul 31, 2024
1 parent 275f060 commit 62c68f0
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Component } from '@angular/core';
import { Component, Inject, InjectionToken } from '@angular/core';
import { TestBed, waitForAsync } from '@angular/core/testing';

interface ServerError {
title: string;
errors: Map<string, string[]>;
}

const DATA_TOKEN = new InjectionToken<ServerError>('DataToken');

@Component({
selector: 'bar',
templateUrl: './bar.component.html',
Expand All @@ -14,11 +21,19 @@ import { TestBed, waitForAsync } from '@angular/core/testing';
`,
],
})
class BarComponent {}
class BarComponent {
constructor(@Inject(DATA_TOKEN) public data: ServerError) {}
}

test('templateUrl/styleUrls/styles should work', waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [BarComponent],
providers: [
{
provide: DATA_TOKEN,
useValue: {},
},
],
});
const fixture = TestBed.createComponent(BarComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { REQUEST } from '@shared/app.tokens';

import { FooComponent } from './foo.component';
import { FOO_COMPONENT_DATA_TOKEN, FooComponent } from './foo.component';

describe('FooComponent', () => {
let fixture: ComponentFixture<FooComponent>;
Expand All @@ -13,6 +13,13 @@ describe('FooComponent', () => {
provide: REQUEST,
useValue: {},
},
{
provide: FOO_COMPONENT_DATA_TOKEN,
useValue: {
title: '',
error: new Map(),
},
},
],
}).createComponent(FooComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component, inject } from '@angular/core';
import { Component, Inject, inject, InjectionToken } from '@angular/core';
import { Services } from '@shared/shared';

export interface ServerError {
title: string;
errors: Map<string, string[]>;
}

export const FOO_COMPONENT_DATA_TOKEN = new InjectionToken<ServerError>('FooComponentData');

@Component({
template: ` <h1>Foo</h1> `,
standalone: true,
})
export class FooComponent {
private readonly appService = inject(Services.AppService);

constructor(@Inject(FOO_COMPONENT_DATA_TOKEN) public data: ServerError) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { REQUEST } from '@shared/app.tokens';

import { FooComponent } from './foo.component';
import { FOO_COMPONENT_DATA_TOKEN, FooComponent } from './foo.component';

describe('FooComponent', () => {
let fixture: ComponentFixture<FooComponent>;
Expand All @@ -13,6 +13,13 @@ describe('FooComponent', () => {
provide: REQUEST,
useValue: {},
},
{
provide: FOO_COMPONENT_DATA_TOKEN,
useValue: {
title: '',
error: new Map(),
},
},
],
}).createComponent(FooComponent);
fixture.detectChanges();
Expand Down
11 changes: 10 additions & 1 deletion examples/example-app-v15/src/app/shared/foo.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component, inject } from '@angular/core';
import { Component, Inject, inject, InjectionToken } from '@angular/core';
import { Services } from '@shared/shared';

export interface ServerError {
title: string;
errors: Map<string, string[]>;
}

export const FOO_COMPONENT_DATA_TOKEN = new InjectionToken<ServerError>('FooComponentData');

@Component({
template: ` <h1>Foo</h1> `,
standalone: true,
})
export class FooComponent {
private readonly appService = inject(Services.AppService);

constructor(@Inject(FOO_COMPONENT_DATA_TOKEN) public data: ServerError) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { REQUEST } from '@shared/app.tokens';

import { FooComponent } from './foo.component';
import { FOO_COMPONENT_DATA_TOKEN, FooComponent } from './foo.component';

describe('FooComponent', () => {
let fixture: ComponentFixture<FooComponent>;
Expand All @@ -13,6 +13,13 @@ describe('FooComponent', () => {
provide: REQUEST,
useValue: {},
},
{
provide: FOO_COMPONENT_DATA_TOKEN,
useValue: {
title: '',
error: new Map(),
},
},
],
}).createComponent(FooComponent);
fixture.detectChanges();
Expand Down
11 changes: 10 additions & 1 deletion examples/example-app-v17/src/app/shared/foo.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component, inject } from '@angular/core';
import { Component, Inject, inject, InjectionToken } from '@angular/core';
import { Services } from '@shared/shared';

export interface ServerError {
title: string;
errors: Map<string, string[]>;
}

export const FOO_COMPONENT_DATA_TOKEN = new InjectionToken<ServerError>('FooComponentData');

@Component({
template: ` <h1>Foo</h1> `,
standalone: true,
})
export class FooComponent {
private readonly appService = inject(Services.AppService);

constructor(@Inject(FOO_COMPONENT_DATA_TOKEN) public data: ServerError) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { REQUEST } from '@shared/app.tokens';

import { FooComponent } from './foo.component';
import { FOO_COMPONENT_DATA_TOKEN, FooComponent } from './foo.component';

describe('FooComponent', () => {
let fixture: ComponentFixture<FooComponent>;
Expand All @@ -13,6 +13,13 @@ describe('FooComponent', () => {
provide: REQUEST,
useValue: {},
},
{
provide: FOO_COMPONENT_DATA_TOKEN,
useValue: {
title: '',
error: new Map(),
},
},
],
}).createComponent(FooComponent);
fixture.detectChanges();
Expand Down
11 changes: 10 additions & 1 deletion examples/example-app-v18/src/app/shared/foo.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component, inject } from '@angular/core';
import { Component, Inject, inject, InjectionToken } from '@angular/core';
import { Services } from '@shared/shared';

export interface ServerError {
title: string;
errors: Map<string, string[]>;
}

export const FOO_COMPONENT_DATA_TOKEN = new InjectionToken<ServerError>('FooComponentData');

@Component({
template: ` <h1>Foo</h1> `,
standalone: true,
})
export class FooComponent {
private readonly appService = inject(Services.AppService);

constructor(@Inject(FOO_COMPONENT_DATA_TOKEN) public data: ServerError) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { REQUEST } from '@shared/app.tokens';

import { FooComponent } from './foo.component';
import { FOO_COMPONENT_DATA_TOKEN, FooComponent } from './foo.component';

describe('FooComponent', () => {
let fixture: ComponentFixture<FooComponent>;
Expand All @@ -13,6 +13,13 @@ describe('FooComponent', () => {
provide: REQUEST,
useValue: {},
},
{
provide: FOO_COMPONENT_DATA_TOKEN,
useValue: {
title: '',
error: new Map(),
},
},
],
}).createComponent(FooComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { Component, inject } from '@angular/core';
import { Component, Inject, inject, InjectionToken } from '@angular/core';
import { Services } from '@shared/shared';

export interface ServerError {
title: string;
errors: Map<string, string[]>;
}

export const FOO_COMPONENT_DATA_TOKEN = new InjectionToken<ServerError>('FooComponentData');

@Component({
template: ` <h1>Foo</h1> `,
standalone: true,
})
export class FooComponent {
private readonly appService = inject(Services.AppService);

constructor(@Inject(FOO_COMPONENT_DATA_TOKEN) public data: ServerError) {}
}

0 comments on commit 62c68f0

Please sign in to comment.