-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
265 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as DomTestingLibrary from '@testing-library/dom' | ||
|
||
globalThis.DomTestingLibrary = DomTestingLibrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"@testing-library/dom": "^10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
// this is pretty helpful: | ||
// https://codesandbox.io/s/quizzical-worker-eo909 | ||
|
||
import { configure, getConfig } from '@testing-library/dom' | ||
|
||
export {render, setup} from './setup' | ||
export {addEventListener, addListeners} from './listeners' | ||
|
||
export function isJsdomEnv() { | ||
return window.navigator.userAgent.includes(' jsdom/') | ||
} | ||
|
||
/** | ||
* Reset the DTL wrappers | ||
* | ||
* Framework libraries configure the wrappers in DTL as side effect when being imported. | ||
* In the Toolbox testenvs that side effect is triggered by including the library as a setup file. | ||
*/ | ||
export function resetWrappers() { | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const { asyncWrapper, eventWrapper } = {...getConfig()} | ||
|
||
configure({ | ||
asyncWrapper: (cb) => cb(), | ||
eventWrapper: (cb) => cb(), | ||
}) | ||
|
||
return () => configure({ | ||
asyncWrapper, | ||
eventWrapper, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {isJsdomEnv, render} from '#testHelpers' | ||
|
||
test('window.getComputedStyle returns resolved inherited style in browser', () => { | ||
const {element, xpathNode} = render(` | ||
<div style='pointer-events: none'> | ||
<button></button> | ||
</div>`) | ||
|
||
expect(window.getComputedStyle(element)).toHaveProperty( | ||
'pointer-events', | ||
'none', | ||
) | ||
expect(window.getComputedStyle(xpathNode('//button'))).toHaveProperty( | ||
'pointer-events', | ||
isJsdomEnv() ? '' : 'none', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {isJsdomEnv, render} from '#testHelpers' | ||
import {waitFor} from '@testing-library/dom' | ||
|
||
test('`Selection.setBaseAndExtent()` resets input selection in browser', async () => { | ||
const {element} = render<HTMLInputElement>(`<input value="foo"/>`, { | ||
selection: {focusOffset: 3}, | ||
}) | ||
expect(element.selectionStart).toBe(3) | ||
|
||
element.ownerDocument.getSelection()?.setBaseAndExtent(element, 0, element, 0) | ||
|
||
expect(element.selectionStart).toBe(isJsdomEnv() ? 3 : 0) | ||
}) | ||
|
||
test('events are not dispatched on same microtask in browser', async () => { | ||
const {element} = render<HTMLInputElement>(`<input value="foo"/>`) | ||
const onSelect = mocks.fn() | ||
element.addEventListener('select', onSelect) | ||
|
||
element.setSelectionRange(1, 2) | ||
|
||
expect(onSelect).toBeCalledTimes(isJsdomEnv() ? 1 : 0) | ||
|
||
await waitFor(() => expect(onSelect).toBeCalledTimes(1)) | ||
}) | ||
|
||
test('`HTMLInputElement.focus()` in contenteditable changes `Selection` in browser', () => { | ||
const {element, xpathNode} = render<HTMLInputElement>( | ||
`<div contenteditable="true"><input/></div><span></span>`, | ||
{ | ||
selection: { | ||
focusNode: '//span', | ||
}, | ||
}, | ||
) | ||
|
||
expect(element.ownerDocument.getSelection()).toHaveProperty( | ||
'anchorNode', | ||
xpathNode('//span'), | ||
) | ||
|
||
xpathNode('//input').focus() | ||
|
||
expect(element.ownerDocument.getSelection()).toHaveProperty( | ||
'anchorNode', | ||
isJsdomEnv() ? xpathNode('//span') : element, | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.