Skip to content

Commit 75f689e

Browse files
committed
fix: npm warnings
1 parent ca47273 commit 75f689e

File tree

7 files changed

+922
-1825
lines changed

7 files changed

+922
-1825
lines changed

Diff for: karma.conf.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function (config) {
1919
// for example, you can disable the random execution with `random: false`
2020
// or set a specific seed with `seed: 4321`
2121
},
22-
clearContext: false, // leave Jasmine Spec Runner output visible in browser
22+
clearContext: true, // leave Jasmine Spec Runner output visible in browser
2323
},
2424
jasmineHtmlReporter: {
2525
suppressAll: true, // removes the duplicated traces
@@ -35,7 +35,14 @@ module.exports = function (config) {
3535
logLevel: config.LOG_INFO,
3636
autoWatch: true,
3737
browsers: ["Chrome"],
38+
customLaunchers: {
39+
ChromeHeadlessCI: {
40+
base: "ChromeHeadless",
41+
flags: ["--no-sandbox"],
42+
},
43+
},
3844
singleRun: false,
3945
restartOnFileChange: true,
46+
browserNoActivityTimeout: 1000 * 60, // (Default: 10000)
4047
});
4148
};

Diff for: package-lock.json

+844-1,799
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"zone.js": "~0.11.3"
2929
},
3030
"devDependencies": {
31-
"@angular-devkit/build-angular": "~0.1102.10",
31+
"@angular-devkit/build-angular": "^0.1102.12",
3232
"@angular/cli": "~11.2.10",
3333
"@angular/compiler-cli": "~11.2.11",
3434
"@types/echarts": "^4.1.8",

Diff for: src/app/components/example/example.component.spec.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
import { ComponentFixture, TestBed } from "@angular/core/testing";
2-
1+
import { Component } from "@angular/core";
2+
import { TestBed } from "@angular/core/testing";
3+
import { By } from "@angular/platform-browser";
34
import { ExampleComponent } from "./example.component";
45

56
describe("ExampleComponent", () => {
6-
let component: ExampleComponent;
7-
let fixture: ComponentFixture<ExampleComponent>;
8-
97
beforeEach(async () => {
108
await TestBed.configureTestingModule({
119
declarations: [ExampleComponent],
1210
}).compileComponents();
1311
});
1412

15-
beforeEach(() => {
16-
fixture = TestBed.createComponent(ExampleComponent);
17-
component = fixture.componentInstance;
13+
it("should className correct", () => {
14+
const fixture = TestBed.createComponent(ExampleComponent);
15+
const cmpt = fixture.debugElement.query(By.css(".example"));
1816
fixture.detectChanges();
17+
expect(cmpt).toBeTruthy();
1918
});
2019

21-
it("should create", () => {
22-
expect(component).toBeTruthy();
20+
it("should theme work", () => {
21+
const fixture = TestBed.createComponent(ExampleComponent);
22+
const cmpt = fixture.debugElement.query(By.css(".is-dark"));
23+
const cmptIns = fixture.componentInstance;
24+
cmptIns.theme = "dark";
25+
fixture.detectChanges();
26+
expect(cmpt).toBeTruthy();
2327
});
2428
});
29+
30+
@Component({
31+
template: `<example>
32+
<h1>H1</h1>
33+
</example>`,
34+
})
35+
class TestExampleComponent {}

Diff for: src/app/components/example/example.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Component, Input, OnInit } from "@angular/core";
1+
import { Component, Input, OnInit, ViewEncapsulation } from "@angular/core";
22

33
@Component({
4-
// tslint:disable-next-line:component-selector
54
selector: "div[example]",
65
templateUrl: "./example.component.html",
76
styleUrls: ["./example.component.less"],
7+
preserveWhitespaces: false,
8+
encapsulation: ViewEncapsulation.None,
89
})
910
export class ExampleComponent implements OnInit {
1011
@Input() theme = "light";
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import { ComponentFixture, TestBed } from "@angular/core/testing";
2-
1+
import { By } from "@angular/platform-browser";
2+
import { TestBed } from "@angular/core/testing";
33
import { NzFooterBarComponent } from "./nz-footer-bar.component";
44

55
describe("NzFooterBarComponent", () => {
6-
let component: NzFooterBarComponent;
7-
let fixture: ComponentFixture<NzFooterBarComponent>;
8-
96
beforeEach(async () => {
107
await TestBed.configureTestingModule({
118
declarations: [NzFooterBarComponent],
129
}).compileComponents();
1310
});
1411

15-
beforeEach(() => {
16-
fixture = TestBed.createComponent(NzFooterBarComponent);
17-
component = fixture.componentInstance;
12+
it("should className correct", () => {
13+
const fixture = TestBed.createComponent(NzFooterBarComponent);
1814
fixture.detectChanges();
19-
});
20-
21-
it("should create", () => {
22-
expect(component).toBeTruthy();
15+
const cmpt = fixture.debugElement.query(By.css(".nz-footer-bar")).nativeElement;
16+
expect(cmpt).toBeTruthy();
2317
});
2418
});

Diff for: src/app/helpers/testing.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { CommonModule } from "@angular/common";
2+
import { DebugElement, NgModule, NO_ERRORS_SCHEMA, Type } from "@angular/core";
3+
import { ComponentFixture, TestBed, TestBedStatic } from "@angular/core/testing";
4+
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
5+
6+
type ComponentBedOptions = Pick<NgModule, "providers" | "declarations" | "imports">;
7+
export interface ComponentBed<T> {
8+
bed: TestBedStatic;
9+
fixture: ComponentFixture<T>;
10+
nativeElement: HTMLElement;
11+
debugElement: DebugElement;
12+
component: T;
13+
}
14+
export function createComponentBed<T>(
15+
component: Type<T>,
16+
options: ComponentBedOptions = {
17+
providers: [],
18+
declarations: [],
19+
imports: [],
20+
}
21+
): ComponentBed<T> {
22+
const { imports, declarations, providers } = options;
23+
const config = {
24+
imports: [NoopAnimationsModule, CommonModule, ...(imports || [])],
25+
declarations: [component, ...(declarations || [])],
26+
schemas: [NO_ERRORS_SCHEMA],
27+
providers: providers || [],
28+
};
29+
const bed = TestBed.configureTestingModule(config);
30+
const fixture = TestBed.createComponent<T>(component);
31+
fixture.detectChanges();
32+
return {
33+
bed,
34+
fixture,
35+
nativeElement: fixture.nativeElement,
36+
debugElement: fixture.debugElement,
37+
component: fixture.componentInstance,
38+
};
39+
}

0 commit comments

Comments
 (0)