Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 456ff16

Browse files
committed
fix: tests for theme provider
1 parent 7cbbf69 commit 456ff16

File tree

12 files changed

+175
-10
lines changed

12 files changed

+175
-10
lines changed

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
presets: [
3-
'@vue/app'
3+
'@vue/app',
4+
'@babel/preset-env'
45
]
56
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
transform: {
99
'^.+\\.vue$': 'vue-jest',
1010
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
11-
'^.+\\.jsx?$': 'babel-jest'
11+
'^.+\\.(js|jsx)?$': 'babel-jest'
1212
},
1313
transformIgnorePatterns: [
1414
'/node_modules/'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"build-storybook": "build-storybook"
1313
},
1414
"dependencies": {
15+
"@babel/preset-env": "^7.6.3",
1516
"core-js": "^2.6.5",
1617
"css-loader": "^3.2.0",
1718
"esm": "^3.2.25",

src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<div>
33
{{ greeting }}
4-
<k-button>Simple text</k-button>
4+
<Button>Simple text</Button>
55
</div>
66
</template>
77

88
<script>
9-
import KButton from './components/Button/index'
9+
import Button from './components/Button/index'
1010
1111
export default {
1212
name: 'App',
1313
components: {
14-
KButton
14+
Button
1515
},
1616
data () {
1717
return {

src/components/Button/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<script>
2222
export default {
2323
name: 'Button',
24-
inject: ['KiwiTheme'],
2524
props: {
2625
as: {
2726
type: String,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import ThemeProvider from '../ThemeProvider'
3+
import Theme from '../../../kiwi.config'
4+
5+
describe('===== ThemeProvider Component =====', () => {
6+
let themeProvider
7+
const ChildComponent = {
8+
inject: ['KiwiTheme'],
9+
render: h => h('div', {})
10+
}
11+
12+
it('should be a Vue component', () => {
13+
themeProvider = shallowMount(ThemeProvider, {
14+
slots: {
15+
default: [ChildComponent]
16+
}
17+
})
18+
expect(themeProvider.isVueInstance()).toBeTruthy()
19+
})
20+
21+
it('should provide theme to child components', () => {
22+
themeProvider = shallowMount(ThemeProvider, {
23+
slots: {
24+
default: [ChildComponent]
25+
}
26+
})
27+
expect(themeProvider.find(ChildComponent).vm.KiwiTheme).toBe(Theme)
28+
})
29+
})

src/lib/plugin/index.js

Whitespace-only changes.

src/lib/utils/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Logger from './logger'
2+
import { provideTheme } from './provide-theme'
23

34
export {
4-
Logger
5+
Logger,
6+
provideTheme
57
}

src/lib/utils/provide-theme.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import ThemeProvider from '../../components/ThemeProvider'
2+
3+
/**
4+
* @description Provides Kiwi theme to component
5+
* @param {Function} h Vue render function
6+
* @param {Vue.Component} Component - Vue component
7+
*/
8+
export const provideTheme = (h, Component) => {
9+
return h(ThemeProvider, {}, [h(Component)])
10+
}

0 commit comments

Comments
 (0)