register.test.js 1.7 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
study夏羽 已提交
9
		page = await program.redirectTo('/pages/ucenter/login-page/register/register')
study夏羽's avatar
study夏羽 已提交
10
		await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
11
		console.log("program.pageStack: ",await program.pageStack());
study夏羽's avatar
study夏羽 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25
	})

	 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,
study夏羽's avatar
study夏羽 已提交
26 27
				'pwd2': pwd2,
				"captcha": "1234"
study夏羽's avatar
study夏羽 已提交
28 29
			},
		})
study夏羽's avatar
study夏羽 已提交
30
		console.log(await page.data('formData'),"setData----formData");
study夏羽's avatar
study夏羽 已提交
31 32 33 34 35 36 37 38 39

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

		await page.setData({
			agree: true
		})
study夏羽's avatar
study夏羽 已提交
40 41 42 43 44
		
		
		
		const resRegister = await page.waitFor(async () => {
			return await page.callMethod('submit')
study夏羽's avatar
study夏羽 已提交
45
		})
study夏羽's avatar
study夏羽 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
		
		console.log("resRegister: ",resRegister);
		
		
		switch (resRegister.code){
			case 0:
				console.log('注册成功')
				// expect(resRegister.userInfo.username).toBe("数字天堂");
				// 	await program.navigateTo('/pages/ucenter/settings/settings')
				break;
			case 20102:
				expect(resRegister.errMsg).toBe("此账号已注册");
				// expect(getUid.msg).toBe("此用户名已注册");
				// expect(getUid.msg).toBe("Account exists");
				// 	await program.navigateTo('/pages/ucenter/login-page/pwd-login/pwd-login')
				break;
			default:
				break;
study夏羽's avatar
study夏羽 已提交
64
		}
study夏羽's avatar
study夏羽 已提交
65
		
study夏羽's avatar
study夏羽 已提交
66 67
	}) 
})