Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make element='body' viable in solidjs
- Loading branch information
Showing
14 changed files
with
179 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { builtinEnvironments } from 'vitest/environments'; | ||
export default { | ||
name: String(performance.now()), | ||
...builtinEnvironments.jsdom, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
packages/overlayscrollbars-react/test/body/OverlayScrollbarsComponent.test.tsx
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,61 @@ | ||
import { describe, test, afterEach, expect, vi } from 'vitest'; | ||
import { render, cleanup } from '@testing-library/react'; | ||
import { OverlayScrollbarsComponent } from '~/overlayscrollbars-react'; | ||
|
||
const getComputedStyleOriginal = window.getComputedStyle; | ||
vi.stubGlobal( | ||
'getComputedStyle', | ||
vi.fn(function (...args: Parameters<typeof getComputedStyleOriginal>) { | ||
const result: CSSStyleDeclaration = getComputedStyleOriginal.apply( | ||
// @ts-ignore | ||
this, | ||
args | ||
); | ||
const getPropertyValueOriginal = result.getPropertyValue; | ||
result.getPropertyValue = function (prop: string) { | ||
if (prop === 'scrollbar-width' || prop === 'scrollbarWidth') { | ||
return 'none'; | ||
} | ||
return getPropertyValueOriginal.call(this, prop); | ||
}; | ||
return result; | ||
}) | ||
); | ||
|
||
vi.useFakeTimers({ | ||
toFake: [ | ||
'requestAnimationFrame', | ||
'cancelAnimationFrame', | ||
'requestIdleCallback', | ||
'cancelIdleCallback', | ||
], | ||
}); | ||
|
||
describe('OverlayScrollbarsComponent', () => { | ||
afterEach(() => cleanup()); | ||
|
||
test('body', () => { | ||
const htmlElement = document.documentElement; | ||
const { unmount } = render( | ||
<OverlayScrollbarsComponent element="body"> | ||
<section id="body" /> | ||
</OverlayScrollbarsComponent>, | ||
{ | ||
baseElement: htmlElement, | ||
container: htmlElement, | ||
wrapper: ({ children }) => { | ||
document.body.remove(); | ||
return children; | ||
}, | ||
} | ||
); | ||
|
||
expect(htmlElement).toHaveAttribute('data-overlayscrollbars'); | ||
expect(htmlElement.querySelector('body')).toHaveAttribute('data-overlayscrollbars-initialize'); | ||
expect(htmlElement.querySelector('body')).not.toBeEmptyDOMElement(); | ||
expect(htmlElement.querySelector('body')?.firstElementChild!.tagName).toBe('SECTION'); | ||
expect(htmlElement.querySelector('body')?.firstElementChild).toHaveAttribute('id', 'body'); | ||
|
||
unmount(); | ||
}); | ||
}); |
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,14 @@ | ||
import { fileURLToPath } from 'url'; | ||
import { mergeConfig } from 'vite'; | ||
import vitestConfig from '@~local/config/vitest'; | ||
import viteConfig from './vite.config.mjs'; | ||
|
||
export default mergeConfig(viteConfig, vitestConfig); | ||
export default mergeConfig(viteConfig, { | ||
...vitestConfig, | ||
test: { | ||
...vitestConfig.test, | ||
environmentMatchGlobs: [ | ||
['test/body/*', fileURLToPath(import.meta.resolve('@~local/config/vitest.new-jsdom.env'))], | ||
], | ||
}, | ||
}); |
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
55 changes: 55 additions & 0 deletions
55
packages/overlayscrollbars-solid/test/body/OverlayScrollbarsComponent.test.tsx
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,55 @@ | ||
import { describe, test, afterEach, expect, vi } from 'vitest'; | ||
import { render, cleanup } from 'solid-testing-library'; | ||
import { OverlayScrollbarsComponent } from '~/overlayscrollbars-solid'; | ||
|
||
const getComputedStyleOriginal = window.getComputedStyle; | ||
vi.stubGlobal( | ||
'getComputedStyle', | ||
vi.fn(function (...args: Parameters<typeof getComputedStyleOriginal>) { | ||
const result: CSSStyleDeclaration = getComputedStyleOriginal.apply( | ||
// @ts-ignore | ||
this, | ||
args | ||
); | ||
const getPropertyValueOriginal = result.getPropertyValue; | ||
result.getPropertyValue = function (prop: string) { | ||
if (prop === 'scrollbar-width' || prop === 'scrollbarWidth') { | ||
return 'none'; | ||
} | ||
return getPropertyValueOriginal.call(this, prop); | ||
}; | ||
return result; | ||
}) | ||
); | ||
|
||
describe('OverlayScrollbarsComponent', () => { | ||
afterEach(() => cleanup()); | ||
|
||
test('body', async () => { | ||
const htmlElement = document.documentElement; | ||
|
||
const { unmount } = render( | ||
() => ( | ||
<OverlayScrollbarsComponent element="body"> | ||
<section id="body" /> | ||
</OverlayScrollbarsComponent> | ||
), | ||
{ | ||
baseElement: htmlElement, | ||
container: htmlElement, | ||
wrapper: ({ children }) => { | ||
document.body.remove(); | ||
return children; | ||
}, | ||
} | ||
); | ||
|
||
expect(htmlElement).toHaveAttribute('data-overlayscrollbars'); | ||
expect(htmlElement.querySelector('body')).toHaveAttribute('data-overlayscrollbars-initialize'); | ||
expect(htmlElement.querySelector('body')).not.toBeEmptyDOMElement(); | ||
expect(htmlElement.querySelector('body')?.firstElementChild!.tagName).toBe('SECTION'); | ||
expect(htmlElement.querySelector('body')?.firstElementChild).toHaveAttribute('id', 'body'); | ||
|
||
unmount(); | ||
}); | ||
}); |
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