jpudysz / react-native-unistyles

Level up your React Native StyleSheet

Home Page:https://unistyl.es

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnistylesRegistry breaks test with barrel files

rokkoo opened this issue Β· comments

Description

Hello @jpudysz! πŸ‘‹ I'm adding the Unistyles library to my project. This project has a lot of tests. I have splited the project into multiple folders that use barrel files. When I add the UnistylesRegistry to the Jest config, all the tests that use those barrel files don't pass. In order to fix it, I need to specify the exact path of the import that I need. Without UnistylesRegistry, it works perfectly.

Im using monorepo with a beare react native project.

Steps to reproduce

Initialise UnistylesRegistry on jest.config.js.

require('./theme/unistyles');

Unistyles setup

// unistyles.ts
import { UnistylesRegistry } from 'react-native-unistyles';
import { LightTheme } from './themes';
import { breakpoints } from './breakpoints';

// if you defined breakpoints
type AppBreakpoints = typeof breakpoints;

// if you defined themes
type AppThemes = {
  light: typeof LightTheme;
};

// override library types
declare module 'react-native-unistyles' {
  export interface UnistylesBreakpoints extends AppBreakpoints {}
  export interface UnistylesThemes extends AppThemes {}
}

UnistylesRegistry.addThemes({
  light: LightTheme,
})
  .addBreakpoints(breakpoints)
  .addConfig({
    adaptiveThemes: false,
  });

Hook file

// hook.ts

// fails ❌
import { InfoService } from '@repo/universal';

// pass βœ…
import * as InfoService from '@repo/universal/services/info-service';

(Jest) Test file

// hook.test.ts
jest.mock('@repo/universal/services/info-service', () => ({
  getVersion: jest.fn(() => Promise.resolve(mockVersion)),
}));

Snack or a link to a repository (optional)

No response

Unistyles version

2.7.1

React Native version

0.73.5

Platforms

Android, iOS

Engine

Hermes

Architecture

Fabric (new)

Hey, and what's the issue on Unistyles side?

You have a unique monorepo setup, and I have no control over how Jest resolves the files.