Browse Source

fix(keycodes-symphony-dom test): redefine function

pull/1572/head
nprimo 2 years ago committed by Niccolò Primo
parent
commit
c0d3cddadc
  1. 21
      js/tests/keycodes-symphony-dom_test.mjs

21
js/tests/keycodes-symphony-dom_test.mjs

@ -1,11 +1,12 @@
export const tests = [] export const tests = []
export const setup = async ({ page }) => ({ export const setup = async () => {
getNotes: async () => const getNotes = async (page) =>
await page.$$eval('.note', (nodes) => { await page.$$eval('.note', (nodes) => {
return nodes.map((note) => note.textContent) return nodes.map((note) => note.textContent)
}), })
}) return { getNotes }
}
const characters = `didyouhandlethekeydowneventcorrectly` const characters = `didyouhandlethekeydowneventcorrectly`
@ -14,7 +15,7 @@ tests.push(async ({ page, eq, ctx }) => {
for (const [i, character] of characters.split('').entries()) { for (const [i, character] of characters.split('').entries()) {
await page.keyboard.down(character) await page.keyboard.down(character)
const typed = characters.slice(0, i + 1).split('') const typed = characters.slice(0, i + 1).split('')
eq(await ctx.getNotes(), typed) eq(await ctx.getNotes(page), typed)
} }
}) })
@ -24,7 +25,7 @@ tests.push(async ({ page, eq, ctx }) => {
while (step < 10) { while (step < 10) {
await page.keyboard.down('Backspace') await page.keyboard.down('Backspace')
const typed = characters.slice(0, characters.length - step).split('') const typed = characters.slice(0, characters.length - step).split('')
eq(await ctx.getNotes(), typed) eq(await ctx.getNotes(page), typed)
step++ step++
} }
}) })
@ -32,8 +33,8 @@ tests.push(async ({ page, eq, ctx }) => {
tests.push(async ({ page, eq, ctx }) => { tests.push(async ({ page, eq, ctx }) => {
// check that all the notes are cleared when Escape key is pressed // check that all the notes are cleared when Escape key is pressed
await page.keyboard.down('Escape') await page.keyboard.down('Escape')
const cleared = (await ctx.getNotes()).length === 0 const cleared = (await ctx.getNotes(page)).length === 0
eq(await cleared, true) eq(cleared, true)
}) })
tests.push(async ({ page, eq }) => { tests.push(async ({ page, eq }) => {

Loading…
Cancel
Save