From 7a56fb426d5a6ad2a5d07c3fbc0dd2f479c8e64c Mon Sep 17 00:00:00 2001 From: Anne_LXM <54163582+anne-lxm@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:27:35 +0800 Subject: [PATCH] add testSequencer.js --- pages/user-info/detail.test.js | 23 ++++++++++++++++++ pages/user-info/detail.test1.js | 28 ---------------------- pages/user-info/edit.test1.js | 27 +++++++-------------- pages/user-info/list.test.js | 25 ++++++++++++++++++++ pages/user-info/list.test1.js | 42 --------------------------------- testSequencer.js | 16 +++++++++++++ 6 files changed, 73 insertions(+), 88 deletions(-) create mode 100644 pages/user-info/detail.test.js delete mode 100644 pages/user-info/detail.test1.js create mode 100644 pages/user-info/list.test.js delete mode 100644 pages/user-info/list.test1.js create mode 100644 testSequencer.js diff --git a/pages/user-info/detail.test.js b/pages/user-info/detail.test.js new file mode 100644 index 0000000..52aa70f --- /dev/null +++ b/pages/user-info/detail.test.js @@ -0,0 +1,23 @@ +describe('pages/user-info/detail.vue', () => { + let page + beforeAll(async () => { + // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) + // page = await program.navigateTo('/pages/user-info/detail') + page = await program.currentPage() + await page.waitFor('view') + // console.log('page: ',page); + }) + it('点击修改',async()=>{ + // expect.assertions(1); + const getQuery = await page.query + console.log('getQuery: ',getQuery); + await page.callMethod('handleUpdate') + await page.waitFor(1000) + console.log('currentPage',await program.currentPage()) + // console.log('query',await page.query) + expect((await program.currentPage()).path).toBe('pages/user-info/edit') + }) + // it('点击删除',async()=>{ + // const handleDelete = await page.callMethod('handleDelete') + // }) +}) \ No newline at end of file diff --git a/pages/user-info/detail.test1.js b/pages/user-info/detail.test1.js deleted file mode 100644 index 5a84d3e..0000000 --- a/pages/user-info/detail.test1.js +++ /dev/null @@ -1,28 +0,0 @@ -describe('pages/user-info/detail.vue', () => { - - let page - beforeAll(async () => { - // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) - page = await program.reLaunch('/pages/user-info/detail') - await page.waitFor('view') - page = await program.currentPage() - }) - - - it('点击修改',async()=>{ - const getId = await page.data('_id') - console.log("getId: ",getId); - expect.assertions(1); - const getQuery = await page.query - console.log('getQuery: ',getQuery); - expect(getQuery).not.toBeUndefined(); - const handleUpdate = await page.callMethod('handleUpdate') - }) - - - it('点击删除',async()=>{ - const handleDelete = await page.callMethod('handleDelete') - }) - - -}) \ No newline at end of file diff --git a/pages/user-info/edit.test1.js b/pages/user-info/edit.test1.js index 00798f1..1cd23f2 100644 --- a/pages/user-info/edit.test1.js +++ b/pages/user-info/edit.test1.js @@ -1,23 +1,21 @@ describe('pages/user-info/detail.vue', () => { - let page beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) - - page = await program.reLaunch('/pages/user-info/edit?id=601d044ac9e7be0001cc00b8') - await page.waitFor('view') + // page = await program.navigateTo('/pages/user-info/edit?id=601d044ac9e7be0001cc00b8') page = await program.currentPage() + console.log('page: ',page); + await page.waitFor('view') }) - it('修改表单内容', async () => { - + const getQuery = await page.query + console.log('getQuery: ',getQuery); let username = "林小明加" let weight = 51 let mobile = "17766666666" let email = "1076998866@qq.com" let url = "https://dcloud.io/" - - const setForm = await page.setData({ + await page.setData({ "formData": { "username":username, "gender":1, @@ -34,27 +32,20 @@ describe('pages/user-info/detail.vue', () => { } }) await page.waitFor(1000) - //console.log(await page.data('formData'), "setForm---"); - //姓名只能输入中文 - //expect(username).toMatch(/^[\u4e00-\u9fa5]+/); - + expect(username).toMatch(/^[\u4e00-\u9fa5]+/); //手机号校验 expect(mobile).toMatch(/^1[3|4|5|7|8][0-9]{9}$/); - - //var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/ expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/); - //url验证 const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/; expect(url).toMatch(urlEx); - //体重要大于50 小于或等于500 expect(weight).toBeGreaterThan(50) expect(weight).toBeLessThanOrEqual(500) - await page.callMethod('submit') - + const res = await page.callMethod('submit') + console.log('res: ',res); }) }) \ No newline at end of file diff --git a/pages/user-info/list.test.js b/pages/user-info/list.test.js new file mode 100644 index 0000000..82b3d10 --- /dev/null +++ b/pages/user-info/list.test.js @@ -0,0 +1,25 @@ +// jest.setTimeout(20000) +describe('pages/user-info/list.vue', () => { + let page,currentPage; + beforeAll(async () => { + // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) + page = await program.navigateTo('/pages/user-info/list') + await page.waitFor('view') + }) + it('点击fab跳转到添加页',async()=>{ + await page.callMethod('fabClick') + currentPage = await program.currentPage() + expect(currentPage.path).toBe('pages/user-info/add') + await program.navigateBack() + }) + it('点击第一条',async()=>{ + const items = await page.$$('.uni-list-item') + await items[0].tap() + await page.waitFor(500) + currentPage = await program.currentPage() + // console.log('currentPage:---3 ',currentPage); + expect(currentPage.path).toBe('pages/user-info/detail') + // await program.navigateBack() + // console.log('currentPage',await program.currentPage()) + }) +}) \ No newline at end of file diff --git a/pages/user-info/list.test1.js b/pages/user-info/list.test1.js deleted file mode 100644 index c9f7af5..0000000 --- a/pages/user-info/list.test1.js +++ /dev/null @@ -1,42 +0,0 @@ -describe('pages/user-info/list.vue', () => { - - let page - beforeAll(async () => { - // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) - page = await program.reLaunch('/pages/user-info/list') - await page.waitFor('view') - page = await program.currentPage() - }) - - // beforeEach(async()=>{ - // jest.setTimeout(20000) - // return false - // }) - it('点击第一条',async()=>{ - const items = await page.$$('.uni-list-item') - // console.log('items: ',items); - await items[0].tap() - }) - - /* it('点击某一条',async()=>{ - const getDataList = await page.data('dataList') - console.log("getDataList: ",getDataList); - for (var i = 0; i < getDataList.length; i++) { - console.log("getDataList[i]: ",getDataList[i]); - } - const uId = getDataList[0]._id - console.log("uId: ",uId); - - if(uId){ - const handleItemClick = await page.callMethod('handleItemClick',uId) - } - - }) */ - - - - it('点击fab跳转到添加页',async()=>{ - const fabClick = await page.callMethod('fabClick') - }) - -}) \ No newline at end of file diff --git a/testSequencer.js b/testSequencer.js new file mode 100644 index 0000000..85ac482 --- /dev/null +++ b/testSequencer.js @@ -0,0 +1,16 @@ +const Sequencer = require("@jest/test-sequencer").default; +const sortTestFilenames = ["add.test.js","list.test.js","detail.test.js","edit.test.js"]; +class CustomSequencer extends Sequencer { + sort(tests) { + // 测试例排序 + const copyTests = Array.from(tests); + const sortTests = sortTestFilenames + .map((filename) => { + return copyTests.find((test) => test.path.endsWith(filename)); + }) + .filter(Boolean); + console.log(sortTests); + return [...new Set([...sortTests, ...copyTests])]; + } +} +module.exports = CustomSequencer; -- GitLab