Skip to content

Commit

Permalink
test(test): implement e2e test with testcafe #3
Browse files Browse the repository at this point in the history
  • Loading branch information
weicheng2138 committed May 11, 2022
1 parent 698fff6 commit 71e30e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"prepare": "husky install",
"format-check": "npx prettier --check ./",
"format-write": "npx prettier --write ./",
"test": "vitest"
"test": "vitest",
"test:e2e": "testcafe chrome tests/"
},
"lint-staged": {
"*.{js,vue,ts}": [
Expand All @@ -38,6 +39,7 @@
"prettier": "^2.6.2",
"prettier-plugin-tailwindcss": "^0.1.10",
"tailwindcss": "^3.0.24",
"testcafe": "^1.18.6",
"typescript": "^4.6.4",
"vitest": "^0.12.4"
},
Expand Down
36 changes: 36 additions & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// import { Selector, ClientFunction } from 'testcafe'
import { Selector } from 'testcafe'

// fixture`Getting Started`.page`http://devexpress.github.io/testcafe/example`
fixture`Getting Started`.page`http://localhost:3000`

test('index page', async (t) => {
await t
// Use the assertion to check if the actual header text is equal to the expected one
.expect(Selector('h1').innerText)
.eql('Get Started')
})

// test('login layout without Drawer', async (t) => {
// const drawer = Selector('[data-testid="drawer"]').exists
// await t.expect(drawer).notOk
// })

// test('login with wrong account', async (t) => {
// await t
// .typeText('[data-testid="input-account"]', '[email protected]')
// .typeText('[data-testid="input-password"]', 'zxcvbnm')
// .click('[data-testid="submit"]')
// .expect(Selector('[data-testid="error"]').innerText)
// .eql('Error: 帳號不存在或密碼錯誤,請重新輸入。')
// })

// test('login success', async (t) => {
// await t
// .typeText('[data-testid="input-account"]', '[email protected]')
// .typeText('[data-testid="input-password"]', 'zxcvbnm')
// .click('[data-testid="submit"]')

// const getLocation = ClientFunction(() => document.location.href)
// await t.expect(getLocation()).contains('http://localhost:3000/')
// })

0 comments on commit 71e30e0

Please sign in to comment.