Skip to content

Commit

Permalink
update: complete balstack tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchickenburger committed Jan 20, 2022
1 parent 220ea73 commit 708c8b2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
68 changes: 63 additions & 5 deletions src/components/_global/BalStack/BalStack.spec.ts
@@ -1,9 +1,9 @@
import { render } from '@testing-library/vue';
import BalStack from './BalStack.vue';

describe('BalStack', () => {
describe.only('BalStack', () => {
describe('When using BalStack', () => {
it('should render items horizontally when the horizontal prop is supplied', () => {
it('should render items', () => {
const { getByText } = render(BalStack, {
slots: {
default: '<div>First</div><div>Second</div><div>Third</div>'
Expand All @@ -16,10 +16,68 @@ describe('BalStack', () => {
expect(getByText('Third')).toBeVisible();
});

// it('should render items vertically when the vertical prop is supplied', () => {});
it('should render items horizontally when the horizontal prop is supplied', () => {
const { getByText } = render(BalStack, {
slots: {
default: '<div>First</div><div>Second</div><div>Third</div>'
},
props: {
horizontal: true
}
});

// its fine to make this assumption here as we render the children without any wrappers
const stackEl = getByText('First').parentElement;
expect(stackEl).toHaveClass('flex-row');
});

it('should render items verticlly if vertical prop is supplied', () => {
const { getByText } = render(BalStack, {
slots: {
default: '<div>First</div><div>Second</div><div>Third</div>'
},
props: {
vertical: true
}
});

// its fine to make this assumption here as we render the children without any wrappers
const stackEl = getByText('First').parentElement;
expect(stackEl).toHaveClass('flex-col');
});

it('should render items with space between them', () => {
const { getByText } = render(BalStack, {
slots: {
default: '<div>First</div><div>Second</div><div>Third</div>'
},
props: {
vertical: true
}
});

// it('should render items with a space between them', () => {});
// the default spacing unit (tailwind) is 4. So can be either mb-4 or mr-4
expect(getByText('First')).toHaveClass('mb-4');
expect(getByText('Second')).toHaveClass('mb-4');
// last el shouldn't have a spacing class
expect(getByText('Third')).not.toHaveClass('mb-4');
});
it('should render items with a border between them if withBorder prop is supplied', () => {
const { getByText } = render(BalStack, {
slots: {
default: '<div>First</div><div>Second</div><div>Third</div>'
},
props: {
vertical: true,
withBorder: true
}
});

// it('should render items with a border between them if withBorder prop is supplied', () => {});
// the default spacing unit (tailwind) is 4. So can be either mb-4 or mr-4
expect(getByText('First')).toHaveClass('mb-4 border-b');
expect(getByText('Second')).toHaveClass('mb-4 border-b');
// last el shouldn't have a spacing class
expect(getByText('Third')).not.toHaveClass('mb-4 border-b');
});
});
});
2 changes: 1 addition & 1 deletion src/plugins/components.ts
Expand Up @@ -6,7 +6,7 @@ export function registerGlobalComponents(app: App): void {
const req = require.context(
'@/components/_global',
true,
/^((?!stories).)*\.(js|ts|vue)$/i
/^((?!(stories|spec)).)*\.(js|ts|vue)$/i
);
for (const filePath of req.keys()) {
const componentName = parsePath(filePath).name;
Expand Down

0 comments on commit 708c8b2

Please sign in to comment.