Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Jun 24, 2024
1 parent 4127d05 commit 8845575
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 62 deletions.
120 changes: 60 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/NavBar/NavBarDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ withDefaults(defineProps<Props>(), {

<template>
<li>
<a>
<a data-test="label">
<slot name="label">{{ label }}</slot> <span uk-navbar-parent-icon></span>
</a>
<div class="uk-navbar-dropdown" uk-dropdown="offset: 0">
<ul class="uk-nav uk-navbar-dropdown-nav">
<ul class="uk-nav uk-navbar-dropdown-nav" data-test="slot">
<slot></slot>
</ul>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/tests/components/Content/CardBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ test('Basic test', () => {
expect(wrapper.get('[data-test="title"]').text()).toMatch('Hello world')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})

test('Test with no prop and slot', () => {
// Arrange
const wrapper = mount(CardBox)

// Assert
expect(wrapper.find('[data-test="title"]').exists()).toBe(false)
expect(wrapper.get('[data-test="slot"]').text()).toMatch('')
})
49 changes: 49 additions & 0 deletions src/tests/components/NavBar/NavBarDropdown.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
import MainContent from '../../../components/NavBar/NavBarDropdown.vue'

test('Label as slot', () => {
// Arrange
const wrapper = mount(MainContent, {
slots: {
label: 'This is the Label as Slot',
default: 'This is the slot content'
}
})

// Assert
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})

test('Label as prop', () => {
// Arrange
const wrapper = mount(MainContent, {
props: {
label: 'This is the Label as prop',
},
slots: {
default: 'This is the slot content'
}
})

// Assert
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as prop')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content')
})

test('Label slot overwrite prop', () => {
// Arrange
const wrapper = mount(MainContent, {
props: {
label: 'This is the Label as prop'
},
slots: {
label: 'This is the Label as Slot'
}
})

// Assert
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot')
expect(wrapper.get('[data-test="slot"]').text()).toMatch('')
})

0 comments on commit 8845575

Please sign in to comment.