From fcf547a1ec5167f8924de8acc3c2fa579a20bb7f Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Sat, 24 Apr 2021 21:06:44 +0200 Subject: [PATCH 1/2] chore: fix linting problems --- .eslintrc.json | 9 +-------- angular.json | 14 +++----------- apps/example-app/.eslintrc.json | 4 ++++ projects/jest-utils/.eslintrc.json | 4 ++-- projects/jest-utils/tests/create-mock.spec.ts | 4 ++-- projects/testing-library/.eslintrc.json | 4 ++-- .../testing-library/src/lib/testing-library.ts | 1 + .../testing-library/tests/auto-cleanup.spec.ts | 4 ++-- projects/testing-library/tests/config.spec.ts | 2 +- projects/testing-library/tests/debug.spec.ts | 6 +++--- .../testing-library/tests/detect-changes.spec.ts | 2 +- projects/testing-library/tests/find-by.spec.ts | 2 +- projects/testing-library/tests/fire-event.spec.ts | 2 +- projects/testing-library/tests/navigate.spec.ts | 2 +- .../tests/providers/component-provider.spec.ts | 2 +- .../tests/providers/module-provider.spec.ts | 2 +- .../testing-library/tests/render-template.spec.ts | 4 +--- projects/testing-library/tests/render.spec.ts | 4 ++-- projects/testing-library/tests/rerender.spec.ts | 6 +++--- .../tests/wait-for-element-to-be-removed.spec.ts | 2 +- projects/testing-library/tests/wait-for.spec.ts | 2 +- 21 files changed, 35 insertions(+), 47 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b740f815..cde0f6cf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -49,7 +49,7 @@ ], "@typescript-eslint/no-unused-expressions": "error", "@typescript-eslint/prefer-function-type": "error", - "@typescript-eslint/quotes": ["error", "single"], + "@typescript-eslint/quotes": "off", "@typescript-eslint/type-annotation-spacing": "error", "@typescript-eslint/no-explicit-any": "off", "arrow-body-style": "error", @@ -105,13 +105,6 @@ ] } }, - { - "files": ["*.spec.ts"], - "extends": ["plugin:testing-library/angular", "plugin:jest-dom/recommended"], - "rules": { - "testing-library/prefer-explicit-assert": "error" - } - }, { "files": ["*.html"], "rules": {} diff --git a/angular.json b/angular.json index 46f51c32..376b9ca6 100644 --- a/angular.json +++ b/angular.json @@ -71,7 +71,7 @@ "lint": { "builder": "@nrwl/linter:eslint", "options": { - "lintFilePatterns": ["apps/example-app/src/**/*.ts", "apps/example-app/src/**/*.html"] + "lintFilePatterns": ["apps/example-app/**/*.ts", "apps/example-app/**/*.html"] } }, "test": { @@ -106,11 +106,7 @@ "lint": { "builder": "@nrwl/linter:eslint", "options": { - "lintFilePatterns": [ - "projects/testing-library/src/**/*.ts", - "projects/testing-library/src/**/*.html", - "projects/testing-library/src/**/*.html" - ] + "lintFilePatterns": ["projects/testing-library/**/*.ts", "projects/testing-library/**/*.html"] } }, "build": { @@ -159,11 +155,7 @@ "lint": { "builder": "@nrwl/linter:eslint", "options": { - "lintFilePatterns": [ - "projects/jest-utils/src/**/*.ts", - "projects/jest-utils/src/**/*.html", - "projects/jest-utils/src/**/*.html" - ] + "lintFilePatterns": ["projects/jest-utils/**/*.ts", "projects/jest-utils/**/*.html"] } }, "build": { diff --git a/apps/example-app/.eslintrc.json b/apps/example-app/.eslintrc.json index 2e1ae78b..38181327 100644 --- a/apps/example-app/.eslintrc.json +++ b/apps/example-app/.eslintrc.json @@ -28,6 +28,10 @@ }, "plugins": ["@angular-eslint/eslint-plugin", "@typescript-eslint"] }, + { + "files": ["*.spec.ts"], + "extends": ["plugin:testing-library/angular", "plugin:jest-dom/recommended"] + }, { "files": ["*.html"], "extends": ["plugin:@nrwl/nx/angular-template"], diff --git a/projects/jest-utils/.eslintrc.json b/projects/jest-utils/.eslintrc.json index 4687290e..90906e5b 100644 --- a/projects/jest-utils/.eslintrc.json +++ b/projects/jest-utils/.eslintrc.json @@ -13,7 +13,7 @@ "error", { "type": "attribute", - "prefix": "lib", + "prefix": "atl", "style": "camelCase" } ], @@ -21,7 +21,7 @@ "error", { "type": "element", - "prefix": "lib", + "prefix": "atl", "style": "kebab-case" } ] diff --git a/projects/jest-utils/tests/create-mock.spec.ts b/projects/jest-utils/tests/create-mock.spec.ts index 9494f8cb..6e313a22 100644 --- a/projects/jest-utils/tests/create-mock.spec.ts +++ b/projects/jest-utils/tests/create-mock.spec.ts @@ -1,8 +1,8 @@ import { Component } from '@angular/core'; import { TestBed } from '@angular/core/testing'; +import { fireEvent, render } from '@testing-library/angular'; import { createMock, provideMock, Mock } from '../src/public_api'; -import { render, fireEvent } from '../../testing-library/src/public_api'; class FixtureService { constructor(private foo: string, public bar: string) {} @@ -13,7 +13,7 @@ class FixtureService { } @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` `, }) export class FixtureComponent { diff --git a/projects/testing-library/.eslintrc.json b/projects/testing-library/.eslintrc.json index f3960e87..a76c4ce4 100644 --- a/projects/testing-library/.eslintrc.json +++ b/projects/testing-library/.eslintrc.json @@ -13,7 +13,7 @@ "error", { "type": "attribute", - "prefix": "lib", + "prefix": ["atl"], "style": "camelCase" } ], @@ -21,7 +21,7 @@ "error", { "type": "element", - "prefix": "lib", + "prefix": ["atl"], "style": "kebab-case" } ] diff --git a/projects/testing-library/src/lib/testing-library.ts b/projects/testing-library/src/lib/testing-library.ts index fe3a22ca..b02c905d 100644 --- a/projects/testing-library/src/lib/testing-library.ts +++ b/projects/testing-library/src/lib/testing-library.ts @@ -358,6 +358,7 @@ if (typeof afterEach === 'function' && !process.env.ATL_SKIP_AUTO_CLEANUP) { }); } +// TODO: rename to `atl-wrapper-component` // eslint-disable-next-line @angular-eslint/component-selector @Component({ selector: 'wrapper-component', template: '' }) class WrapperComponent {} diff --git a/projects/testing-library/tests/auto-cleanup.spec.ts b/projects/testing-library/tests/auto-cleanup.spec.ts index 13f0de8c..a22b646c 100644 --- a/projects/testing-library/tests/auto-cleanup.spec.ts +++ b/projects/testing-library/tests/auto-cleanup.spec.ts @@ -2,8 +2,8 @@ import { Component, Input } from '@angular/core'; import { render } from '../src/public_api'; @Component({ - selector: 'fixture', - template: ` Hello {{ name }}! `, + selector: 'atl-fixture', + template: `Hello {{ name }}!`, }) class FixtureComponent { @Input() name: string; diff --git a/projects/testing-library/tests/config.spec.ts b/projects/testing-library/tests/config.spec.ts index 06a79915..ccd004f5 100644 --- a/projects/testing-library/tests/config.spec.ts +++ b/projects/testing-library/tests/config.spec.ts @@ -4,7 +4,7 @@ import { render, configure } from '../src/public_api'; import { ReactiveFormsModule, FormBuilder } from '@angular/forms'; @Component({ - selector: 'app-fixture', + selector: 'atl-fixture', template: `
diff --git a/projects/testing-library/tests/debug.spec.ts b/projects/testing-library/tests/debug.spec.ts index 3a868989..29845d3b 100644 --- a/projects/testing-library/tests/debug.spec.ts +++ b/projects/testing-library/tests/debug.spec.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import { render } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: `

rawr

@@ -11,7 +11,7 @@ import { render } from '../src/public_api'; class FixtureComponent {} test('debug', async () => { - jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'log').mockImplementation(); const { debug } = await render(FixtureComponent); debug(); @@ -21,7 +21,7 @@ test('debug', async () => { }); test('debug allows to be called with an element', async () => { - jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'log').mockImplementation(); const { debug, getByTestId } = await render(FixtureComponent); const btn = getByTestId('btn'); diff --git a/projects/testing-library/tests/detect-changes.spec.ts b/projects/testing-library/tests/detect-changes.spec.ts index e74c402f..5dae8254 100644 --- a/projects/testing-library/tests/detect-changes.spec.ts +++ b/projects/testing-library/tests/detect-changes.spec.ts @@ -5,7 +5,7 @@ import { delay } from 'rxjs/operators'; import { render, fireEvent } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` diff --git a/projects/testing-library/tests/find-by.spec.ts b/projects/testing-library/tests/find-by.spec.ts index 791fa215..c55430ee 100644 --- a/projects/testing-library/tests/find-by.spec.ts +++ b/projects/testing-library/tests/find-by.spec.ts @@ -4,7 +4,7 @@ import { render, screen } from '../src/public_api'; import { mapTo } from 'rxjs/operators'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: `
{{ result | async }}
`, }) class FixtureComponent { diff --git a/projects/testing-library/tests/fire-event.spec.ts b/projects/testing-library/tests/fire-event.spec.ts index 1c93bc59..7a9a7f0d 100644 --- a/projects/testing-library/tests/fire-event.spec.ts +++ b/projects/testing-library/tests/fire-event.spec.ts @@ -2,7 +2,7 @@ import { Component } from '@angular/core'; import { render, fireEvent } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` `, }) class FixtureComponent {} diff --git a/projects/testing-library/tests/navigate.spec.ts b/projects/testing-library/tests/navigate.spec.ts index d26dde3b..ca0d8ad8 100644 --- a/projects/testing-library/tests/navigate.spec.ts +++ b/projects/testing-library/tests/navigate.spec.ts @@ -4,7 +4,7 @@ import { Router } from '@angular/router'; import { render } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ``, }) class FixtureComponent {} diff --git a/projects/testing-library/tests/providers/component-provider.spec.ts b/projects/testing-library/tests/providers/component-provider.spec.ts index e7c88c8a..30fe2d37 100644 --- a/projects/testing-library/tests/providers/component-provider.spec.ts +++ b/projects/testing-library/tests/providers/component-provider.spec.ts @@ -50,7 +50,7 @@ export class Service { } @Component({ - selector: 'fixture-component', + selector: 'atl-fixture', template: '{{service.foo()}}', providers: [Service], }) diff --git a/projects/testing-library/tests/providers/module-provider.spec.ts b/projects/testing-library/tests/providers/module-provider.spec.ts index 6270795f..2256d02b 100644 --- a/projects/testing-library/tests/providers/module-provider.spec.ts +++ b/projects/testing-library/tests/providers/module-provider.spec.ts @@ -60,7 +60,7 @@ export class Service { } @Component({ - selector: 'fixture-component', + selector: 'atl-fixture', template: '{{service.foo()}}', }) export class FixtureComponent { diff --git a/projects/testing-library/tests/render-template.spec.ts b/projects/testing-library/tests/render-template.spec.ts index 1bc4e30d..5e6f4f73 100644 --- a/projects/testing-library/tests/render-template.spec.ts +++ b/projects/testing-library/tests/render-template.spec.ts @@ -1,5 +1,3 @@ -/* eslint-disable testing-library/no-container */ -/* eslint-disable testing-library/render-result-naming-convention */ import { Directive, HostListener, ElementRef, Input, Output, EventEmitter, Component } from '@angular/core'; import { render, fireEvent } from '../src/public_api'; @@ -70,7 +68,7 @@ test('the directive renders (compatibility with the deprecated signature)', asyn expect(component.container.querySelector('[onoff]')).toBeInTheDocument(); }); -test.only('uses the default props', async () => { +test('uses the default props', async () => { const component = await render('
', { declarations: [OnOffDirective], }); diff --git a/projects/testing-library/tests/render.spec.ts b/projects/testing-library/tests/render.spec.ts index 01fe9f0c..aeac9789 100644 --- a/projects/testing-library/tests/render.spec.ts +++ b/projects/testing-library/tests/render.spec.ts @@ -13,7 +13,7 @@ import { TestBed } from '@angular/core/testing'; import { render, fireEvent } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` @@ -83,7 +83,7 @@ describe('animationModule', () => { describe('Angular component life-cycle hooks', () => { @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` {{ name }} `, }) class FixtureWithNgOnChangesComponent implements OnInit, OnChanges { diff --git a/projects/testing-library/tests/rerender.spec.ts b/projects/testing-library/tests/rerender.spec.ts index 5f7d152a..f9f82ca0 100644 --- a/projects/testing-library/tests/rerender.spec.ts +++ b/projects/testing-library/tests/rerender.spec.ts @@ -3,7 +3,7 @@ import { screen } from '@testing-library/dom'; import { render } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: ` {{ name }} `, }) class FixtureComponent { @@ -23,7 +23,7 @@ test('will rerender the component with updated props', async () => { }); @Component({ - selector: 'fixture-onchanges', + selector: 'atl-fixture', template: ` {{ name }} `, }) class FixtureWithNgOnChangesComponent implements OnChanges { @@ -54,7 +54,7 @@ test('will call ngOnChanges on rerender', async () => { @Component({ changeDetection: ChangeDetectionStrategy.OnPush, - selector: 'fixture-onpush', + selector: 'atl-fixture', template: `
Number
`, }) class FixtureWithOnPushComponent { diff --git a/projects/testing-library/tests/wait-for-element-to-be-removed.spec.ts b/projects/testing-library/tests/wait-for-element-to-be-removed.spec.ts index c3859c62..0995c8ca 100644 --- a/projects/testing-library/tests/wait-for-element-to-be-removed.spec.ts +++ b/projects/testing-library/tests/wait-for-element-to-be-removed.spec.ts @@ -3,7 +3,7 @@ import { render, screen, waitForElementToBeRemoved } from '../src/public_api'; import { timer } from 'rxjs'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: `
👋
`, }) class FixtureComponent implements OnInit { diff --git a/projects/testing-library/tests/wait-for.spec.ts b/projects/testing-library/tests/wait-for.spec.ts index 082358be..ce80b08d 100644 --- a/projects/testing-library/tests/wait-for.spec.ts +++ b/projects/testing-library/tests/wait-for.spec.ts @@ -3,7 +3,7 @@ import { timer } from 'rxjs'; import { render, screen, fireEvent, waitFor as waitForATL } from '../src/public_api'; @Component({ - selector: 'fixture', + selector: 'atl-fixture', template: `
{{ result }}
From e21d8b5bdc017fa4eba1e2e5988b077ff43282e4 Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Sat, 24 Apr 2021 21:27:01 +0200 Subject: [PATCH 2/2] chore: add jest eslint --- .eslintrc.json | 8 ++++++++ apps/example-app/src/app/issues/issue-106.spec.ts | 2 +- package.json | 3 ++- projects/jest-utils/tests/create-mock.spec.ts | 3 ++- projects/testing-library/tests/issues/188.spec.ts | 2 +- projects/testing-library/tests/issues/67.spec.ts | 2 +- .../tests/providers/component-provider.spec.ts | 4 ++-- .../tests/providers/module-provider.spec.ts | 4 ++-- projects/testing-library/tests/render-template.spec.ts | 8 ++++---- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index cde0f6cf..85f44c38 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -105,6 +105,14 @@ ] } }, + { + "files": ["*.spec.ts"], + "extends": ["plugin:jest/recommended"], + "rules": { + "jest/no-done-callback": "off", + "jest/expect-expect": "off" + } + }, { "files": ["*.html"], "rules": {} diff --git a/apps/example-app/src/app/issues/issue-106.spec.ts b/apps/example-app/src/app/issues/issue-106.spec.ts index 52bc81e1..0ac749a8 100644 --- a/apps/example-app/src/app/issues/issue-106.spec.ts +++ b/apps/example-app/src/app/issues/issue-106.spec.ts @@ -6,7 +6,7 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/angular'; template: `
Here I am
`, }) -export class TestSelectComponent { +class TestSelectComponent { showSubj = new BehaviorSubject(false); show$ = this.showSubj.asObservable(); diff --git a/package.json b/package.json index 0490d1c6..1c02d26d 100644 --- a/package.json +++ b/package.json @@ -66,9 +66,10 @@ "@typescript-eslint/eslint-plugin": "4.22.0", "@typescript-eslint/parser": "4.22.0", "cpy-cli": "^3.1.1", - "eslint": "7.24.0", + "eslint": "^7.25.0", "eslint-config-prettier": "8.2.0", "eslint-plugin-import": "latest", + "eslint-plugin-jest": "^24.3.5", "eslint-plugin-jest-dom": "3.8.0", "eslint-plugin-testing-library": "^4.0.1", "husky": "^4.2.5", diff --git a/projects/jest-utils/tests/create-mock.spec.ts b/projects/jest-utils/tests/create-mock.spec.ts index 6e313a22..8b814fe6 100644 --- a/projects/jest-utils/tests/create-mock.spec.ts +++ b/projects/jest-utils/tests/create-mock.spec.ts @@ -16,7 +16,7 @@ class FixtureService { selector: 'atl-fixture', template: ` `, }) -export class FixtureComponent { +class FixtureComponent { constructor(private service: FixtureService) {} print() { @@ -39,6 +39,7 @@ it('provides a mock service', async () => { expect(service.print).toHaveBeenCalledTimes(1); }); +// eslint-disable-next-line jest/expect-expect it('is possible to write a mock implementation', async (done) => { const { getByText } = await render(FixtureComponent, { providers: [provideMock(FixtureService)], diff --git a/projects/testing-library/tests/issues/188.spec.ts b/projects/testing-library/tests/issues/188.spec.ts index c972aad0..cb430bb4 100644 --- a/projects/testing-library/tests/issues/188.spec.ts +++ b/projects/testing-library/tests/issues/188.spec.ts @@ -5,7 +5,7 @@ import { render } from '../../src/public_api'; @Component({ template: `

Hello {{ formattedName }}

`, }) -export class BugOnChangeComponent implements OnChanges { +class BugOnChangeComponent implements OnChanges { @Input() name: string; formattedName: string; diff --git a/projects/testing-library/tests/issues/67.spec.ts b/projects/testing-library/tests/issues/67.spec.ts index 1e4dff75..243dbf4d 100644 --- a/projects/testing-library/tests/issues/67.spec.ts +++ b/projects/testing-library/tests/issues/67.spec.ts @@ -13,7 +13,7 @@ import { render } from '../../src/public_api';
`, }) -export class BugGetByLabelTextComponent {} +class BugGetByLabelTextComponent {} it('first step to reproduce the bug: skip this test to avoid the error or remove the for attribute of label', async () => { expect(await render(BugGetByLabelTextComponent)).toBeDefined(); diff --git a/projects/testing-library/tests/providers/component-provider.spec.ts b/projects/testing-library/tests/providers/component-provider.spec.ts index 30fe2d37..723a0317 100644 --- a/projects/testing-library/tests/providers/component-provider.spec.ts +++ b/projects/testing-library/tests/providers/component-provider.spec.ts @@ -43,7 +43,7 @@ test('shows the provided service value with template syntax', async () => { }); @Injectable() -export class Service { +class Service { foo() { return 'foo'; } @@ -54,6 +54,6 @@ export class Service { template: '{{service.foo()}}', providers: [Service], }) -export class FixtureComponent { +class FixtureComponent { constructor(public service: Service) {} } diff --git a/projects/testing-library/tests/providers/module-provider.spec.ts b/projects/testing-library/tests/providers/module-provider.spec.ts index 2256d02b..82dbee64 100644 --- a/projects/testing-library/tests/providers/module-provider.spec.ts +++ b/projects/testing-library/tests/providers/module-provider.spec.ts @@ -53,7 +53,7 @@ test('shows the provided service value with template syntax', async () => { }); @Injectable() -export class Service { +class Service { foo() { return 'foo'; } @@ -63,6 +63,6 @@ export class Service { selector: 'atl-fixture', template: '{{service.foo()}}', }) -export class FixtureComponent { +class FixtureComponent { constructor(public service: Service) {} } diff --git a/projects/testing-library/tests/render-template.spec.ts b/projects/testing-library/tests/render-template.spec.ts index 5e6f4f73..73420211 100644 --- a/projects/testing-library/tests/render-template.spec.ts +++ b/projects/testing-library/tests/render-template.spec.ts @@ -6,7 +6,7 @@ import { render, fireEvent } from '../src/public_api'; // eslint-disable-next-line @angular-eslint/directive-selector selector: '[onOff]', }) -export class OnOffDirective { +class OnOffDirective { @Input() on = 'on'; @Input() off = 'off'; @Output() clicked = new EventEmitter(); @@ -25,7 +25,7 @@ export class OnOffDirective { // eslint-disable-next-line @angular-eslint/directive-selector selector: '[update]', }) -export class UpdateInputDirective { +class UpdateInputDirective { @Input() set update(value: any) { this.el.nativeElement.textContent = value; @@ -39,7 +39,7 @@ export class UpdateInputDirective { selector: 'greeting', template: 'Hello {{ name }}!', }) -export class GreetingComponent { +class GreetingComponent { @Input() name = 'World'; } @@ -57,7 +57,7 @@ test('the component renders', async () => { }); expect(component.container.querySelector('greeting')).toBeInTheDocument(); - expect(component.getByText('Hello Angular!')); + expect(component.getByText('Hello Angular!')).toBeInTheDocument(); }); test('the directive renders (compatibility with the deprecated signature)', async () => {