From f0c59af2be69e3f2a24b57d0774807bb371e3564 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Fri, 24 Jul 2020 17:26:08 +0800 Subject: [PATCH] feat: add the first test case --- packages/button/__tests__/button.spec.ts | 36 ++++++++++++++++++++++-- packages/button/src/index.vue | 4 +-- typings/vue-shim.d.ts | 6 ++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/button/__tests__/button.spec.ts b/packages/button/__tests__/button.spec.ts index a7f412fe58..cbaffccab0 100644 --- a/packages/button/__tests__/button.spec.ts +++ b/packages/button/__tests__/button.spec.ts @@ -1,6 +1,36 @@ +import {mount, config} from '@vue/test-utils' +import Button from '../src/index.vue' + +const AXIOM = 'Rem is the best girl' +const COMMON_CONFIG = { + global: { + provide: { + elForm: {}, + elFormItem: {}, + } + } +} + describe('Button.vue', () => { - test('hello world', () => { - const bestGirl = 'Rem' - expect(bestGirl).not.toMatch('Emilia') + test('render text', () => { + const instance = mount(Button, { + slots: { + default: AXIOM + }, + ...COMMON_CONFIG, + }) + expect(instance.text()).toEqual(AXIOM) + }) + + test('handle click', async () => { + const instance = mount(Button, { + slots: { + default: AXIOM + }, + ...COMMON_CONFIG, + }) + await instance.trigger('click') + expect(instance.emitted()).toBeDefined() + }) }) diff --git a/packages/button/src/index.vue b/packages/button/src/index.vue index 50e4025c7a..26b8d75155 100644 --- a/packages/button/src/index.vue +++ b/packages/button/src/index.vue @@ -29,7 +29,7 @@ const ELEMENT: { } = {} // TODOS: replace these interface definition with actual ElForm interface interface ElForm { - disabled: boolean; + disabled: boolean; } interface ElFormItem { elFormItemSize: number; @@ -89,4 +89,4 @@ export default { } } }; - \ No newline at end of file + diff --git a/typings/vue-shim.d.ts b/typings/vue-shim.d.ts index de1defd2c4..42c297747f 100644 --- a/typings/vue-shim.d.ts +++ b/typings/vue-shim.d.ts @@ -1,5 +1,7 @@ declare module '*.vue' { - import { Component } from 'vue' - const _default: Component + import { Component, ComponentPublicInstance } from 'vue' + const _default: Component & { + new (): ComponentPublicInstance + } export default _default }