react-dom-resize-observer
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -13,7 +13,2 @@ "use strict"; | ||
class ResizeObserver { | ||
constructor(callback) { | ||
this.callback = function (entries) { | ||
console.log(entries); | ||
}; | ||
} | ||
observe() { | ||
@@ -64,1 +59,67 @@ mockObserve(); | ||
}); | ||
it("returns the entry from the observer callback", () => { | ||
let observerCallback = () => { }; | ||
class ResizeObserver { | ||
constructor(callback) { | ||
observerCallback = callback; | ||
} | ||
observe() { } | ||
disconnect() { } | ||
unobserve() { } | ||
} | ||
window.ResizeObserver = ResizeObserver; | ||
const { result } = (0, react_1.renderHook)(() => (0, useResizeObserver_1.useResizeObserver)()); | ||
(0, react_1.act)(() => { | ||
const el = document.createElement("div"); | ||
result.current.observer(el); | ||
}); | ||
(0, react_1.act)(() => { | ||
observerCallback([{ test: "test" }], new ResizeObserver(observerCallback)); | ||
}); | ||
expect(result.current.entry).toEqual({ test: "test" }); | ||
}); | ||
it("calls onResize callback if there are entries", () => { | ||
let observerCallback = () => { }; | ||
class ResizeObserver { | ||
constructor(callback) { | ||
observerCallback = callback; | ||
} | ||
observe() { } | ||
disconnect() { } | ||
unobserve() { } | ||
} | ||
window.ResizeObserver = ResizeObserver; | ||
const mockOnResize = jest.fn(); | ||
const { result } = (0, react_1.renderHook)(() => (0, useResizeObserver_1.useResizeObserver)(mockOnResize)); | ||
(0, react_1.act)(() => { | ||
const el = document.createElement("div"); | ||
result.current.observer(el); | ||
}); | ||
(0, react_1.act)(() => { | ||
observerCallback([{ test: "test" }], new ResizeObserver(observerCallback)); | ||
}); | ||
expect(mockOnResize).toHaveBeenCalledTimes(1); | ||
}); | ||
it("returns a null entry and does not call onResize if no rentries were called back", () => { | ||
let observerCallback = () => { }; | ||
class ResizeObserver { | ||
constructor(callback) { | ||
observerCallback = callback; | ||
} | ||
observe() { } | ||
disconnect() { } | ||
unobserve() { } | ||
} | ||
window.ResizeObserver = ResizeObserver; | ||
const mockOnResize = jest.fn(); | ||
const { result } = (0, react_1.renderHook)(() => (0, useResizeObserver_1.useResizeObserver)(mockOnResize)); | ||
(0, react_1.act)(() => { | ||
const el = document.createElement("div"); | ||
result.current.observer(el); | ||
}); | ||
(0, react_1.act)(() => { | ||
observerCallback([], new ResizeObserver(observerCallback)); | ||
}); | ||
expect(result.current.entry).toBeNull(); | ||
expect(mockOnResize).not.toHaveBeenCalled(); | ||
}); |
{ | ||
"name": "react-dom-resize-observer", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11493
222