Skip to content

Commit

Permalink
add WithStyle test util
Browse files Browse the repository at this point in the history
Signed-off-by: balanza <[email protected]>
  • Loading branch information
balanza committed Jun 21, 2024
1 parent f2992cd commit 7c92ef4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions assets/js/lib/test-utils/ui/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

const css = require('fs').readFileSync(
`${__dirname}/../../../../../priv/static/assets/app.css`,
'utf8'
);

/**
* Prepend the application global css in a <style> element.
* It's meant to be used in component testing when css classes must be resolved.
*
* @example
*
* render(
* <WithStyle>
* <Elem />
* </WithStyle>
* );
*/
export function WithStyle({ children }) {
return (
<>
<style>{css}</style>
{children}
</>
);
}
1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"lint": "eslint . --ext js,jsx",
"format:check": "prettier -c .",
"format": "prettier --write .",
"pretest": "ls ../priv/static/assets/app.css || npm run tailwind:build",
"test": "jest",
"chromatic": "npx chromatic --exit-zero-on-changes"
}
Expand Down

0 comments on commit 7c92ef4

Please sign in to comment.