adriantoine / enzyme-to-json

Snapshot test your Enzyme wrappers
MIT License
947 stars 64 forks source link

`null` instead of `Object {}` for imported css #108

Open ashgaliyev opened 6 years ago

ashgaliyev commented 6 years ago

Hello! I've recently upgraded from 1.5.1 to 3.3.4 and saw that all properties that get css files have been rewritten from Object {} to null

I didn't find this change in the changelog and maybe it is a bug?

here is an example:

import React from 'react';
import LinkInner from './LinkInner';
import styles from './style.css';

class Link extends React.Component {
  render() {
    return (
      <a href={this.props.page || '#'}>
        <LinkInner theme={styles} />
      </a>
    );
  }
}

export default Link;

test:

import React from 'react';
import Link from './Link';
import { shallow } from 'enzyme';

it('renders correctly', () => {
  const component = shallow(<Link page="http://www.facebook.com">Facebook</Link>);
  expect(component).toMatchSnapshot();
});

snapshot:

exports[`renders correctly 1`] = `
<a
  href="http://www.facebook.com"
>
  <LinkInner
    theme={null}
  />
</a>
`;
ashgaliyev commented 6 years ago

There is return null in the new code of enzyme-to-json which wasn't before. If it gets object other than the react component (style object this our case) it will return null. https://github.com/adriantoine/enzyme-to-json/blob/master/src/shallow.js#L62

in the old code it returns empty object https://github.com/adriantoine/enzyme-to-json/blob/v1.5.1/src/shallow.js#L10

correct me if I'm wrong

VincentLanglet commented 5 years ago

PR are welcomed.

Prior to null behaviour, you had just an empty object ? I would be better to have the complete object with the style property.