forked from ZeeCoder/use-resize-observer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added real browser tests, including ie11
- Loading branch information
Showing
16 changed files
with
188 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ yarn-error.log* | |
dist | ||
/polyfilled.js | ||
/polyfilled.d.ts | ||
local.log |
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,2 @@ | ||
import "../utils/ie-polyfills"; | ||
import "../basic"; |
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,56 @@ | ||
import "react-app-polyfill/ie11"; | ||
import React, { FunctionComponent, useEffect, useRef } from "react"; | ||
import { | ||
createComponentHandler, | ||
HandlerResolverComponentProps, | ||
ObservedSize, | ||
render, | ||
} from "../utils"; | ||
import useResizeObserver from "../../polyfilled"; | ||
import delay from "../utils/delay"; | ||
import ROP from "resize-observer-polyfill"; | ||
|
||
/** | ||
* This test ensures that the shipped polyfilled version actually works. | ||
* This has to run alone independent from other tests, otherwise the environment | ||
* may have been polyfilled already. | ||
*/ | ||
describe("Polyfilled lib testing", () => { | ||
beforeAll(() => { | ||
// @ts-ignore | ||
delete window.ResizeObserver; | ||
}); | ||
|
||
afterAll(() => { | ||
if (!window.ResizeObserver) { | ||
// @ts-ignore | ||
window.ResizeObserver = ROP; | ||
} | ||
}); | ||
|
||
it("should work with the polyfilled version", async () => { | ||
const Test: FunctionComponent<HandlerResolverComponentProps> = ({ | ||
resolveHandler, | ||
}) => { | ||
const { ref, width, height } = useResizeObserver<HTMLDivElement>(); | ||
const currentSizeRef = useRef<ObservedSize>({} as ObservedSize); | ||
currentSizeRef.current.width = width; | ||
currentSizeRef.current.height = height; | ||
|
||
useEffect(() => { | ||
resolveHandler(createComponentHandler({ currentSizeRef })); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ width: 50, height: 40 }} ref={ref}> | ||
{width}x{height} | ||
</div> | ||
); | ||
}; | ||
|
||
const { assertSize } = await render(Test); | ||
|
||
await delay(50); | ||
assertSize({ width: 50, height: 40 }); | ||
}); | ||
}); |
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,2 @@ | ||
import "../utils/ie-polyfills"; | ||
import "../testing-lib"; |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
// @see https://stackoverflow.com/a/21825207/982092 | ||
// @ts-ignore | ||
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode; | ||
export default function awaitNextFrame() { | ||
return new Promise((resolve) => setTimeout(resolve, 1000 / 60)); | ||
return new Promise((resolve) => | ||
// Seems like that on IE with the RO polyfill we need to slow things down a bit | ||
setTimeout(resolve, 1000 / (isIE11 ? 10 : 60)) | ||
); | ||
} |
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,2 @@ | ||
export default (time: number) => | ||
new Promise((resolve) => setTimeout(resolve, time)); |
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,18 @@ | ||
import "react-app-polyfill/ie11"; | ||
import "react-app-polyfill/stable"; | ||
import ROP from "resize-observer-polyfill"; | ||
if (!window.ResizeObserver) { | ||
// @ts-ignore | ||
window.ResizeObserver = ROP; | ||
} | ||
if (!Object.entries) { | ||
// @ts-ignore | ||
Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
|
||
return resArray; | ||
}; | ||
} |
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