register.test.js 1.5 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8
// jest官方文档: https://www.jestjs.cn/
// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start


describe('pages/ucenter/login-page/register/register.vue', () => {

	let page
	beforeAll(async () => {
study夏羽's avatar
update  
study夏羽 已提交
9
		page = await program.navigateTo('/pages/ucenter/login-page/register/register')
study夏羽's avatar
study夏羽 已提交
10
		await page.waitFor(500)
study夏羽's avatar
update  
study夏羽 已提交
11 12
		//navigateTo
		//redirectTo
study夏羽's avatar
study夏羽 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
	})

	 it('注册账号', async () => {

		let username = "数字天堂"
		let nickname = "DCloud"
		let password = "111111"
		let pwd2 = "111111"

		const setInput = await page.setData({
			formData: {
				"username": username,
				"nickname": nickname,
				'password': password,
				'pwd2': pwd2
			},
		})
study夏羽's avatar
update  
study夏羽 已提交
30
		console.log(await page.data('formData'),"0000000000000");
study夏羽's avatar
study夏羽 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

		expect(username).toMatch(/^.{3,20}$/);
		expect(password).toMatch(/^.{6,20}$/);
		expect(pwd2).toMatch(/^.{6,20}$/);
		expect(pwd2).toEqual(password);

		await page.setData({
			agree: true
		})

		const getUid = await page.waitFor(async () => {
			const resRegister = await page.callMethod('submit')
			await page.waitFor(300)
			return resRegister
		})
		console.log("getUid:---------- ",getUid.msg);
		if (getUid.uid) {
study夏羽's avatar
study夏羽 已提交
48
			// expect(getUid.msg).toBe("注册成功");
study夏羽's avatar
study夏羽 已提交
49 50 51
			expect(getUid.userInfo.username).toBe("数字天堂");
			await program.navigateTo('/pages/ucenter/settings/settings')
		} else {
study夏羽's avatar
测试  
study夏羽 已提交
52 53
			console.log("getUid.msg: ",getUid.msg);
			// expect(getUid.msg).toBe("此用户名已注册");
study夏羽's avatar
study夏羽 已提交
54
			// expect(getUid.msg).toBe("Account exists");
study夏羽's avatar
study夏羽 已提交
55 56 57 58
			await program.navigateTo('/pages/ucenter/login-page/pwd-login/pwd-login')
		}
	}) 
})