Skip to content

Commit

Permalink
ci: add jest eslint rules (#5531)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Oct 5, 2023
1 parent 065ceca commit 05123fa
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 145 deletions.
51 changes: 5 additions & 46 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@
"extends": [
"plugin:@taiga-ui/experience/all",
"plugin:@taiga-ui/experience/taiga-naming-convention"
],
"overrides": [
{
"files": [
"**/*.spec.ts"
],
"plugins": [
"jest"
],
"extends": [
"plugin:jest/recommended"
],
"rules": {
"jest/expect-expect": "off",
"jest/no-disabled-tests": "off",
"jest/no-done-callback": "off",
"jest/no-test-prefixes": "off"
}
}
]
},
"stylelint": {
Expand All @@ -107,6 +126,7 @@
"@angular/platform-server": "12.2.17",
"@angular/router": "12.2.17",
"core-js": "2.6.12",
"eslint-plugin-jest": "27.4.2",
"parse5": "6.0.1",
"rxjs": "6.6.7",
"zone.js": "0.11.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {

describe(`getCurrencySymbol`, () => {
describe(`string`, () => {
it(`returns founded currency symbol`, () => {
it(`returns founded currency symbol by currency`, () => {
expect(tuiGetCurrencySymbol(`HKD`)).toBe(`HK$`);
});

it(`returns founded currency symbol`, () => {
it(`returns founded currency symbol by currency code`, () => {
expect(tuiGetCurrencySymbol(`344`)).toBe(`HK$`);
});

Expand Down
2 changes: 1 addition & 1 deletion projects/addon-commerce/utils/test/is-expire-valid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe(`tuiIsExpireValid`, () => {
};

for (const expire in specs) {
describe(expire, () => {
describe(`${expire}`, () => {
for (const {today, valid} of specs[expire as keyof typeof specs]) {
it(`It's ${valid ? `valid` : `invalid`} when today is ${today}`, () =>
expect(tuiIsExpireValid(expire, new Date(today))).toBe(valid));
Expand Down
16 changes: 8 additions & 8 deletions projects/cdk/date-time/test/day.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,25 +294,25 @@ describe(`TuiDay`, () => {
beforeEach(() => tuiSwitchNgDevMode(true));

it(`'2018-aa-20'`, () => {
expect(() => TuiDay.jsonParse(`2018-aa-20`)).toThrowError(
expect(() => TuiDay.jsonParse(`2018-aa-20`)).toThrow(
`Invalid month: NaN`,
);
});

it(`'2018-99-20'`, () => {
expect(() => TuiDay.jsonParse(`2018-99-20`)).toThrowError(
expect(() => TuiDay.jsonParse(`2018-99-20`)).toThrow(
`Invalid month: 98`,
);
});

it(`'2001-02-29'`, () => {
expect(() => TuiDay.jsonParse(`2001-02-29`)).toThrowError(
expect(() => TuiDay.jsonParse(`2001-02-29`)).toThrow(
`Invalid day: 29`,
);
});

it(`'test'`, () => {
expect(() => TuiDay.jsonParse(`test`)).toThrowError(
expect(() => TuiDay.jsonParse(`test`)).toThrow(
`Invalid year: NaN`,
);
});
Expand All @@ -322,19 +322,19 @@ describe(`TuiDay`, () => {

describe(`production mode`, () => {
it(`'2018-aa-20'`, () => {
expect(() => TuiDay.jsonParse(`2018-aa-20`)).toThrowError(``);
expect(() => TuiDay.jsonParse(`2018-aa-20`)).toThrow(``);
});

it(`'2018-99-20'`, () => {
expect(() => TuiDay.jsonParse(`2018-99-20`)).toThrowError(``);
expect(() => TuiDay.jsonParse(`2018-99-20`)).toThrow(``);
});

it(`'2001-02-29'`, () => {
expect(() => TuiDay.jsonParse(`2001-02-29`)).toThrowError(``);
expect(() => TuiDay.jsonParse(`2001-02-29`)).toThrow(``);
});

it(`'test'`, () => {
expect(() => TuiDay.jsonParse(`test`)).toThrowError(``);
expect(() => TuiDay.jsonParse(`test`)).toThrow(``);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe(`ng-update angular.json`, () => {
);
});

it(`it included proprietary-tds-icons now`, async () => {
it(`included proprietary-tds-icons now`, async () => {
setActiveProject(createProject(host));

createSourceFile(
Expand Down
6 changes: 6 additions & 0 deletions projects/cdk/services/test/static-request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ xdescribe(`TuiStaticRequest service`, () => {
beforeEach(() => {
service = new TuiStaticRequestService({} as any, {} as any);
// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
jasmine.Ajax.install();
});

afterEach(() => {
// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
jasmine.Ajax.uninstall();
});

Expand Down Expand Up @@ -50,9 +52,11 @@ xdescribe(`TuiStaticRequest service`, () => {
});

// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
jasmine.Ajax.requests.mostRecent().respondWith(RESPONSE);

// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
expect(jasmine.Ajax.requests.mostRecent().url).toBe(`test`);
expect(result).toBe(`awesome response`);
expect(completed).toBe(true);
Expand All @@ -68,6 +72,7 @@ xdescribe(`TuiStaticRequest service`, () => {
});

// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
jasmine.Ajax.requests.mostRecent().respondWith(RESPONSE);

service.request(`test`).subscribe({
Expand All @@ -80,6 +85,7 @@ xdescribe(`TuiStaticRequest service`, () => {
});

// @ts-ignore
// eslint-disable-next-line jest/no-jasmine-globals
expect(jasmine.Ajax.requests.count()).toBe(1);
expect(result2).toBe(result1);
expect(completed).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/utils/dom/test/point-to-client-rect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe(`tuiPointToClientRect`, () => {
);
});

it(`default`, () => {
it(`x=100,y=200`, () => {
expect(tuiPointToClientRect(100, 200)).toEqual(
// @ts-ignore
expect.objectContaining({
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/utils/focus/tests/move-focus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {tuiMoveFocus} from '@taiga-ui/cdk';

describe(`move focus`, () => {
it(` `, () => {
it(`default`, () => {
const first = document.createElement(`button`);
const second = document.createElement(`textarea`);

Expand Down
4 changes: 0 additions & 4 deletions projects/cdk/utils/math/test/normalize-to-int-number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ describe(`normalizeToIntNumber`, () => {
expect(tuiNormalizeToIntNumber(5.7, min, max)).toBe(6);
});

it(`0.1`, () => {
expect(tuiNormalizeToIntNumber(0.1, min, max)).toBe(0);
});

it(`Infinity`, () => {
expect(tuiNormalizeToIntNumber(Infinity, min, max)).toBe(max);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe(`Getting fractional part from number`, () => {
expect(tuiGetFractionPartPadded(-10, 2)).toBe(``);
});

it(`fractional value with small precision and bigger `, () => {
it(`fractional value with small precision and bigger`, () => {
expect(tuiGetFractionPartPadded(0.0002, 2)).toBe(`00`);
});

Expand All @@ -54,7 +54,7 @@ describe(`Getting fractional part from number`, () => {
expect(tuiGetFractionPartPadded(-10, 8)).toBe(``);
});

it(`fractional value with small precision and bigger `, () => {
it(`fractional value with small precision and bigger`, () => {
expect(tuiGetFractionPartPadded(0.0002, 8)).toBe(`0002`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe(`Dialogs + browser back navigation`, () => {
});

// TODO: change it back after solving https://github.com/taiga-family/taiga-ui/issues/3270
describe.skip(`feature is disabled`, () => {
xdescribe(`feature is disabled`, () => {
beforeEach(() => {
cy.tuiVisit(`components/dialog`, {inIframe: true});
});
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/components/badge/test/badge.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe(`Badge`, () => {
});
});

describe(`states: `, () => {
describe(`states:`, () => {
it(`if value is empty, add appropriate css class`, async () => {
testComponent.value = ``;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe(`Breadcrumbs Wrapper`, () => {
});

describe(`icon:`, () => {
it(`the last element is missing `, () => {
it(`the last element is missing`, () => {
const itemsArrayLength = ITEMS.length;
const iconsArrayLength = fixture.debugElement.queryAll(
By.css(`.t-icon`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe(`CalendarMonth`, () => {
});

describe(`year change`, () => {
it(`append year on next`, () => {
it(`append year by onNextYear`, () => {
const year = new TuiYear(TODAY.year);

component.year = year;
Expand All @@ -209,7 +209,7 @@ describe(`CalendarMonth`, () => {
expect(testComponent.year.year).toBe(year.year + 1);
});

it(`append year on next`, () => {
it(`reduce year by onPreviousYear`, () => {
const year = new TuiYear(TODAY.year);

component.year = year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import {
import {configureTestSuite, TuiPageObject} from '@taiga-ui/testing';
import {Observable, of} from 'rxjs';

export function tuiRangeCalendarTestFactory(
control: NgControl | null,
): Observable<TuiDayRange | null> | null {
return control ? tuiControlValue(control) : of(null);
}

describe(`rangeCalendarComponent`, () => {
@Component({
template: `
Expand All @@ -43,7 +37,10 @@ describe(`rangeCalendarComponent`, () => {
{
provide: TUI_CALENDAR_DATE_STREAM,
deps: [[new Optional(), new Self(), NgControl]],
useFactory: tuiRangeCalendarTestFactory,
useFactory: (
control: NgControl | null,
): Observable<TuiDayRange | null> | null =>
control ? tuiControlValue(control) : of(null),
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,6 @@ describe(`InputNumber - backward compatibility for separators`, () => {
});
});

describe(`Format - {d d d,d}`, () => {
configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
TuiInputNumberModule,
ReactiveFormsModule,
],
declarations: [TestComponent],
});
});

beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
testComponent = fixture.componentInstance;
fixture.detectChanges();
component = testComponent.component;
fixture.detectChanges();
inputPO = new TuiNativeInputPO(
fixture,
`tui-primitive-textfield__native-input`,
);
});

it(`comma usage`, () => {
inputPO.sendText(`55666,7777`);
inputPO.focus();

expect(component.computedValue).toBe(`55${CHAR_NO_BREAK_SPACE}666,77`);
});

it(`dot usage`, () => {
inputPO.sendText(`55666.7777`);
inputPO.focus();

expect(component.computedValue).toBe(`55${CHAR_NO_BREAK_SPACE}666,77`);
});
});

describe(`Format - {d,d,d.d}`, () => {
configureTestSuite(() => {
TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe(`InputNumber`, () => {
});

describe(`When decimal === always`, () => {
it(`Adds the number of zeros specified by the precision property when updating Value with an integer`, () => {
it(`Adds the number of zeros specified by the precision property when updating Value (123) with an integer`, () => {
const value = `123`;
const precision = 2;

Expand All @@ -349,7 +349,7 @@ describe(`InputNumber`, () => {
expect(component.computedValue).toBe(`${value},00`);
});

it(`Adds the number of zeros specified by the precision property when updating Value with an integer`, () => {
it(`Adds the number of zeros specified by the precision property when updating Value (0) with an integer`, () => {
const value = `0`;
const precision = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe(`InputPhoneInternational`, () => {
expect(component.countryIsoCode).toBe(TuiCountryIsoCode.UA);
});

it(`should set country code on paste event `, () => {
it(`should set country code on paste event`, () => {
const data = new DataTransfer();

data.setData(`text/plain`, `88005553535`);
Expand All @@ -143,7 +143,7 @@ describe(`InputPhoneInternational`, () => {

describe(`should set KZ country code on paste event`, () => {
for (const phone of [`+7(600)555-3535`, `+7 7272 588300`]) {
it(phone, () => {
it(`${phone}`, () => {
const data = new DataTransfer();

data.setData(`text/plain`, phone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ describe(`InputTime`, () => {
});
});

describe(`Short time input (less than 5 characters, including colon)`, () => {
it(`The value of formControl is passed null`, () => {
component.onValueChange(`11:1`);
fixture.detectChanges();
expect(testComponent.control.value).toBeNull();
});
});

describe(`Keyboard control`, () => {
beforeEach(async () => fixture.whenStable());

Expand Down
Loading

0 comments on commit 05123fa

Please sign in to comment.