Skip to content

Commit

Permalink
Adds VAction Unit tests (#121)
Browse files Browse the repository at this point in the history
* chore: bump^ minor version "wait-on"

* feat: adds VAction tests and linting fix + clean up git history
  • Loading branch information
ontoneio committed Feb 5, 2021
1 parent 3372d89 commit 2a737d8
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/components/VAction/VAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export default {
if (tag === 'RouterLink') {
options.nativeOn = listeners;
}
/**
* Supress Vue warnings of .native modifiers
* Reference comment and issue #9999 on Vuetify
* https://github.com/vuetifyjs/vuetify/issues/9999#issuecomment-579434865
*/
if (tag === 'button') {
options.nativeOn = null;
}
return h(tag, options, children);
},
Expand Down
17 changes: 9 additions & 8 deletions src/components/VBreadcrumbs/VBreadcrumbs.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<nav role="navigation" class="vts-breadcrumbs">
<ol itemscope itemtype="http://schema.org/BreadcrumbList" class="vts-breadcrumbs__list">
<ol
itemscope
itemtype="http://schema.org/BreadcrumbList"
class="vts-breadcrumbs__list"
>
<li
v-for="(item, index) in routeBreadcrumbs"
:key="index"
Expand All @@ -9,10 +13,7 @@
itemtype="http://schema.org/ListItem"
class="vts-breadcrumbs__item"
>
<span
v-if="index === routeBreadcrumbs.length - 1"
class="active"
>
<span v-if="index === routeBreadcrumbs.length - 1" class="active">
{{ item.text }}
</span>
<router-link
Expand All @@ -38,11 +39,11 @@ export default {
},
computed: {
routeBreadcrumbs() {
if (this.breadcrumbs.length) {
routeBreadcrumbs({ $route }) {
if (this.breadcrumbs['length']) {
return this.breadcrumbs;
}
if (this.$route.fullPath === '/dashboard') {
if ($route['fullPath'] === '/dashboard') {
return [{ text: 'Home' }];
}
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/src/components/VAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { render } from '@testing-library/vue';
import { RouterLinkStub } from '@vue/test-utils';
import VActionStub from '../stubs/VActionStub.vue';

describe('VAction Unit Test', () => {
describe('Default Functionality', () => {
it('Returns a <RouterLink/> tag', () => {
const { getByTestId } = render(VActionStub, {
stubs: {
RouterLink: RouterLinkStub
},
});

const testLink = getByTestId('internal');
expect(testLink).toHaveAttribute(
'to',
expect.stringContaining('/internal-link')
);
});
it('Returns an anchor tag with :href', () => {
const { getByTestId } = render(VActionStub);
const testLink = getByTestId('external-href');
expect(testLink).toHaveAttribute(
'href',
expect.stringContaining('http://example.com/')
);
});
it('Fails to return an anchor tag with :attrs', () => {
const { getByTestId } = render(VActionStub);
const testLink = getByTestId('external-attrs');
expect(testLink).not.toHaveAttribute('href');
});
it('Fails to return an anchor tag with :data', () => {
const { getByTestId } = render(VActionStub);
const testLink = getByTestId('external-data');
expect(testLink).not.toHaveAttribute('href');
});
it('Returns a <button />', () => {
const { getByTestId } = render(VActionStub);
const testLink = getByTestId('button');
expect(testLink).toHaveTextContent('Button');
});
});
});
48 changes: 48 additions & 0 deletions tests/unit/src/stubs/VActionStub.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div>
<!-- ROUTER LINK -->
<v-action data-testid="internal" to="/internal-link">
Internal Link
</v-action>
<!-- ANCHOR TAG -->
<!-- TEST WONT PASS -->
<v-action data-testid="external-data" :data="data">
External Link
</v-action>
<!-- TEST WONT PASS -->
<v-action data-testid="external-attrs" :attrs="attrs">
External Link
</v-action>
<!-- TEST WILL PASS -->
<v-action data-testid="external-href" :href="attrs.href">
External Link
</v-action>
<!-- BUTTON -->
<v-action data-testid="button">
Button
</v-action>
</div>
</template>

<script>
// TURNS OFF ERROR IN CONSOLE for UNIT TEST
import { RouterLinkStub } from '@vue/test-utils';
const RouterLink = RouterLinkStub;
import VAction from '../../../../src/components/VAction/VAction.vue';
export default {
name: 'VActionStub',
components: {
VAction,
// eslint-disable-next-line vue/no-unused-components
RouterLink
},
data() {
return {
attrs: {
href: 'http://example.com/',
},
};
},
};
</script>

0 comments on commit 2a737d8

Please sign in to comment.