Skip to content

Commit

Permalink
build: remove init test environment calls from harness examples (#23853)
Browse files Browse the repository at this point in the history
Removes the init test environment calls from the harness examples. This
is meant to make the examples a little more readable, and easier to
integrate within CLI projects (especially when are starting to use
a plain CLI project as foundation for our StackBlitz examples).

The CLI sets up the test environment in a global test init file, so
we should make this assumption in our examples as well. This also helps
with reducing duplication in our code base.

(cherry picked from commit 88b718e)
  • Loading branch information
devversion authored and jelbourn committed Nov 2, 2021
1 parent 157dcd2 commit a65792e
Show file tree
Hide file tree
Showing 70 changed files with 38 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatTableHarness} from '@angular/material/table/testing';
import {HarnessLoader, parallel} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatTableModule} from '@angular/material/table';
import {TableHarnessExample} from './table-harness-example';

describe('TableHarnessExample', () => {
let fixture: ComponentFixture<TableHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatTableModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/autocomplete/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatAutocompleteHarness} from '@angular/material/autocomplete/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatAutocompleteModule} from '@angular/material/autocomplete';
import {AutocompleteHarnessExample} from './autocomplete-harness-example';

describe('AutocompleteHarnessExample', () => {
let fixture: ComponentFixture<AutocompleteHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatAutocompleteModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/badge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatBadgeHarness} from '@angular/material/badge/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatBadgeModule} from '@angular/material/badge';
import {BadgeHarnessExample} from './badge-harness-example';

describe('BadgeHarnessExample', () => {
let fixture: ComponentFixture<BadgeHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatBadgeModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/bottom-sheet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatBottomSheetHarness} from '@angular/material/bottom-sheet/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatBottomSheetModule} from '@angular/material/bottom-sheet';
import {BottomSheetHarnessExample} from './bottom-sheet-harness-example';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand All @@ -14,10 +10,6 @@ describe('BottomSheetHarnessExample', () => {
let fixture: ComponentFixture<BottomSheetHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatBottomSheetModule, NoopAnimationsModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/button-toggle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatButtonToggleGroupHarness} from '@angular/material/button-toggle/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatButtonToggleModule} from '@angular/material/button-toggle';
import {ButtonToggleHarnessExample} from './button-toggle-harness-example';

describe('ButtonToggleHarnessExample', () => {
let fixture: ComponentFixture<ButtonToggleHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatButtonToggleModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/button/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatButtonHarness} from '@angular/material/button/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatButtonModule} from '@angular/material/button';
import {ButtonHarnessExample} from './button-harness-example';

Expand All @@ -14,10 +10,6 @@ describe('ButtonHarnessExample', () => {
let loader: HarnessLoader;
let buttonHarness = MatButtonHarness;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatButtonModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/card/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatButtonHarness} from '@angular/material/button/testing';
import {MatCardHarness} from '@angular/material/card/testing';
import {HarnessLoader, parallel} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatCardModule} from '@angular/material/card';
import {CardHarnessExample} from './card-harness-example';

describe('CardHarnessExample', () => {
let fixture: ComponentFixture<CardHarnessExample>;
let loader: HarnessLoader;
beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatCardModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/checkbox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatCheckboxHarness} from '@angular/material/checkbox/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {ReactiveFormsModule} from '@angular/forms';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatCheckboxModule} from '@angular/material/checkbox';
import {CheckboxHarnessExample} from './checkbox-harness-example';

describe('CheckboxHarnessExample', () => {
let fixture: ComponentFixture<CheckboxHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatCheckboxModule, ReactiveFormsModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/chips/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatChipHarness, MatChipListboxHarness} from '@angular/material/chips/testing';
import {HarnessLoader, parallel} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {ChipsHarnessExample} from './chips-harness-example';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MatChipsModule} from '@angular/material/chips';
Expand All @@ -14,10 +10,6 @@ describe('ChipsHarnessExample', () => {
let fixture: ComponentFixture<ChipsHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatChipsModule, NoopAnimationsModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/datepicker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatDatepickerInputHarness} from '@angular/material/datepicker/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatDatepickerModule} from '@angular/material/datepicker';
import {DatepickerHarnessExample} from './datepicker-harness-example';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand All @@ -16,10 +12,6 @@ describe('DatepickerHarnessExample', () => {
let fixture: ComponentFixture<DatepickerHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatDatepickerModule, NoopAnimationsModule, MatNativeDateModule, FormsModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatDialogHarness} from '@angular/material/dialog/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatDialogModule} from '@angular/material/dialog';
import {DialogHarnessExample} from './dialog-harness-example';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand All @@ -14,10 +10,6 @@ describe('DialogHarnessExample', () => {
let fixture: ComponentFixture<DialogHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(async () => {
await TestBed.configureTestingModule({
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/divider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatDividerHarness} from '@angular/material/divider/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatDividerModule} from '@angular/material/divider';
import {DividerHarnessExample} from './divider-harness-example';

describe('DividerHarnessExample', () => {
let fixture: ComponentFixture<DividerHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatDividerModule],
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/material/expansion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
exclude_init_script = True,
deps = [":unit_tests_lib"],
)
Loading

0 comments on commit a65792e

Please sign in to comment.