add.test.js 1.9 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
describe('pages/user-info/add.vue', () => {

	let page
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch('/pages/user-info/add')
		if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
			await page.waitFor(1000)
		}
		if (process.env.UNI_PLATFORM === "mp-weixin") {
			await page.waitFor(1000);//微信等待
		}
		page = await program.currentPage()
		// console.log("page-add: ",page);
	})


	beforeEach(async()=>{
		jest.setTimeout(20000)
		return false
	})
	
	it('输入表单内容', async () => {
		
		
		const getForm = await page.data('formData')
A
Anne_LXM 已提交
27
		// console.log("getForm: ",getForm);
study夏羽's avatar
study夏羽 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
		
		let username = "林小明"
		let weight = 51
		let mobile = "17769516066"
		let email = "1076998870@qq.com"
		let url = "https://dcloud.io/"
		const setForm = await page.setData({
			"formData": {
				"username":username,
				"gender":1,
				"birth_date": 1612519694000,
				"weight":weight,
				"mobile":mobile,
				"email":email,
				"url":url,
				"favorite_book_id": "4",
				"address_code": "110105",
				"party_member": true,
				"hobby":["dance"],
				"comment": "好的"
			}
		})
		//console.log(await page.data('formData'), "setForm---");
		
		//姓名只能输入中文
		//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)
		const subRes = await page.callMethod('submit')
		console.log("subRes: ",subRes);
	})
	
	
	
})