Skip to content

Instantly share code, notes, and snippets.

@vslinko
Last active December 11, 2015 13:10
Show Gist options
  • Save vslinko/1c427a055e1188d2245a to your computer and use it in GitHub Desktop.
Save vslinko/1c427a055e1188d2245a to your computer and use it in GitHub Desktop.
React Markers
export default function marker(value) {
if (process.env.NODE_ENV !== 'production') {
return {
'data-marker': value,
};
}
return {};
}
export function createMarker(prefix) {
return (suffix) => marker(`${prefix}-${suffix}`);
}
const mark = createMarker('Logo');
export default class Logo extends React.Component {
render() {
return (
<Link
{...mark('Link')}
/>
);
}
}
export default function marker(value) {
return `[data-marker="${value}"]`;
}
export function createMarker(prefix) {
return (suffix) => marker(`${prefix}-${suffix}`);
}
export function chain(...selectors) {
return selectors.join(' ');
}
test('logo/isLink', async (t) => {
const b = createHeadlessBrowser();
await b.openUrl('/');
await b.waitForSelector(Logo('Link'));
const logo = b.querySelector(Logo('Link'));
t.equal(logo.tagName, 'A');
t.equal(logo.getAttribute('href'), '/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment