From e14ca0b257cdbfd8be1c7ee1d6d6b41202aaa447 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Wed, 1 Dec 2021 23:59:53 +0800 Subject: [PATCH] test(Card): add demo test --- example/app.json | 1 + example/pages/card/index.js | 6 +- example/pages/card/index.wxml | 33 +-- packages/card/demo/index.json | 7 + .../card/demo/index.less | 0 packages/card/demo/index.ts | 8 + packages/card/demo/index.wxml | 32 +++ .../card/test/__snapshots__/demo.spec.ts.snap | 217 ++++++++++++++++++ packages/card/test/demo.spec.ts | 11 + 9 files changed, 278 insertions(+), 37 deletions(-) create mode 100644 packages/card/demo/index.json rename example/pages/card/index.wxss => packages/card/demo/index.less (100%) create mode 100644 packages/card/demo/index.ts create mode 100644 packages/card/demo/index.wxml create mode 100644 packages/card/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/card/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 3813fe43..bab31741 100644 --- a/example/app.json +++ b/example/app.json @@ -70,6 +70,7 @@ "van-button": "./dist/button/index", "van-button-demo": "./dist/button/demo/index", "van-card": "./dist/card/index", + "van-card-demo": "./dist/card/demo/index", "van-cell": "./dist/cell/index", "van-cell-group": "./dist/cell-group/index", "van-checkbox": "./dist/checkbox/index", diff --git a/example/pages/card/index.js b/example/pages/card/index.js index bcbac713..cc11dfda 100644 --- a/example/pages/card/index.js +++ b/example/pages/card/index.js @@ -1,7 +1,3 @@ import Page from '../../common/page'; -Page({ - data: { - imageURL: 'https://img.yzcdn.cn/upload_files/2017/07/02/af5b9f44deaeb68000d7e4a711160c53.jpg' - } -}); +Page(); diff --git a/example/pages/card/index.wxml b/example/pages/card/index.wxml index 0bc3b7ec..b3be7bb6 100644 --- a/example/pages/card/index.wxml +++ b/example/pages/card/index.wxml @@ -1,32 +1 @@ - - - - - - - - - 标签1 - 标签2 - - - 按钮 - 按钮 - - - - + diff --git a/packages/card/demo/index.json b/packages/card/demo/index.json new file mode 100644 index 00000000..d22c0b5c --- /dev/null +++ b/packages/card/demo/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-card": "../../card/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/card/index.wxss b/packages/card/demo/index.less similarity index 100% rename from example/pages/card/index.wxss rename to packages/card/demo/index.less diff --git a/packages/card/demo/index.ts b/packages/card/demo/index.ts new file mode 100644 index 00000000..05abaf53 --- /dev/null +++ b/packages/card/demo/index.ts @@ -0,0 +1,8 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: { + imageURL: + 'https://img.yzcdn.cn/upload_files/2017/07/02/af5b9f44deaeb68000d7e4a711160c53.jpg', + }, +}); diff --git a/packages/card/demo/index.wxml b/packages/card/demo/index.wxml new file mode 100644 index 00000000..0bc3b7ec --- /dev/null +++ b/packages/card/demo/index.wxml @@ -0,0 +1,32 @@ + + + + + + + + + 标签1 + 标签2 + + + 按钮 + 按钮 + + + + diff --git a/packages/card/test/__snapshots__/demo.spec.ts.snap b/packages/card/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..7b320cd9 --- /dev/null +++ b/packages/card/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,217 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + + 基础用法 + + + + + + + + + + + 2018秋冬新款男士休闲时尚军绿飞行夹克秋冬新款男 + + + 描述信息 + + + + + + ¥ + + + 2 + + + .00 + + + + x 2 + + + + + + + + + + + + + 高级用法 + + + + + + + + + + 标签 + + + + + + + + 2018秋冬新款男士休闲时尚军绿飞行夹克秋冬新款男 + + + 描述信息 + + + + 标签1 + + + 标签2 + + + + + + + ¥ + + + 2 + + + .00 + + + + ¥ 10.00 + + + x 2 + + + + + + + + 按钮 + + + 按钮 + + + + + + + + +
+`; diff --git a/packages/card/test/demo.spec.ts b/packages/card/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/card/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(); +});