Skip to content

Commit

Permalink
chore: modernize things (lint TS)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Nov 14, 2020
1 parent 3679627 commit 0105ad3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"pretty-format": "^26.6.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/jest-dom": "^5.11.6",
"@types/estree": "0.0.45",
"dtslint": "^4.0.5",
"jest-in-case": "^1.0.2",
"jest-serializer-ansi": "^1.0.3",
"jest-watch-select-projects": "^2.0.0",
"jsdom": "^16.4.0",
"kcd-scripts": "^6.7.0",
"kcd-scripts": "^7.0.3",
"typescript": "^4.0.5"
},
"eslintConfig": {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ test('should get the first label with aria-labelledby contains multiple ids', ()
})

test('should suggest hidden option if element is not in the accessibilty tree', () => {
console.warn.mockImplementation(() => {})

const {container} = renderIntoDocument(`
<input type="text" aria-hidden=true />
`)
Expand Down
6 changes: 6 additions & 0 deletions types/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
"one-var": "off",
"@typescript-eslint/no-explicit-any": "off" // let's do better in the future
}
}
32 changes: 18 additions & 14 deletions types/__tests__/type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
findByRole,
} = queries

async function testQueries() {
export async function testQueries() {
// element queries
const element = document.createElement('div')
getByText(element, 'foo')
Expand All @@ -46,7 +46,7 @@ async function testQueries() {
await screen.findAllByText('bar', undefined, {timeout: 10})
}

async function testQueryHelpers() {
export async function testQueryHelpers() {
const element = document.createElement('div')
const includesAutomationId = (content: string, automationId: string) =>
content.split(/\s+/).some(id => id === automationId)
Expand Down Expand Up @@ -78,16 +78,16 @@ async function testQueryHelpers() {
queryByAutomationId(element, 'id')
getAllByAutomationId(element, 'id')
getByAutomationId(element, ['id', 'automationId'])
findAllByAutomationId(element, 'id', {}, {timeout: 1000})
findByAutomationId(element, 'id', {}, {timeout: 1000})
await findAllByAutomationId(element, 'id', {}, {timeout: 1000})
await findByAutomationId(element, 'id', {}, {timeout: 1000})
// test optional params too
findAllByAutomationId(element, 'id', {})
findByAutomationId(element, 'id', {})
findAllByAutomationId(element, 'id')
findByAutomationId(element, 'id')
await findAllByAutomationId(element, 'id', {})
await findByAutomationId(element, 'id', {})
await findAllByAutomationId(element, 'id')
await findByAutomationId(element, 'id')
}

async function testByRole() {
export async function testByRole() {
const element = document.createElement('button')
element.setAttribute('aria-hidden', 'true')

Expand Down Expand Up @@ -115,8 +115,7 @@ async function testByRole() {
console.assert(queryByRole(element, 'button', {name: /^Log/}) === null)
console.assert(
queryByRole(element, 'button', {
name: (name, element) =>
name === 'Login' && element.hasAttribute('disabled'),
name: (name, el) => name === 'Login' && el.hasAttribute('disabled'),
}) === null,
)

Expand All @@ -127,12 +126,12 @@ async function testByRole() {
console.assert(screen.queryByRole(/foo/) === null)
}

function testA11yHelper() {
export function testA11yHelper() {
const element = document.createElement('svg')
console.assert(!isInaccessible(element))
}

function eventTest() {
export function eventTest() {
fireEvent.popState(window, {
location: 'http://www.example.com/?page=1',
state: {page: 1},
Expand All @@ -156,7 +155,7 @@ function eventTest() {
fireEvent(element, customEvent)
}

async function testWaitFors() {
export async function testWaitFors() {
const element = document.createElement('div')

await waitFor(() => getByText(element, 'apple'))
Expand All @@ -181,3 +180,8 @@ async function testWaitFors() {

await waitFor(async () => {})
}

/*
eslint
@typescript-eslint/no-unnecessary-condition: "off",
*/
2 changes: 1 addition & 1 deletion types/screen.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {OptionsReceived} from 'pretty-format'
import {BoundFunctions, Queries} from './get-queries-for-element'
import * as queries from './queries'
import {OptionsReceived} from 'pretty-format'

export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q> & {
/**
Expand Down

0 comments on commit 0105ad3

Please sign in to comment.