Giter Site home page Giter Site logo

Cannot Do Unit Test about react-lazy-load HOT 5 CLOSED

loktar00 avatar loktar00 commented on July 17, 2024 3
Cannot Do Unit Test

from react-lazy-load.

Comments (5)

m8ms avatar m8ms commented on July 17, 2024 9

I had similar problem with jest. A simple mock helped:

jest.mock('react-lazy-load', () => (props) => props.children)

However, I have no idea how this applies to other testing suites.

from react-lazy-load.

ahome-tm avatar ahome-tm commented on July 17, 2024 4

Hey I want to flag this issue again. I am working with version 3.0.12. I am using mocha and enzyme testing framework. I cannot execute my unit tests for the same reason reported here. The patch suggested by @raliasadil does not work.

from react-lazy-load.

raliasadil avatar raliasadil commented on July 17, 2024 3

Solution is the attached Patch

Subject: [PATCH] Fixes issue with HTMLElement


src/utils/parentScroll.js | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/utils/parentScroll.js b/src/utils/parentScroll.js
index e497941..4cfc154 100644
--- a/src/utils/parentScroll.js
+++ b/src/utils/parentScroll.js
@@ -3,6 +3,8 @@ const style = (element, prop) =>
? getComputedStyle(element, null).getPropertyValue(prop)
: element.style[prop];

+var HTMLElement = typeof HTMLElement === 'undefined' ? function(){} : HTMLElement;
+
const overflow = (element) =>
style(element, 'overflow') + style(element, 'overflow-y') + style(element, 'overflow-x');

2.8.1

from react-lazy-load.

joFolta avatar joFolta commented on July 17, 2024 1

@m8ms solution worked for me! Thanks!
https://jestjs.io/docs/en/mock-functions#mocking-modules

from react-lazy-load.

RamiroIsBack avatar RamiroIsBack commented on July 17, 2024

hello,
I'm having this same Issue I think, this is the complete log while trying to run test with jest.
"react": "^16.2.0",
"react-lazy-load": "^3.0.13",
`ReferenceError: HTMLElement is not defined

  at scrollParent (node_modules/react-lazy-load/lib/utils/parentScroll.js:15:28)
  at LazyLoad.getEventNode (node_modules/react-lazy-load/lib/LazyLoad.js:107:41)
  at LazyLoad.componentDidMount (node_modules/react-lazy-load/lib/LazyLoad.js:71:28)
  at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:4553:24)
  at commitAllLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5729:9)
  at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1559:10)
  at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1506:29)
  at commitRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5833:9)
  at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6800:42)
  at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6750:7)

`
Any progress on the matter ? thank you!!

from react-lazy-load.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.