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.

Warning: `NaN` is an invalid value for the `height` css style property.

See original GitHub issue

I’m getting the following warnings in a Jest test:

  console.error node_modules/fbjs/lib/warning.js:33
    Warning: `NaN` is an invalid value for the `height` css style property.
        in div (created by DayPicker)
        in div (created by DayPicker)
        in div (created by DayPicker)
        in div (created by OutsideClickHandler)
        in OutsideClickHandler (created by DayPicker)
        in div (created by DayPicker)
        in DayPicker (created by withStyles(DayPicker))
        in withStyles(DayPicker) (created by DayPickerSingleDateController)
        in DayPickerSingleDateController (at DateTimeSelector.js:131)
        in div (created by DateTimeSelector__DayPickerWrapper)
        in DateTimeSelector__DayPickerWrapper (at DateTimeSelector.js:130)
        in div (created by DateTimeSelector__Container)
        in DateTimeSelector__Container (at DateTimeSelector.js:126)
        in DateTimeSelector (created by Connect(DateTimeSelector))
        in Connect(DateTimeSelector) (at OrderPage.js:166)
        in div (created by OrderPage__Container)
        in OrderPage__Container (at OrderPage.js:165)
        in OrderPage (created by Connect(OrderPage))
        in Connect(OrderPage) (at index.js:9)
        in Route (at index.js:5)
        in ProtectedRoute (at PortalApp.js:36)
        in Switch (at PortalApp.js:22)
        in div (at PortalApp.js:20)
        in Router (created by BrowserRouter)
        in BrowserRouter (at PortalApp.js:19)
        in Routes (created by Connect(Routes))
        in Connect(Routes) (at PortalApp.js:85)
        in Provider (at PortalApp.js:84)
        in PortalApp (created by WrapperComponent)
        in WrapperComponent

  console.error node_modules/fbjs/lib/warning.js:33
    Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

    Please check the code for the DayPicker component.

I solved that adding the following line to setupTests.js:

jest.spyOn(CalendarMonth.WrappedComponent.prototype, 'setMonthTitleHeight').mockImplementation();

I also get the following:

  console.error node_modules/fbjs/lib/warning.js:33
    Warning: `NaN` is an invalid value for the `width` css style property.
        in div (created by DayPicker)
        in DayPicker (created by withStyles(DayPicker))
        in withStyles(DayPicker) (created by DayPickerSingleDateController)
        in DayPickerSingleDateController (at DateTimeSelector.js:131)
        in div (created by DateTimeSelector__DayPickerWrapper)
        in DateTimeSelector__DayPickerWrapper (at DateTimeSelector.js:130)
        in div (created by DateTimeSelector__Container)
        in DateTimeSelector__Container (at DateTimeSelector.js:126)
        in DateTimeSelector (created by Connect(DateTimeSelector))
        in Connect(DateTimeSelector) (at OrderPage.js:166)
        in div (created by OrderPage__Container)
        in OrderPage__Container (at OrderPage.js:165)
        in OrderPage (created by Connect(OrderPage))
        in Connect(OrderPage) (at index.js:9)
        in Route (at index.js:5)
        in ProtectedRoute (at PortalApp.js:36)
        in Switch (at PortalApp.js:22)
        in div (at PortalApp.js:20)
        in Router (created by BrowserRouter)
        in BrowserRouter (at PortalApp.js:19)
        in Routes (created by Connect(Routes))
        in Connect(Routes) (at PortalApp.js:85)
        in Provider (at PortalApp.js:84)
        in PortalApp (created by WrapperComponent)
        in WrapperComponent

Solved by:

const { componentDidMount } = DayPicker.WrappedComponent.prototype;
jest.spyOn(DayPicker.WrappedComponent.prototype, 'componentDidMount').mockImplementation(
    function mock(...args) {
        const { style } = this.calendarInfo;
        if (!style.marginLeft) style.marginLeft = 0;
        if (!style.marginRight) style.marginRight = 0;
        componentDidMount.apply(this, args);
    },
);

I think that both NaN are generated in calculateDimension https://github.com/airbnb/react-dates/blob/83ec316167b499ce939058973da0aff30e70d178/src/utils/calculateDimension.js#L19 Would be nice to do something like:

if (withMargin) {
  size +=
    parseFloat(style[`margin${axisStart}`] || 0)
    + parseFloat(style[`margin${axisEnd}`] || 0);
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:14
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
fresholliecommented, Mar 2, 2020

For those who want to remove this error from their tests right now:

Object.defineProperty(window, 'getComputedStyle', {
    value: () => ({
        paddingLeft: 0,
        paddingRight: 0,
        paddingTop: 0,
        paddingBottom: 0,
        marginLeft: 0,
        marginRight: 0,
        marginTop: 0,
        marginBottom: 0,
        borderBottomWidth: 0,
        borderTopWidth: 0,
        borderRightWidth: 0,
        borderLeftWidth: 0
    })
});
4reactions
renatoagdscommented, Apr 13, 2020

@freshollie workaround didn’t work entire for me, since I was using the current getComputedStyle implementation of jsdom, that return a few stuffs (https://github.com/jsdom/jsdom/blob/master/lib/jsdom/browser/Window.js#L643-L671) and default return for getComputedStyle is CSSStyleDeclaration. That way I got the principle of his idea and arrived in this solution:

const originalGetComputedStyle = window.getComputedStyle

const getComputedStyle = (...args) => {
  const cssStyleDeclaration = originalGetComputedStyle(...args)
  cssStyleDeclaration.setProperty('padding-left', 0)
  cssStyleDeclaration.setProperty('padding-right', 0)
  cssStyleDeclaration.setProperty('padding-top', 0)
  cssStyleDeclaration.setProperty('padding-bottom', 0)
  cssStyleDeclaration.setProperty('margin-left', 0)
  cssStyleDeclaration.setProperty('margin-right', 0)
  cssStyleDeclaration.setProperty('margin-top', 0)
  cssStyleDeclaration.setProperty('margin-bottom', 0)
  cssStyleDeclaration.setProperty('border-left-width', 0)
  cssStyleDeclaration.setProperty('border-right-width', 0)
  cssStyleDeclaration.setProperty('border-top-width', 0)
  cssStyleDeclaration.setProperty('border-bottom-width', 0)
  return cssStyleDeclaration
}

Object.defineProperty(window, 'getComputedStyle', {
  value: getComputedStyle,
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: `NaN` is an invalid value for the `height` css style ...
I'm getting the following warnings in a Jest test: console.error ... Warning: NaN is an invalid value for the height css style property....
Read more >
`NaN` is an invalid value for the `background` css style ...
I changed the value of the background property to a string literal and that fixed the issue. enter={{ background: `${stripe.background}`, }}.
Read more >
`NaN` is an invalid value for the `width` css style property - Web
Everytime I join a meeting, I always get this error in the console, though I can successfully join a meeting, it just bothers...
Read more >
Warning: `NaN` is an invalid value for the `height` css style ...
I'm getting the following warnings in a Jest test: console. error node_modules/fbjs/lib/warning. js:33 Warning: `NaN` is an invalid value for the `height` css...
Read more >
React DOM element's style property name or value should not ...
React Warning: NaN is an invalid value for the fontSize css style property. Was this documentation helpful? Analyze Your GitHub Project Now.
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