Skip to content

toHaveStyleRule fails with media and supports option parametersΒ #245

Open
@erikvorhes

Description

@erikvorhes

Given this component:

// StickyDiv/index.js
import styled from 'styled-components';

const StickyDiv = styled.div`
  @media screen {
    @supports (position: sticky) {
      position: sticky;
    }
  }
`;

export default StickyDiv;

and this test:

// StickyDiv/__tests__/index.test.js
import * as React from 'react';
import { mount } from 'enzyme';
import 'jest-styled-components';

import StickyDiv from '../';

test('is sticky when supported', () => {
  const component = mount(<StickyDiv />);
  expect(component).toHaveStyleRule('position', 'sticky', {
    media: 'screen',
    supports: '(position: sticky)',
  });
});

The test fails with this message:

No style rules found on passed Component using options:
{"media":"screen","supports":"(position: sticky)"}

Tests pass if a component has either a media query or a feature query, but not when they are nested.

My project uses:

  • React 16.8.6
  • Jest 23.6.0
  • Enzyme 3.9.0
  • styled-components 4.2.0
  • jest-styled-components 6.3.1

Is there a workaround for this scenario?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions