airbnb / react-with-styles-interface-aphrodite

Interface to use react-with-styles with Aphrodite
MIT License
54 stars 14 forks source link

please export StyleSheetTestUtils #72

Open RonHouben opened 3 years ago

RonHouben commented 3 years ago

Hi! First of all thanks for making this interface!

Is it possible to export the following test-utility function from aphrodite: StyleSheetTestUtils

This would remove the need to add the complete aphrodite dependency to a project while only actually using react-with-styles-interface-aphrodite, just for testing purposes.

I'm currently only using this interface for the react-dates dateRangePicker component but the tests are currently throwing this error:

styleTag = document.querySelector("style[data-aphrodite]")
                        ^
TypeError: Cannot read property 'querySelector' of null

This issue can be solved by adding the following for each test:

beforeEach(() => {
  StyleSheetTestUtils.suppressStyleInjection();
});
afterEach(() => {
  StyleSheetTestUtils.clearBufferAndResumeStyleInjection();
});

Since the StyleSheetTestUtils are not exported by react-with-styles-interface-aphrodite I'll need to install the complete aphrodite package just for testing, which feels like an overkill.

I'll prepare an PR for this.

ljharb commented 3 years ago

This project is explicitly only intended to be used with aphrodite - it shouldn't be used unless aphrodite is present.

RonHouben commented 3 years ago

This project is explicitly only intended to be used with aphrodite - it shouldn't be used unless aphrodite is present.

I understand, although just adding the complete aphrodite package seperatly just to be able to unit test one component (react-dates in my case) feels like a bit of an overkill. Especially if it could be exported from react-with-styles-interface-aphrodite which is already necessary for the react-dates component.

For now I added the aphrodite package as a dev dependency to my project just to use the StyleSheetTestUtils in my tests.

ljharb commented 3 years ago

How are you using react-dates in production? If that's used with aphrodite, then it'd already be there; if not, why not use the same interface in tests?