Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu component causing error in tests #1113

Closed
JakeDluhy opened this issue Dec 28, 2016 · 1 comment
Closed

Menu component causing error in tests #1113

JakeDluhy opened this issue Dec 28, 2016 · 1 comment

Comments

@JakeDluhy
Copy link

JakeDluhy commented Dec 28, 2016

I am writing tests around using the Menu component. I use enzyme and jsdom and my test looks like

it('will call the spy with the expected payload', function() {
    this.wrapper.find('.spec-role-menu').simulate('click');
    // Need to use document instead of enzyme because the menu renders at the body level
    document.getElementsByClassName('spec-activate')[0].click();

    expect(this.spy.args[0][0]).to.deep.equal({ active: 1 });
});

Expected Behavior

On this.wrapper.find('.spec-role-menu').simulate('click'); the menu should render at the top level of the document

Actual Behavior

I get an error. This is the top of the stack trace

TypeError: this.anchorStepRef.scrollIntoView is not a function
      at DropContents.componentDidMount (node_modules/grommet/utils/Drop.js:90:30)
      at ReactCompositeComponentWrapper.invokeComponentDidMountWithTimer (node_modules/react/lib/ReactCompositeComponent.js:60:18)
      at CallbackQueue.notifyAll (node_modules/react/lib/CallbackQueue.js:67:22)
      at ReactReconcileTransaction.close (node_modules/react/lib/ReactReconcileTransaction.js:81:26)

URL, screen shot, or Codepen exhibiting the issue

Here is a repo created from react static boilerplate with enzyme, jsdom, and grommet added
https://github.com/JakeDluhy/grommet-menu-error

Steps to Reproduce

  1. git clone git@github.com:JakeDluhy/grommet-menu-error.git
  2. cd grommet-menu-error
  3. npm test

Tests should fail

Your Environment

  • Grommet version: 1.1.0
  • Browser Name and version: Chrome 55
  • Operating System and version (desktop or mobile): MacOS Sierra

I was able to fix this by modifying grommet and adding some additional checks for the existence of scrollIntoView, but I thought I'd see what your thoughts are.

@JakeDluhy
Copy link
Author

Hmmm upon further investigation this may be a bug with jsdom (or they intentionally left it out for some reason). I added window.HTMLElement.prototype.scrollIntoView = function() {}; into my testHelper.js file and it works. I'm creating an issue there (jsdom/jsdom#1695). Feel free to close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants