Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the eslintConfig property from the package.json and copy some of the overridden rules to this file.

Also the extends can be: require.resolve('kcd-scripts/eslint')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it was in the package.json. I was wondering where that was coming from.

Also the extends can be: require.resolve('kcd-scripts/eslint')

👍

extends: require.resolve('kcd-scripts/dist/config/eslintrc.js'),
env: {
browser: false,
},
}
1 change: 1 addition & 0 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {configure} from '../config'
import {render, renderIntoDocument} from './helpers/test-utils'
import document from './helpers/document'

beforeEach(() => {
document.defaultView.Cypress = null
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import document from './helpers/document'
import {fireEvent} from '..'
const window = document.defaultView

const eventTypes = [
{
Expand Down Expand Up @@ -219,7 +221,7 @@ test('fires shortcut events on Window', () => {
})

test('throws a useful error message when firing events on non-existent nodes', () => {
expect(() => fireEvent(undefined, new MouseEvent('click'))).toThrow(
expect(() => fireEvent(undefined, new window.MouseEvent('click'))).toThrow(
'Unable to fire a "click" event - please provide a DOM element.',
)
})
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
wait,
fireEvent,
} from '../'
import document from './helpers/document'

function getExampleDOM() {
// This is just a raw example of setting up some DOM
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/get-queries-for-element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {getQueriesForElement} from '../get-queries-for-element'
import document from './helpers/document'
import {queries} from '..'

test('uses default queries', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {getDocument, newMutationObserver} from '../helpers'
import document from './helpers/document'
const window = document.defaultView

test('returns global document if exists', () => {
expect(getDocument()).toBe(document)
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/helpers/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://github.com/testing-library/jest-dom/blob/v4.1.2/src/__tests__/helpers/document.js
if (global.document) {
module.exports = global.document
} else {
const {JSDOM} = require('jsdom')
const {window} = new JSDOM()

module.exports = window.document
}
1 change: 1 addition & 0 deletions src/__tests__/helpers/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {getQueriesForElement} from '../../get-queries-for-element'
import document from './document'

function render(html, {container = document.createElement('div')} = {}) {
container.innerHTML = html
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/pretty-dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {prettyDOM, logDOM} from '../pretty-dom'
import {render, renderIntoDocument} from './helpers/test-utils'
import document from './helpers/document'

beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {})
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/wait-for-dom-change.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {renderIntoDocument} from './helpers/test-utils'
import document from './helpers/document'
const window = document.defaultView

function importModule() {
return require('../').waitForDomChange
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/wait-for-element-to-be-removed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {renderIntoDocument} from './helpers/test-utils'
import document from './helpers/document'

const window = document.defaultView

function importModule() {
return require('../').waitForElementToBeRemoved
Expand Down
13 changes: 12 additions & 1 deletion src/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import {prettyDOM} from './pretty-dom'

const elementRoleList = buildElementRoleList(elementRoles)

/**
* @param {Node} node -
* @returns {Window} -
*/
function defaultViewOf(node) {
// is null when node is already the document
return node.ownerDocument === null
? node.defaultView
: node.ownerDocument.defaultView
}

/**
* Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
* which should only be used for elements with a non-presentational role i.e.
Expand All @@ -15,7 +26,7 @@ const elementRoleList = buildElementRoleList(elementRoles)
* @returns {boolean} true if excluded, otherwise false
*/
function isInaccessible(element) {
const window = element.ownerDocument.defaultView
const window = defaultViewOf(element)
const computedStyle = window.getComputedStyle(element)
// since visibility is inherited we can exit early
if (computedStyle.visibility === 'hidden') {
Expand Down
1 change: 0 additions & 1 deletion tests/jest.config.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ module.exports = {
'/__tests__/',
'/__node_tests__/',
],
testMatch: ['**/__node_tests__/**.js'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the existing file(s) to regular test files (or just remove them?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about that when we're getting closer to green tests 😄

}