0

这里有一个doozy。仍在试图弄清楚整个类型脚本的事情。基本上我正在做的是我试图从我制作的实用程序文件中调用一个函数并且我得到 --- 评估失败:ReferenceError:testUtils_test_1 未定义。问题是当我尝试调用我制作的遍历函数时。我可能需要在函数本身中修复更多的东西,但我还没有完全解决它,因为该函数甚至没有从我的测试中执行。我正在使用 Jest+puppeteer 和 .ts

测试在 .test.ts 文件中,函数在单独的 testUtils.test.ts 文件中

  • 我已经完成了正确的导入语句

这可能是我犯的一个简单错误,但我是新手。解释会很有帮助!提前致谢。

test('testing', async () => {
      // click on location targeting (there is three elements that match this selector)
      await page.click('#root > div > div.euiPage.euiPage--paddingMedium.euiPage--grow.euiPage-- > main > div > div:nth-child(3) > div.euiFlexItem.euiFlexItem--flexGrowZero > div')
      await page.waitForTimeout(3000)
      console.log('far')
      await page.waitForSelector('#showBusinessTypeFlyout')
      await page.click('#showBusinessTypeFlyout')
      console.log('keep')
      await page.waitForSelector('ul[aria-label="Business type categories"]')

      await page.$eval('ul[aria-label="Business type categories"]', () => { // could also use page.evaluate here
        traverse('ul[aria-label="Business type categories"]')
      })
      expect(page).toContain('') // placeholder test

    }, 100000)
    
    
// NEXT SNIPPET ///////////////////////

export const traverse = async function(selector:string){
  // get children of selector as Elements

    const list: HTMLCollectionOf<Element> = await page.$eval(selector, uiElement => {
      return uiElement.getElementsByClassName('euiTreeView__node euiTreeView--compressed')
    })
    console.log(list.length)
    // loop through each element in selectors array
    for (let category of list) {
      let sel = 'li[class=' + category.getAttribute('class') + ']'
      console.log(sel)
      await page.click('sel')

      if (category.childElementCount > 0) {
        await traverse(sel)
      }
      const list: HTMLCollectionOf<Element> = await page.$eval('ul[class=euiListGroup euiListGroup-flush euiListGroup-bordered', uiElement => {
        return uiElement.getElementsByClassName('li[class=euiListGroupItem--small euiListGroupItem-isClickable')
      })
      console.log(list.length)

      for (let businessType of list) {
        let sel = 'li[class=' + businessType.getAttribute('class') + ']'
        await page.click(sel)
        await page.click('body > div:nth-child(21) > div:nth-child(3) > div > div.euiFlyoutFooter > div > div > button > span > span')
        await expect(null) // placeholder
        await page.click('#showBusinessTypeFlyout > span > span')

      }
    }
}
    
    
    

4

0 回答 0