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

Fail snapshot test after including the typeahead #139

Closed
davidyu85 opened this issue Feb 15, 2017 · 6 comments
Closed

Fail snapshot test after including the typeahead #139

davidyu85 opened this issue Feb 15, 2017 · 6 comments

Comments

@davidyu85
Copy link

davidyu85 commented Feb 15, 2017

Although I am able to make the typeahead function in browser, but it mysteriously failed the snapshot test. It shows this error message.

Invariant Violation: getNodeFromInstance: Invalid argument.

Need help on this one as the error messages aren't that helpful pin pointing me the issue.

@ericgio
Copy link
Owner

ericgio commented Feb 15, 2017

I'm going to need more info: version? code sample?

This doesn't sound on the surface like an issue with the component, though.

@davidyu85
Copy link
Author

version: 1.0.0-beta5

Code sample:
DatePicker.js (shorterned but working example):

import React, { Component } from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';

export default class DatePicker extends Component {
  render() {
    return (
      <div className="date">  
        <Typeahead
          labelKey={option => `${option.label}`}
          placeholder="Day"
          options={ 
            (function() {
              var arr = [], i;
              for(i=1;i<=31;i++) {
                arr.push({
                  name: 'day',
                  value: i, 
                  label: i
                });
              }
              return arr;
            })()
          }
        />
        <br /><br />
      </div>
    )
  }
}

Snapshot test:

import React from 'react';
import DatePicker from './DatePicker';
import renderer from 'react-test-renderer';

describe('DatePicker', function() {
  test('renders correctly', function() {
    const component = renderer.create(<DatePicker />).toJSON();
    expect(component).toMatchSnapshot();
  });
})

@ericgio
Copy link
Owner

ericgio commented Feb 15, 2017

Your date picker code looks correct to me. I'm not familiar with how to write tests using Jest, though, so I can't tell you what's wrong there.

@ericgio
Copy link
Owner

ericgio commented Feb 15, 2017

Looks like the test-renderer might not work with refs or findDOMNode?

@davidyu85
Copy link
Author

Looks like this is the case, since I've seen findDOMNode used in the typeahead component.

facebook/react#7371

@ericgio
Copy link
Owner

ericgio commented Feb 15, 2017

Seems like it, unfortunately.

@ericgio ericgio closed this as completed Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants