Skip to content

Commit baac4ea

Browse files
committed
added tests
1 parent 8a00c03 commit baac4ea

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/VueFinalModal.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@keydown="onEsc"
99
>
1010
<transition
11+
ref="vfmOverlayTransition"
1112
v-bind="computedOverlayTransition"
1213
@before-enter="beforeOverlayEnter"
1314
@after-enter="afterOverlayEnter"
@@ -22,6 +23,7 @@
2223
></div>
2324
</transition>
2425
<transition
26+
ref="vfmTransition"
2527
v-bind="computedTransition"
2628
@before-enter="beforeModalEnter"
2729
@after-enter="afterModalEnter"

tests/unit/VueFinalModal.spec.js

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createLocalVue, enableAutoDestroy } from '@vue/test-utils'
2-
import { afterTransition, createOpenedModal, createClosedModal, initDynamicModal } from './utils'
32
import VueFinalModal from '../../lib'
3+
import { afterTransition, createClosedModal, createOpenedModal, initDynamicModal, transitionStub } from './utils'
44

55
enableAutoDestroy(afterEach)
66

@@ -192,6 +192,89 @@ describe('VueFinalModal.vue', () => {
192192
})
193193
expect(wrapper.attributes('style')).toContain(zIndexStyle)
194194
})
195+
it('transition is string', async () => {
196+
const transition = 'vfm-test-transition'
197+
const { wrapper } = await createClosedModal(
198+
{
199+
transition
200+
},
201+
{},
202+
{},
203+
{ transition: transitionStub() }
204+
)
205+
const transitionComponent = wrapper
206+
.findComponent({
207+
ref: 'vfmTransition'
208+
})
209+
.attributes()
210+
expect(transitionComponent.name).toEqual(transition)
211+
})
212+
it('transition is an object', async () => {
213+
const transition = {
214+
'enter-active-class': 'transition duration-200 ease-in-out transform',
215+
'enter-class': 'translate-y-full',
216+
'enter-to-class': 'translate-y-0',
217+
'leave-active-class': 'transition duration-200 ease-in-out transform',
218+
'leave-to-class': 'translate-y-full',
219+
'leave-class': 'translate-y-0'
220+
}
221+
const { wrapper } = await createClosedModal(
222+
{
223+
transition
224+
},
225+
{},
226+
{},
227+
{ transition: transitionStub() }
228+
)
229+
const transitionComponent = wrapper
230+
.findComponent({
231+
ref: 'vfmTransition'
232+
})
233+
.attributes()
234+
expect(transitionComponent).toEqual(expect.objectContaining(transition))
235+
})
236+
it('overlayTransition is string', async () => {
237+
const overlayTransition = 'vfm-test-overlay-transition'
238+
const { wrapper } = await createClosedModal(
239+
{
240+
overlayTransition
241+
},
242+
{},
243+
{},
244+
{ transition: transitionStub() }
245+
)
246+
const transitionComponent = wrapper
247+
.findComponent({
248+
ref: 'vfmOverlayTransition'
249+
})
250+
.attributes()
251+
expect(transitionComponent.name).toEqual(overlayTransition)
252+
})
253+
it('overlayTransition is an object', async () => {
254+
const overlayTransition = {
255+
'enter-active-class': 'transition duration-200 ease-in-out transform',
256+
'enter-class': 'translate-y-full',
257+
'enter-to-class': 'translate-y-0',
258+
'leave-active-class': 'transition duration-200 ease-in-out transform',
259+
'leave-to-class': 'translate-y-full',
260+
'leave-class': 'translate-y-0'
261+
}
262+
const { wrapper } = await createClosedModal(
263+
{
264+
overlayTransition
265+
},
266+
{},
267+
{},
268+
{ transition: transitionStub() }
269+
)
270+
271+
const transitionComponent = wrapper
272+
.findComponent({
273+
ref: 'vfmOverlayTransition'
274+
})
275+
.attributes()
276+
expect(transitionComponent).toEqual(expect.objectContaining(overlayTransition))
277+
})
195278
})
196279

197280
describe('API', () => {

tests/unit/utils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export function afterTransition(callback, transitionDelay = 60) {
77
}, transitionDelay)
88
}
99

10+
export const transitionStub = () => ({
11+
render: function() {
12+
return this.$options._renderChildren
13+
}
14+
})
15+
1016
export function createOpenedModal(propsData = {}, listeners = {}, mountingOptions = {}) {
1117
const localVue = createLocalVue()
1218
localVue.use(VueFinalModal())
@@ -39,12 +45,12 @@ export function createOpenedModal(propsData = {}, listeners = {}, mountingOption
3945
})
4046
})
4147
}
42-
export function createClosedModal(propsData = {}, listeners = {}, mountingOptions = {}) {
48+
export function createClosedModal(propsData = {}, listeners = {}, mountingOptions = {}, stubs = false) {
4349
const localVue = createLocalVue()
4450
localVue.use(VueFinalModal())
4551
return new Promise(resolve => {
4652
const wrapper = mount(localVue.options.components.VueFinalModal, {
47-
stubs: false,
53+
stubs,
4854
localVue,
4955
propsData: {
5056
value: false,

0 commit comments

Comments
 (0)