From fa3b17fdaa45b93159724f14cab84a8b30f08670 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Sun, 12 Dec 2021 22:45:28 +0800 Subject: [PATCH] test(NoticeBar): add demo test --- example/app.json | 1 + example/pages/notice-bar/index.js | 7 +---- example/pages/notice-bar/index.wxml | 31 +------------------ packages/notice-bar/demo/index.json | 7 +++++ .../notice-bar/demo/index.less | 1 - packages/notice-bar/demo/index.ts | 8 +++++ packages/notice-bar/demo/index.wxml | 30 ++++++++++++++++++ packages/notice-bar/test/demo.spec.ts | 11 +++++++ 8 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 packages/notice-bar/demo/index.json rename example/pages/notice-bar/index.wxss => packages/notice-bar/demo/index.less (50%) create mode 100644 packages/notice-bar/demo/index.ts create mode 100644 packages/notice-bar/demo/index.wxml create mode 100644 packages/notice-bar/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index fbfda951..e5e5e403 100644 --- a/example/app.json +++ b/example/app.json @@ -99,6 +99,7 @@ "van-loading-demo": "./dist/loading/demo/index", "van-nav-bar": "./dist/nav-bar/index", "van-notice-bar": "./dist/notice-bar/index", + "van-notice-bar-demo": "./dist/notice-bar/demo/index", "van-notify": "./dist/notify/index", "van-notify-demo": "./dist/notify/demo/index", "van-panel": "./dist/panel/index", diff --git a/example/pages/notice-bar/index.js b/example/pages/notice-bar/index.js index a00afba2..cc11dfda 100644 --- a/example/pages/notice-bar/index.js +++ b/example/pages/notice-bar/index.js @@ -1,8 +1,3 @@ import Page from '../../common/page'; -Page({ - data: { - text: '在代码阅读过程中人们说脏话的频率是衡量代码质量的唯一标准。', - shortText: '技术是开发它的人的共同灵魂。', - }, -}); +Page(); diff --git a/example/pages/notice-bar/index.wxml b/example/pages/notice-bar/index.wxml index 8e5028bc..d84e1d4f 100644 --- a/example/pages/notice-bar/index.wxml +++ b/example/pages/notice-bar/index.wxml @@ -1,30 +1 @@ - - - - - - - - - - - - - - - - - - - - - - + diff --git a/packages/notice-bar/demo/index.json b/packages/notice-bar/demo/index.json new file mode 100644 index 00000000..a43d86d0 --- /dev/null +++ b/packages/notice-bar/demo/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-notice-bar": "../../notice-bar/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/notice-bar/index.wxss b/packages/notice-bar/demo/index.less similarity index 50% rename from example/pages/notice-bar/index.wxss rename to packages/notice-bar/demo/index.less index 1308e481..5597003f 100644 --- a/example/pages/notice-bar/index.wxss +++ b/packages/notice-bar/demo/index.less @@ -1,4 +1,3 @@ -/* pages/notice-bar/index.wxss */ .margin-top { margin-top: 4px; } diff --git a/packages/notice-bar/demo/index.ts b/packages/notice-bar/demo/index.ts new file mode 100644 index 00000000..a0555469 --- /dev/null +++ b/packages/notice-bar/demo/index.ts @@ -0,0 +1,8 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: { + text: '在代码阅读过程中人们说脏话的频率是衡量代码质量的唯一标准。', + shortText: '技术是开发它的人的共同灵魂。', + }, +}); diff --git a/packages/notice-bar/demo/index.wxml b/packages/notice-bar/demo/index.wxml new file mode 100644 index 00000000..8e5028bc --- /dev/null +++ b/packages/notice-bar/demo/index.wxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/notice-bar/test/demo.spec.ts b/packages/notice-bar/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/notice-bar/test/demo.spec.ts @@ -0,0 +1,11 @@ +import path from 'path'; +import simulate from 'miniprogram-simulate'; + +test('should render demo and match snapshot', () => { + const id = simulate.load(path.resolve(__dirname, '../demo/index'), { + rootPath: path.resolve(__dirname, '../../'), + }); + const comp = simulate.render(id); + comp.attach(document.createElement('parent-wrapper')); + expect(comp.toJSON()).toMatchSnapshot(); +});