From 166afd1b045e2c6e34857da3e1039aba9af4cac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Fri, 31 May 2019 10:03:25 +0800 Subject: [PATCH] [improvement] NavBar: add test cases --- packages/card/test/index.spec.js | 66 ++++++++----------- .../test/__snapshots__/index.spec.js.snap | 17 +++++ packages/nav-bar/test/index.spec.js | 23 +++++++ 3 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 packages/nav-bar/test/__snapshots__/index.spec.js.snap create mode 100644 packages/nav-bar/test/index.spec.js diff --git a/packages/card/test/index.spec.js b/packages/card/test/index.spec.js index 85a93fad8..f4af8a3c0 100644 --- a/packages/card/test/index.spec.js +++ b/packages/card/test/index.spec.js @@ -1,67 +1,57 @@ -import Vue from 'vue'; import Card from '..'; import { mount } from '../../../test/utils'; -Vue.use(Card); - -test('render origin-price slot', () => { - const wrapper = mount({ - template: ` - - - - ` +test('render price & num slot', () => { + const wrapper = mount(Card, { + scopedSlots: { + num: () => 'Custom Num', + price: () => 'Custom Price' + } }); expect(wrapper).toMatchSnapshot(); }); -test('render price & num slot', () => { - const wrapper = mount({ - template: ` - - - - - ` +test('render origin-price slot', () => { + const wrapper = mount(Card, { + scopedSlots: { + 'origin-price': () => 'Custom Origin Price' + } }); expect(wrapper).toMatchSnapshot(); }); test('render bottom slot', () => { - const wrapper = mount({ - template: ` - - - - ` + const wrapper = mount(Card, { + propsData: { + price: 100 + }, + scopedSlots: { + bottom: () => 'Custom Bottom' + } }); expect(wrapper).toMatchSnapshot(); }); test('render thumb & tag slot', () => { - const wrapper = mount({ - template: ` - - - - - ` + const wrapper = mount(Card, { + scopedSlots: { + tag: () => 'Custom Tag', + thumb: () => 'Custom Thumb' + } }); expect(wrapper).toMatchSnapshot(); }); test('render title & desc slot', () => { - const wrapper = mount({ - template: ` - - - - - ` + const wrapper = mount(Card, { + scopedSlots: { + title: () => 'Custom Title', + desc: () => 'Custom desc' + } }); expect(wrapper).toMatchSnapshot(); diff --git a/packages/nav-bar/test/__snapshots__/index.spec.js.snap b/packages/nav-bar/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..092b64cdc --- /dev/null +++ b/packages/nav-bar/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`render left & right slot 1`] = ` +
+
Custom Left
+
+
Custom Right
+
+`; + +exports[`render title slot 1`] = ` +
+
+
Custom Title
+
+
+`; diff --git a/packages/nav-bar/test/index.spec.js b/packages/nav-bar/test/index.spec.js new file mode 100644 index 000000000..12ce9cbe2 --- /dev/null +++ b/packages/nav-bar/test/index.spec.js @@ -0,0 +1,23 @@ +import NavBar from '..'; +import { mount } from '../../../test/utils'; + +test('render left & right slot', () => { + const wrapper = mount(NavBar, { + scopedSlots: { + left: () => 'Custom Left', + right: () => 'Custom Right' + } + }); + + expect(wrapper).toMatchSnapshot(); +}); + +test('render title slot', () => { + const wrapper = mount(NavBar, { + scopedSlots: { + title: () => 'Custom Title' + } + }); + + expect(wrapper).toMatchSnapshot(); +});