Skip to content

Commit

Permalink
refactor: fix typecheck in spec files (#6905)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Feb 28, 2024
1 parent da391fc commit 4346794
Show file tree
Hide file tree
Showing 144 changed files with 659 additions and 645 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: taiga-family/ci/actions/setup/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- uses: taiga-family/ci/actions/setup/[email protected]
- run: npx tsc --project tsconfig.spec.json
- run: npx nx run-many -t test --output-style=stream --nxBail
- run: tree -L 2 ./coverage -P 'lcov.info'
- uses: codecov/[email protected]
Expand Down
21 changes: 11 additions & 10 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Config} from 'jest';
import {resolve} from 'path';
import type {JestConfigWithTsJest} from 'ts-jest';
import {pathsToModuleNameMapper} from 'ts-jest';

process.env.TZ = 'Europe/Moscow';
Expand All @@ -9,7 +9,7 @@ process.env.TS_JEST_DISABLE_VER_CHECKER = 'true';
const {compilerOptions} = require(resolve(__dirname, 'tsconfig.json'));
const maxParallel = require('os').cpus().length / 2;

const config: Config = {
const config: JestConfigWithTsJest = {
rootDir: __dirname,

/**
Expand All @@ -31,13 +31,6 @@ const config: Config = {
* A set of global variables that need
* to be available in all test environments.
*/
globals: {
'ts-jest': {
tsconfig: resolve(__dirname, 'tsconfig.spec.json'),
stringifyContentPathRegex: '\\.html$',
isolatedModules: true,
},
},

/**
* Jest will run .mjs and .js files with nearest package.json's type
Expand All @@ -56,7 +49,15 @@ const config: Config = {
* A map from regular expressions to paths to transformers.
*/
transform: {
'^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
'^.+\\.(ts|js|mjs|html|svg)$': [
'jest-preset-angular',
{
tsconfig: resolve(__dirname, 'tsconfig.spec.json'),
stringifyContentPathRegex: '\\.html$',
isolatedModules: true,
diagnostics: true,
},
],
},
transformIgnorePatterns: ['node_modules/(?!@angular|rxjs|ngx-highlightjs|@maskito)'],

Expand Down
8 changes: 4 additions & 4 deletions projects/addon-charts/components/axes/axes.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ export class TuiAxesComponent {

protected readonly mode$ = inject(TUI_MODE);

protected get hasXLabels(): boolean {
public get hasXLabels(): boolean {
return !!this.axisXLabels.length;
}

protected get hasYLabels(): boolean {
public get hasYLabels(): boolean {
return (!!this.axisYLabels.length && !this.axisYInset) || !!this.axisYName;
}

protected get hasYSecondaryLabels(): boolean {
public get hasYSecondaryLabels(): boolean {
return (
(!!this.axisYSecondaryLabels.length && !this.axisYSecondaryInset) ||
!!this.axisYSecondaryName
);
}

protected fallback(label: string | null): string {
public fallback(label: string | null): string {
return label || CHAR_NO_BREAK_SPACE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ describe('Axes', () => {
})
class TestComponent {
@ViewChild('defaultValues')
protected readonly defaultValues!: TuiAxesComponent;
public readonly defaultValues!: TuiAxesComponent;

@ViewChild('customValues')
protected readonly customValues!: TuiAxesComponent;
public readonly customValues!: TuiAxesComponent;

protected axisXLabels = ['Label 1', 'Label 2'];
public axisXLabels = ['Label 1', 'Label 2'];

protected axisYLabels = ['', 'Label 2', 'Label 3'];
public axisYLabels = ['', 'Label 2', 'Label 3'];

protected axisYSecondaryLabels = ['', 'Label 2', 'Label 3'];
public axisYSecondaryLabels = ['', 'Label 2', 'Label 3'];

protected axisYName = '';
public axisYName = '';

protected axisYSecondaryName = '';
public axisYSecondaryName = '';
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export class TuiBarChartComponent {
return this.hintOptions?.content || '';
}

protected get transposed(): ReadonlyArray<readonly number[]> {
public get transposed(): ReadonlyArray<readonly number[]> {
return this.transpose(this.value);
}

protected get computedMax(): number {
public get computedMax(): number {
return this.max || this.getMax(this.value, this.collapsed);
}

protected readonly percentMapper: TuiTypedMapper<
public readonly percentMapper: TuiTypedMapper<
[readonly number[], boolean, number],
number
> = (set, collapsed, max) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ describe('BarChart', () => {
})
class TestComponent {
@ViewChild(TuiBarChartComponent)
protected readonly component!: TuiBarChartComponent;
public readonly component!: TuiBarChartComponent;

protected readonly value = [
public readonly value = [
[1, 2, 3],
[4, 5, 6],
];

protected max = NaN;
public max = NaN;
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ describe('BarSet', () => {
})
class TestComponent {
@ViewChild(TuiBarSetComponent)
protected readonly component!: TuiBarSetComponent;
public readonly component!: TuiBarSetComponent;

protected readonly value = [10, 20, 30, 40];
protected collapsed = false;
public readonly value = [10, 20, 30, 40];
public collapsed = false;
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('PieChart', () => {
`,
})
class TestComponent {
protected readonly value = [1, 2, 3];
public readonly value = [1, 2, 3];
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class TuiInputCardGroupedComponent
}
}

protected clear(): void {
public clear(): void {
this.expireInert = false;
this.value = null;
this.focusCard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {
TuiCard,
TuiInputCardGroupedComponent,
TuiInputCardGroupedModule,
} from '@taiga-ui/addon-commerce';
Expand All @@ -20,6 +21,7 @@ import {
} from '@taiga-ui/cdk';
import {TuiSvgModule} from '@taiga-ui/core';
import {TuiNativeInputPO} from '@taiga-ui/testing';
import {Mock} from 'jest-mock';

describe('InputCardGrouped', () => {
@Component({
Expand All @@ -36,14 +38,14 @@ describe('InputCardGrouped', () => {
})
class TestComponent {
@ViewChild(TuiInputCardGroupedComponent, {static: true})
protected component!: TuiInputCardGroupedComponent;
public component!: TuiInputCardGroupedComponent;

@ViewChild('customIconTemplate', {read: TemplateRef})
protected customIconTemplate!: TemplateRef<any>;
public customIconTemplate!: TemplateRef<any>;

protected control = new FormControl('');
public control = new FormControl<Partial<TuiCard>>({card: ''});

protected onBinChange = jest.fn();
public onBinChange: (event: string | null) => void = jest.fn();
}

let fixture: ComponentFixture<TestComponent>;
Expand Down Expand Up @@ -101,23 +103,23 @@ describe('InputCardGrouped', () => {

it('Value has changed, first 6 digits are the same', () => {
setCard('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
setCard('123456987');

expect(testComponent.onBinChange).not.toHaveBeenCalled();
});

it('Value has changed, first 6 digits have changed', () => {
setCard('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
setCard('654321789');

expect(testComponent.onBinChange).toHaveBeenCalledWith('654321');
});

it('Value has changed, now it has less than 6 digits', () => {
setCard('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
setCard('123');

expect(testComponent.onBinChange).toHaveBeenCalledWith(null);
Expand Down Expand Up @@ -269,6 +271,6 @@ describe('InputCardGrouped', () => {
}

function getExpire(): string {
return testComponent.control.value.expire;
return testComponent.control.value?.expire ?? '';
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ export abstract class AbstractTuiInputCard<

public abstract get nativeFocusableElement(): TuiNativeFocusableElement | null;

protected get defaultIcon(): string | null {
public get defaultIcon(): string | null {
const paymentSystem = this.getPaymentSystem(this.card);

return paymentSystem && this.options.icons[paymentSystem];
}

protected get paymentSystem(): TuiPaymentSystem | null {
public get paymentSystem(): TuiPaymentSystem | null {
return this.getPaymentSystem(this.card);
}

/** @deprecated remove in 4.0 */
protected get icon(): PolymorpheusContent {
public get icon(): PolymorpheusContent {
return this.cardSrc || this.defaultIcon;
}

Expand All @@ -59,11 +59,11 @@ export abstract class AbstractTuiInputCard<
* @deprecated: drop in v4.0
* use {@link autocomplete}
*/
protected get autocompleteCard(): TuiAutofillFieldName {
public get autocompleteCard(): TuiAutofillFieldName {
return this.autocomplete;
}

protected get bin(): string | null {
public get bin(): string | null {
return this.card.length < 6 ? null : this.card.slice(0, 6);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class TuiInputCardComponent extends AbstractTuiInputCard<string> {
}
}

protected onFocused(focused: boolean): void {
public onFocused(focused: boolean): void {
this.updateFocused(focused);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Component, TemplateRef, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {TuiInputCardComponent, TuiInputCardModule} from '@taiga-ui/addon-commerce';
import {Mock} from 'jest-mock';

describe('InputCard', () => {
@Component({
Expand All @@ -18,14 +19,14 @@ describe('InputCard', () => {
})
class TestComponent {
@ViewChild(TuiInputCardComponent, {static: true})
protected component!: TuiInputCardComponent;
public component!: TuiInputCardComponent;

@ViewChild('customIconTemplateRef', {read: TemplateRef})
protected customIconTemplateRef!: TemplateRef<any>;
public customIconTemplateRef!: TemplateRef<any>;

protected control = new FormControl('');
public control = new FormControl('');

protected onBinChange = jest.fn();
public onBinChange: (event: string | null) => void = jest.fn();
}

let fixture: ComponentFixture<TestComponent>;
Expand Down Expand Up @@ -97,23 +98,23 @@ describe('InputCard', () => {

it('The value has changed, the first 6 characters are unchanged', () => {
testComponent.control.setValue('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
testComponent.control.setValue('123456987');

expect(testComponent.onBinChange).not.toHaveBeenCalled();
});

it('The value has changed, the first 6 characters have changed', () => {
testComponent.control.setValue('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
testComponent.control.setValue('654321789');

expect(testComponent.onBinChange).toHaveBeenCalledWith('654321');
});

it('The value has changed to less than 6 characters', () => {
testComponent.control.setValue('123456789');
testComponent.onBinChange.mockClear();
(testComponent.onBinChange as Mock).mockClear();
testComponent.control.setValue('123');

expect(testComponent.onBinChange).toHaveBeenCalledWith(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export class TuiInputCVCComponent
};
}

protected exampleText = '000';
public exampleText = '000';

protected maskOptions: MaskitoOptions = {
public maskOptions: MaskitoOptions = {
mask: new Array(3).fill(TUI_DIGIT_REGEXP),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('InputCVC', () => {
})
class TestComponent {
@ViewChild('default')
protected default!: TuiInputCVCComponent;
public default!: TuiInputCVCComponent;

@ViewChild('custom')
protected custom!: TuiInputCVCComponent;
public custom!: TuiInputCVCComponent;

protected control = new FormControl('');
public control = new FormControl('');
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe('InputExpire', () => {
})
class TestComponent {
@ViewChild(TuiInputExpireComponent)
protected input!: TuiInputExpireComponent;
public input!: TuiInputExpireComponent;

protected value = '';
public value = '';
}

let fixture: ComponentFixture<TestComponent>;
Expand Down
Loading

0 comments on commit 4346794

Please sign in to comment.