Skip to content

build: run example harness unit tests and fix errors #21759

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 1 commit into from
Feb 1, 2021
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
26 changes: 24 additions & 2 deletions src/components-examples/material/autocomplete/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
name = "autocomplete",
srcs = glob(["**/*.ts"]),
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
assets = glob([
"**/*.html",
"**/*.css",
Expand Down Expand Up @@ -34,3 +37,22 @@ filegroup(
"**/*.ts",
]),
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":autocomplete",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/autocomplete",
"//src/material/autocomplete/testing",
"@npm//@angular/platform-browser-dynamic",
],
)

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,43 +1,30 @@
import {TestBed, ComponentFixture, waitForAsync, inject} from '@angular/core/testing';
import {TestBed, ComponentFixture} 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 {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatAutocompleteModule} from '@angular/material/autocomplete';
import {AutocompleteHarnessExample} from './autocomplete-harness-example';
import {OverlayContainer} from '@angular/cdk/overlay';

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

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

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatAutocompleteModule],
declarations: [AutocompleteHarnessExample]
}).compileComponents();
}));

beforeEach( () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatAutocompleteModule],
declarations: [AutocompleteHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(AutocompleteHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
});

afterEach(() => {
// Angular won't call this for us so we need to do it ourselves to avoid leaks.
overlayContainer.ngOnDestroy();
overlayContainer = null!;
});

it('should load all autocomplete harnesses', async () => {
Expand Down
26 changes: 24 additions & 2 deletions src/components-examples/material/badge/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
name = "badge",
srcs = glob(["**/*.ts"]),
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
assets = glob([
"**/*.html",
"**/*.css",
Expand All @@ -31,3 +34,22 @@ filegroup(
"**/*.ts",
]),
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":badge",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/badge",
"//src/material/badge/testing",
"@npm//@angular/platform-browser-dynamic",
],
)

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,9 +1,11 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {TestBed, ComponentFixture} 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 {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatBadgeModule} from '@angular/material/badge';
import {BadgeHarnessExample} from './badge-harness-example';

Expand All @@ -15,17 +17,15 @@ describe('BadgeHarnessExample', () => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatBadgeModule],
declarations: [BadgeHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(BadgeHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
})
);
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatBadgeModule],
declarations: [BadgeHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(BadgeHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});

it('should load all badge harnesses', async () => {
const badges = await loader.getAllHarnesses(MatBadgeHarness);
Expand Down
27 changes: 25 additions & 2 deletions src/components-examples/material/bottom-sheet/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
name = "bottom-sheet",
srcs = glob(["**/*.ts"]),
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
assets = glob([
"**/*.html",
"**/*.css",
Expand Down Expand Up @@ -32,3 +35,23 @@ filegroup(
"**/*.ts",
]),
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":bottom-sheet",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/bottom-sheet",
"//src/material/bottom-sheet/testing",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
],
)

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,12 +1,13 @@
import {TestBed, ComponentFixture, waitForAsync, inject} from '@angular/core/testing';
import {TestBed, ComponentFixture} 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 {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatBottomSheetModule} from '@angular/material/bottom-sheet';
import {BottomSheetHarnessExample} from './bottom-sheet-harness-example';
import {OverlayContainer} from '@angular/cdk/overlay';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';

describe('BottomSheetHarnessExample', () => {
Expand All @@ -17,19 +18,14 @@ describe('BottomSheetHarnessExample', () => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatBottomSheetModule, NoopAnimationsModule],
declarations: [BottomSheetHarnessExample]
}).compileComponents();
}));

beforeEach(() => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatBottomSheetModule, NoopAnimationsModule],
declarations: [BottomSheetHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(BottomSheetHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);
inject([OverlayContainer], () => {})();
});

it('should load harness for a bottom sheet', async () => {
Expand Down
26 changes: 24 additions & 2 deletions src/components-examples/material/button-toggle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
name = "button-toggle",
srcs = glob(["**/*.ts"]),
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
assets = glob([
"**/*.html",
"**/*.css",
Expand All @@ -30,3 +33,22 @@ filegroup(
"**/*.ts",
]),
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":button-toggle",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/button-toggle",
"//src/material/button-toggle/testing",
"@npm//@angular/platform-browser-dynamic",
],
)

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,9 +1,11 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {TestBed, ComponentFixture} 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 {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import {MatButtonToggleModule} from '@angular/material/button-toggle';
import {ButtonToggleHarnessExample} from './button-toggle-harness-example';

Expand All @@ -15,15 +17,11 @@ describe('ButtonToggleHarnessExample', () => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatButtonToggleModule],
declarations: [ButtonToggleHarnessExample]
}).compileComponents();
}));

beforeEach(() => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatButtonToggleModule],
declarations: [ButtonToggleHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(ButtonToggleHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
Expand Down
26 changes: 24 additions & 2 deletions src/components-examples/material/button/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
name = "button",
srcs = glob(["**/*.ts"]),
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
assets = glob([
"**/*.html",
"**/*.css",
Expand All @@ -31,3 +34,22 @@ filegroup(
"**/*.ts",
]),
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(["**/*.spec.ts"]),
deps = [
":button",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/button",
"//src/material/button/testing",
"@npm//@angular/platform-browser-dynamic",
],
)

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