question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rendering empty div

See original GitHub issue

Hello @DimitryDushkin ,

I am trying to unit test my notification bar and during the test, SlidingPane is rendering an empty div. I have tried everything I could. Maybe a third eye could help me find out the issue. Please let me know if you have any suggestions for me. Thanks in advance !!

My Component

<div ref={(ref) => (this.el = ref)}>
        <SlidingPane
          className="notification"
          overlayClassName="notification__overlay"
          isOpen={this.props.showNotificationPanel}
          from="right"
          onRequestClose={() => {
            this.props.showNotification(false);
          }}>
          //some code
        </SlidingPane>

</div>

My Test

it('renders', () => {
    wrapper = mountWithIntl(<ShowNotification {...minProps} showNotificationPanel={true} />, 'en');
    console.log("wrapper", wrapper.html()); // outputs <div><!-- react-empty: 2 --></div>
    expect(
      wrapper.children().hasClass('notification')
    ).to.equal(true);
  });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gurusewakcommented, Jan 22, 2018

Thanks everyone for your input. There were some solutions in the past using node.portal but its deprecated now. I was able to make it work for now using the following code but I don’t think its the best approach so I will keep looking for a better approach and will post it here if I find something. Meanwhile you can use this code to test your component.

My Component

<div ref={(ref) => (this.el = ref)}>
        <SlidingPane
          className="notification"
          overlayClassName="notification__overlay"
          isOpen={this.props.showNotificationPanel}
          from="right"
          onRequestClose={() => {
            this.props.showNotification(false);
          }}>
          //some code
        </SlidingPane>

</div>

My Test

it('has classes', () => {
    wrapper = shallowWithIntl(<ShowNotification {...minProps} showNotificationPanel={true} />, 'en');
    const Content = document.body.firstChild; //for some people it can be lastChild
    expect(
      Content.querySelector('.notification__card__content span').innerHTML
    ).to.equal('Your Content');
  });
0reactions
DimitryDushkincommented, Jan 22, 2018

I will think how to make it testable

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to render empty <div style="width:50%"> </div ...
I'd personally go for <div style="min-height:1px;width:50%"></div>. That way any non empty divs will not get unwanted padding as in the other answer.
Read more >
How to make an empty div take space ? - GeeksforGeeks
In this article, we will learn how to make an empty div take space using CSS. Approach: The solution is to give some...
Read more >
Don't Fear Empty Divs - Cory Etzkorn
An empty div with a height of 60px surrounded by two divs containing real content. Rendered, it looks like this: Two divs 60px...
Read more >
Render returns empty div as container when passed a portal ...
render method, if not passed a container, returns container by creating a div element in the body. It works fine for all the...
Read more >
empty - CSS: Cascading Style Sheets - MDN Web Docs
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found