Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Viteri committed Jan 31, 2025
1 parent 2aa7967 commit 569646b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { mount } from '../../../../test/vue-jest-style-workaround.js';
import CdrSurfaceNavigation from '../CdrSurfaceNavigation.vue';
import CdrSurfaceNavigationLink from '../CdrSurfaceNavigationLink.vue';

describe('CdrSurface', () => {
describe('snapshot test', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(CdrSurfaceNavigation);
});
it('renders correctly', () => {
wrapper.setProps({ palette: 'default' });
expect(wrapper.element).toMatchSnapshot();
});
});

describe('component unit tests', () => {
let wrapper;
let link;
beforeEach(() => {
wrapper = mount(CdrSurfaceNavigation);
link = mount(CdrSurfaceNavigationLink);
});

describe('default component with no configuration', () => {
it('renders correctly', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('sets the default tag prop correctly', () => {
expect(wrapper.element.tagName).toBe('DIV');
expect(link.element.tagName).toBe('A');
});
it('default class added', () => {
expect(wrapper.classes()).toEqual([
'cdr-surface-navigation',
'cdr-surface-navigation-radius-sharp--rest',
'cdr-surface-navigation-shadow-flat--rest',
]);
});
});

it('has data-palette attribute set to "default" by default', () => {
expect(wrapper.attributes('data-palette')).toBe('default');
});

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`CdrSurface > component unit tests > default component with no configuration > renders correctly 1`] = `
<div
class="cdr-surface-navigation cdr-surface-navigation-radius-sharp--rest cdr-surface-navigation-shadow-flat--rest"
data-palette="default"
>
<!-- @slot Where all default content should be placed. -->
</div>
`;

exports[`CdrSurface > snapshot test > renders correctly 1`] = `
<div
class="cdr-surface-navigation cdr-surface-navigation-radius-sharp--rest cdr-surface-navigation-shadow-flat--rest"
data-palette="default"
>
<!-- @slot Where all default content should be placed. -->
</div>
`;

0 comments on commit 569646b

Please sign in to comment.