本文介绍了Javascript量角器-将外部函数视为未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pages/TablePage.js中是页面对象

In pages/TablePage.js is a page object

在regex2中,尝试使用TablePage.js中的函数

in regex2 there is a try to use a function from TablePage.js

   it('regex2', function(){
            table_page.matchPriceRegex(table_page.workingBalanceField)
        });

是说table_page.matchPriceRegex is not a function

TablePage.js中的函数本身:

The function itself from TablePage.js:

var TablePage = (function () {

  function TablePage() {
    this.workingBalanceField = element(By.xpath('//*[@id="root"]/main/section/div/div/div[5]/div/div[1]'));
  }

  TablePage.prototype.matchPriceRegex = function (locator) {
    this.text = locator.getText();
    expect(this.text).toMatch("\d{0,3}?,?\d{0,3}?\.?\d{0,3}?");
  };
});
module.exports = TablePage;

需求文件已包含在规范文件中,因此它应该可以看到

The require's are incorporated with the spec file so it should see it

var TablePage = require("./../pages/TablePage");
var table_page = new TablePage();
var protractor = require("protractor");
var jasmine = require("jasmine-node");
var browser = protractor.browser;
var number = 0;

在我的IDE(WebStorm)中,按住ctrl并单击函数名称,它会正确地重定向我,如它所见

When in my IDE(WebStorm) I hold ctrl and click on the function name it redirects me correctly, as it sees it

TablePage中的函数或变量的类型未定义

The typeof the functions or variables form TablePage is undefined

您知道问题出在哪里吗?

Do you know where is the problem?

推荐答案

错误来自TablePage.js,应该是.

var TablePage = (function () {

  function TablePage() {
    this.workingBalanceField = element(By.xpath('//*[@id="root"]/main/section/div/div/div[5]/div/div[1]'));
  }

  TablePage.prototype.matchPriceRegex = function (locator) {
    this.text = locator.getText();
    expect(this.text).toMatch("\d{0,3}?,?\d{0,3}?\.?\d{0,3}?");
  };

  return TablePage; // return the class as outer function return value
})(); 
// `(function(...){})` return a function, you should use `()` to execute the
// return function to get the returned class: TablePage.

module.exports = TablePage;

这篇关于Javascript量角器-将外部函数视为未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 12:25