Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer:8 #1145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/angular/8-pure-pipe/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
export default {
displayName: 'angular-projection',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {},
coverageDirectory: '../../../coverage/apps/angular/1-projection',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
20 changes: 9 additions & 11 deletions apps/angular/8-pure-pipe/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { NgFor } from '@angular/common';
import { Component } from '@angular/core';
import { PersonPipe } from './person.pipe';
import { Person } from './types';

@Component({
standalone: true,
imports: [NgFor],
imports: [PersonPipe],
selector: 'app-root',
template: `
<div *ngFor="let person of persons; let index = index">
{{ heavyComputation(person, index) }}
</div>
@for (person of persons; track person) {
<div>
{{ person | person: $index }}
</div>
}
`,
})
export class AppComponent {
persons = ['toto', 'jack'];

heavyComputation(name: string, index: number) {
// very heavy computation
return `${name} - ${index}`;
}
persons: Person[] = ['toto', 'jack'];
}
13 changes: 13 additions & 0 deletions apps/angular/8-pure-pipe/src/app/person.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PersonPipe } from './person.pipe';

describe('PersonPipe', () => {
it('create an instance', () => {
const pipe = new PersonPipe();
expect(pipe).toBeTruthy();
});
it('should transform', () => {
const pipe = new PersonPipe();
expect(pipe.transform('person', 10)).toBe(`person - 10`);
expect(pipe.transform('', 10)).toBe(`? - 10`);
});
});
12 changes: 12 additions & 0 deletions apps/angular/8-pure-pipe/src/app/person.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Person } from './types';

@Pipe({
name: 'person',
standalone: true,
})
export class PersonPipe implements PipeTransform {
transform(person: Person, index: number): string {
return `${person || '?'} - ${index}`;
}
}
1 change: 1 addition & 0 deletions apps/angular/8-pure-pipe/src/app/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Person = string;
1 change: 1 addition & 0 deletions apps/angular/8-pure-pipe/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-preset-angular/setup-jest';
2 changes: 1 addition & 1 deletion apps/angular/8-pure-pipe/tsconfig.editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "./tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"types": []
"types": ["jest", "node"]
}
}
3 changes: 3 additions & 0 deletions apps/angular/8-pure-pipe/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.editor.json"
}
Expand Down
10 changes: 10 additions & 0 deletions apps/angular/8-pure-pipe/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
Loading