Skip to content

update example specs to standalone #400

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

Merged
Merged
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
8 changes: 0 additions & 8 deletions apps/example-app-karma/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"outputPath": "dist/apps/example-app-karma",
"index": "apps/example-app-karma/src/index.html",
"main": "apps/example-app-karma/src/main.ts",
"polyfills": "apps/example-app-karma/src/polyfills.ts",
"tsConfig": "apps/example-app-karma/tsconfig.app.json",
"assets": ["apps/example-app-karma/src/favicon.ico", "apps/example-app-karma/src/assets"],
"styles": [],
Expand All @@ -27,12 +26,6 @@
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "apps/example-app-karma/src/environments/environment.ts",
"with": "apps/example-app-karma/src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
Expand Down Expand Up @@ -74,7 +67,6 @@
"options": {
"main": "apps/example-app-karma/src/test.ts",
"tsConfig": "apps/example-app-karma/tsconfig.spec.json",
"polyfills": "apps/example-app-karma/src/polyfills.ts",
"karmaConfig": "apps/example-app-karma/karma.conf.js"
}
}
Expand Down
9 changes: 0 additions & 9 deletions apps/example-app-karma/src/app/app.module.ts

This file was deleted.

75 changes: 75 additions & 0 deletions apps/example-app-karma/src/app/examples/login-form.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Component } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/angular';
import { NgIf } from '@angular/common';

it('should create a component with inputs and a button to submit', async () => {
await render(LoginComponent);

expect(screen.getByRole('textbox', { name: 'email' })).toBeInTheDocument();
expect(screen.getByLabelText('password')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'submit' })).toBeInTheDocument();
});

it('should display invalid message and submit button must be disabled', async () => {
const user = userEvent.setup();

await render(LoginComponent);

const email = screen.getByRole('textbox', { name: 'email' });
const password = screen.getByLabelText('password');

await user.type(email, 'foo');
await user.type(password, 's');

expect(screen.getAllByText(/is invalid/i).length).toBe(2);
expect(screen.getAllByRole('alert').length).toBe(2);
expect(screen.getByRole('button', { name: 'submit' })).toBeDisabled();
});

@Component({
selector: 'app-login',
standalone: true,
imports: [ReactiveFormsModule, NgIf],
template: `
<h1>Login</h1>

<form [formGroup]="form" (submit)="onSubmit(form)">
<input type="email" aria-label="email" formControlName="email" />
<div *ngIf="email.invalid && (email.dirty || email.touched)" role="alert">Email is invalid</div>
<input type="password" aria-label="password" formControlName="password" />
<div *ngIf="password.invalid && (password.dirty || password.touched)" role="alert">Password is invalid</div>
<button type="submit" aria-label="submit" [disabled]="form.invalid">Submit</button>
</form>
`,
})
class LoginComponent {
form: FormGroup = this.fb.group({
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(8)]],
});

constructor(private fb: FormBuilder) {}

blurred() {
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
console.log('aaaaaaaaac');
}
get email(): FormControl {
return this.form.get('email') as FormControl;
}

get password(): FormControl {
return this.form.get('password') as FormControl;
}

onSubmit(_fg: FormGroup): void {
// do nothing
}
}
69 changes: 0 additions & 69 deletions apps/example-app-karma/src/app/issues/issue-373.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/angular';

it('https://github.com/testing-library/angular-testing-library/issues/222 with rerender', async () => {
it('can rerender component', async () => {
const { rerender } = await render(`<div>Hello {{ name}}</div>`, {
componentProperties: {
name: 'Sarah',
Expand Down
Empty file.
3 changes: 0 additions & 3 deletions apps/example-app-karma/src/environments/environment.prod.ts

This file was deleted.

15 changes: 0 additions & 15 deletions apps/example-app-karma/src/environments/environment.ts

This file was deleted.

Binary file removed apps/example-app-karma/src/favicon.ico
Binary file not shown.
14 changes: 0 additions & 14 deletions apps/example-app-karma/src/index.html

This file was deleted.

13 changes: 0 additions & 13 deletions apps/example-app-karma/src/main.ts

This file was deleted.

65 changes: 0 additions & 65 deletions apps/example-app-karma/src/polyfills.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/example-app-karma/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
Expand Down
2 changes: 1 addition & 1 deletion apps/example-app-karma/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"target": "ES2022",
"useDefineForClassFields": false
},
"files": ["src/main.ts", "src/polyfills.ts"],
"files": ["src/main.ts"],
"include": ["src/**/*.d.ts"],
"exclude": ["**/*.test.ts", "**/*.spec.ts"]
}
2 changes: 1 addition & 1 deletion apps/example-app-karma/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"target": "ES2022",
"useDefineForClassFields": false
},
"files": ["src/test.ts", "src/polyfills.ts"],
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
6 changes: 0 additions & 6 deletions apps/example-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "apps/example-app/src/environments/environment.ts",
"with": "apps/example-app/src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
Expand Down
Loading