From b6381a0b319029458724c5f6dcfa1827818c7dc6 Mon Sep 17 00:00:00 2001 From: nemo-shen Date: Thu, 2 Dec 2021 13:23:14 +0800 Subject: [PATCH] test(Col): add demo test --- example/app.json | 1 + example/pages/col/index.wxml | 25 +-- packages/col/demo/index.json | 8 + .../col/demo/index.less | 0 packages/col/demo/index.ts | 5 + packages/col/demo/index.wxml | 24 +++ .../col/test/__snapshots__/demo.spec.ts.snap | 146 ++++++++++++++++++ packages/col/test/demo.spec.ts | 11 ++ 8 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 packages/col/demo/index.json rename example/pages/col/index.wxss => packages/col/demo/index.less (100%) create mode 100644 packages/col/demo/index.ts create mode 100644 packages/col/demo/index.wxml create mode 100644 packages/col/test/__snapshots__/demo.spec.ts.snap create mode 100644 packages/col/test/demo.spec.ts diff --git a/example/app.json b/example/app.json index 3ad883ba..60d28a40 100644 --- a/example/app.json +++ b/example/app.json @@ -78,6 +78,7 @@ "van-checkbox-demo": "./dist/checkbox/demo/index", "van-checkbox-group": "./dist/checkbox-group/index", "van-col": "./dist/col/index", + "van-col-demo": "./dist/col/demo/index", "van-count-down": "./dist/count-down/index", "van-dialog": "./dist/dialog/index", "van-divider": "./dist/divider/index", diff --git a/example/pages/col/index.wxml b/example/pages/col/index.wxml index f91b4773..e2008cfa 100644 --- a/example/pages/col/index.wxml +++ b/example/pages/col/index.wxml @@ -1,24 +1 @@ - - - span: 8 - span: 8 - span: 8 - - - - span: 4 - offset: 4, span: 10 - - - - offset: 12, span: 12 - - - - - - span: 8 - span: 8 - span: 8 - - + diff --git a/packages/col/demo/index.json b/packages/col/demo/index.json new file mode 100644 index 00000000..8addcef1 --- /dev/null +++ b/packages/col/demo/index.json @@ -0,0 +1,8 @@ +{ + "component": true, + "usingComponents": { + "van-row": "../../row/index", + "van-col": "../../col/index", + "demo-block": "../../../example/components/demo-block/index" + } +} diff --git a/example/pages/col/index.wxss b/packages/col/demo/index.less similarity index 100% rename from example/pages/col/index.wxss rename to packages/col/demo/index.less diff --git a/packages/col/demo/index.ts b/packages/col/demo/index.ts new file mode 100644 index 00000000..a32755a5 --- /dev/null +++ b/packages/col/demo/index.ts @@ -0,0 +1,5 @@ +import { VantComponent } from '../../common/component'; + +VantComponent({ + data: {}, +}); diff --git a/packages/col/demo/index.wxml b/packages/col/demo/index.wxml new file mode 100644 index 00000000..f91b4773 --- /dev/null +++ b/packages/col/demo/index.wxml @@ -0,0 +1,24 @@ + + + span: 8 + span: 8 + span: 8 + + + + span: 4 + offset: 4, span: 10 + + + + offset: 12, span: 12 + + + + + + span: 8 + span: 8 + span: 8 + + diff --git a/packages/col/test/__snapshots__/demo.spec.ts.snap b/packages/col/test/__snapshots__/demo.spec.ts.snap new file mode 100644 index 00000000..2339a35b --- /dev/null +++ b/packages/col/test/__snapshots__/demo.spec.ts.snap @@ -0,0 +1,146 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render demo and match snapshot 1`] = ` +
+ + + + 基础用法 + + + + + + span: 8 + + + + + span: 8 + + + + + span: 8 + + + + + + + + + span: 4 + + + + + offset: 4, span: 10 + + + + + + + + + offset: 12, span: 12 + + + + + + + + + + 在列元素之间增加间距 + + + + + + span: 8 + + + + + span: 8 + + + + + span: 8 + + + + + + +
+`; diff --git a/packages/col/test/demo.spec.ts b/packages/col/test/demo.spec.ts new file mode 100644 index 00000000..4c3798cb --- /dev/null +++ b/packages/col/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(); +});