mercredi 13 février 2019

Enzyme+React expect component string - failed to parse selector

So I have this test case which I need to solve. Background is updating dev environment to newer version and after that a lot of our tests broke.

Here I have a weird case which results in: "Failed to parse selector: Label price detail 1"

This is how the test snippet looks like, I hope I've added all that is necessary.

it('Should render with price and one addon', () => {
    data.addonHeaderName = 'addonHeaderName';
    data.addons.push(
      {
        price: {
          label: 'Addon text 1',
          value: 50.33,
          unit: 'dollars',
          vat: 'excl'
        },
        discount: {
          label: 'Addon text 2',
          value: 11.43,
          unit: 'dollars',
          vat: 'excl'
        },
        future: false,
        addonIcon: 'icon',
        ecoText: 'Addon eco text',
        linkUrl: 'http://testaddonlink.com'
      }
    );
    
    
    data.contract.prices.push(
      {
        id: 'price',
        label: 'Label price detail 1',
        unit: 'dollars',
        value: 4.03
      },
      {
        id: 'Label price detail 2',
        label: 'Discount',
        unit: 'dollars',
        value: -3.00
      }
    );
    
    
 const component = shallow(
      <MyContract
        data={data}
        andSomeOtherStuff={otherStuff}
      />
    );
    expect(component).toMatchSnapshot();
    expect(component.find('Label price detail 1')).toBeTruthy();
    expect(component.find('Label price detail 2')).toBeTruthy();
    expect(component.find('Addon text 1')).toBeTruthy();
    expect(component.find('Addon text 2')).toBeTruthy();
    expect(component.find('Addon eco text')).toBeTruthy();

If I comment out the first expectation, it hits the next one, and then the other one etc etc.

Earlier we ran Enzyme 2.9.1 together with enzyme-adapter-react-15 (and of course React 15) but since we've upgraded to React 16 we also need to update a few other dependencies such as this one. And then shit hit the fan.

Now we're on Enzyme 3.8.0, enzyme-adapter-react-16.3 and React 16.3.x.

I've been fiddling around with trying to get it as a string instead but no bueno. Any ideas on what I'm missing here?

Aucun commentaire:

Enregistrer un commentaire