diff --git a/env.js b/env.js new file mode 100644 index 0000000000000000000000000000000000000000..d7553e4b031ce918e67a304b6b15a63e67ac8c8f --- /dev/null +++ b/env.js @@ -0,0 +1,38 @@ +module.exports = { + "is-custom-runtime": false, + "compile": true, + "h5": { + "options": { + "headless": true + }, + "executablePath": "" + }, + "mp-weixin": { + "port": 9420, + "account": "", + "args": "", + "cwd": "", + "launch": true, + "teardown": "disconnect", + "remote": false, + "executablePath": "" + }, + "app-plus": { + "android": { + "id": "", + "executablePath": "" + }, + "version": "", + "ios": { + "id": "", + "executablePath": "" + }, + "uni-app-x": { + "version": "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/uniappx-launcher/base/version.txt", + "android": { + "id": "emulator-5554", + "executablePath": "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/uniappx-launcher/base/android_base.apk" + } + } + } +} \ No newline at end of file diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000000000000000000000000000000000..882d3642fc1699f6bc7e6a83120ca8a040d2fdc7 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,11 @@ +module.exports = { + testTimeout: 10000, + reporters: [ + 'default' + ], + watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], + moduleFileExtensions: ['js', 'json'], + rootDir: __dirname, + testMatch: ["/pages/**/*test.[jt]s?(x)"], + testPathIgnorePatterns: ['/node_modules/'] +} diff --git a/pages/component/button/button.test.js b/pages/component/button/button.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3a3c201159fa41f52b3402da52b60d6e823666a4 --- /dev/null +++ b/pages/component/button/button.test.js @@ -0,0 +1,82 @@ +function getData(key = '') { + return new Promise(async (resolve, reject) => { + const data = await page.data() + resolve(key ? data[key] : data) + }) +} + +let page +beforeAll(async () => { + page = await program.reLaunch('/pages/component/button/button') + await page.waitFor(1000) +}) + +describe('Button.uvue', () => { + it('click', async () => { + const defaultBtn = await page.$('.default-button') + const disabledBtn = await page.$('.disabled-button') + expect(await getData('count')).toEqual(0) + await defaultBtn.tap() + expect(await getData('count')).toEqual(1) + await disabledBtn.tap() + expect(await getData('count')).toEqual(1) + }) + it('length', async () => { + const btnLen = await page.$$('.button') + expect(btnLen.length).toBe(13) + }) + it('text', async () => { + const textBtn = await page.$('.text-button') + expect(await textBtn.text()).toEqual('按钮') + await page.setData({ + text: 'button' + }) + // TODO 待修复 + expect(await textBtn.text()).toEqual('button') + }) + it('type', async () => { + // TODO 目前获取组件属性只能通过组件的name,并且拿到的是最后一个 + const btn = await page.$('Button') + expect(await btn.property('type')).toBe('warn') + await page.setData({ + type: 'default' + }) + await page.waitFor(500) + expect(await btn.property('type')).toBe('default') + await page.setData({ + type: 'warn' + }) + await page.waitFor(500) + expect(await btn.property('type')).toBe('warn') + }) + it('size', async () => { + const btn = await page.$('Button') + expect(await btn.property('size')).toBe('mini') + await page.setData({ + size: 'default' + }) + await page.waitFor(500) + expect(await btn.property('size')).toBe('default') + await page.setData({ + size: 'mini' + }) + }) + it('plain', async () => { + const btn = await page.$('Button') + expect(await btn.property('plain')).toBe(false) + await page.setData({ + plain: true + }) + await page.waitFor(500) + expect(await btn.property('plain')).toBe(true) + }) + it('disabled', async () => { + const btn = await page.$('Button') + expect(await btn.property('disabled')).toBe(false) + await page.setData({ + disabled: true + }) + await page.waitFor(500) + expect(await btn.property('disabled')).toBe(true) + }) +}) \ No newline at end of file diff --git a/pages/component/button/button.uvue b/pages/component/button/button.uvue index 8e7d90f2438ad47e4c90019183015e94c309816f..31a3c1cd59ad5c472fadb7fac2c1757944b0f849 100644 --- a/pages/component/button/button.uvue +++ b/pages/component/button/button.uvue @@ -2,18 +2,18 @@ - + - - + + - + @@ -24,7 +24,8 @@ - + @@ -36,7 +37,13 @@ return { title: 'button', loading: false, - _timer: 0 + _timer: 0, + text: '按钮', + type: 'warn', + size: 'mini', + plain: false, + disabled: false, + count: 0 } }, onShow() { @@ -55,6 +62,9 @@ // clearTimeout(this._timer); // } // } + addCount() { + this.count++ + } }, }