Uncaught SyntaxError:公共玩家中的意外标识符

时间:2017-08-20 17:01:21

标签: javascript angular typescript jasmine karma-runner

  • 我是茉莉和测试用例的新手
  • 我正试图在小提琴中为我的js代码编写测试用例。
  • 但我面临着一个错误。 未捕获的SyntaxError:意外的标识符
  • 你能告诉我如何解决它。
  • 在下面提供我的代码
  • 我应该使用玩家方法吗?
  • 我是否需要传递玩家的所有参数

http://jsfiddle.net/2yw4o6z8/1/

public players(container: any, options: any, that: any,selectedoptions) {
    $(".displayInlineBlock").removeClass("SWIMMINGumentMobileDiplay");
    let SWIMMINGImageMobile = "SWIMMINGumentMobile";

    let extensionType = {
      ".pdf": "pdfMobile",
      ".ppt": "pptMobile",
      ".xls": "xlsMobile",
      ".xlsx": "xlsMobile",
      ".SWIMMING": "SWIMMINGumentMobile",
      ".SWIMMINGx": "SWIMMINGumentMobile",
      ".msg": "mailMobile"
    };
    let lastIndex = options.model.SWIMMINGumentName.lastIndexOf(".");

    SWIMMINGImageMobile = extensionType[options.model.SWIMMINGumentName.slice(lastIndex).toLowerCase()];

    if (typeof options.model.SWIMMINGumentMobile != "undefined" && options.model.SWIMMINGumentMobile != "") {
      SWIMMINGImageMobile = options.model.SWIMMINGumentMobile;
    }
    if (typeof SWIMMINGImageMobile == "undefined") {
      SWIMMINGImageMobile = "newDocMobile";
    }
    let kendotxtMenu = "";
    if (options.model.isElfDoc == true) {
      kendotxtMenu = "SWIMMINGumentMobileDiplay";
    }
    //"isElfDoc":true;

    let input = $("<span class='" + SWIMMINGImageMobile + " displayInlineBlock " + options.model.SWIMMINGumentlength + " " + kendotxtMenu + " ' ></span><ul class='fileTypeHolder' id='fileTypeMobiles' style='display: none;'><li class='fileTypeHolderTitle'>ELF Document Type</li><li><span class='SWIMMINGumentMobile displayInlineBlock' (click)='browseFileType(SWIMMING)'></span></li> <li><span class='xlsMobile displayInlineBlock' (click)='browseFileType('xls')'></span></li> <li><span class='pptMobile displayInlineBlock'(click)='browseFileType('ppt')'></span></li> <li><span class='pdfMobile displayInlineBlock' (click)='browseFileType('pdf')'></span></li><li><span class='newDocMobile displayInlineBlock' (click)='browseFileType('newSWIMMING')'></span></li><li><span class='mailMobile displayInlineBlock' (click)='browseFileType('mail')'></span></li><li class='fileTypeHolderCloseBtn'> <button id='CloseBtn' class='commonBtn'>Close</button></ul>");
    input.appendTo(container);
    // <button class='commonBtn' id='CloseBtn'>Close</button>
    this.selectedoptions = null;
    this.selectedoptions = options;
    $("#fileTypeMobiles").kendoContextMenu({
      target: ".SWIMMINGumentMobileDiplay",
      showOn: "click",
      open: function(e) {

        //  console.log($(this).index(this));
        // console.log($(this).index());
      },
      select: function(e) {

        //console.log(e.item.firstElementChild);
        //console.log(e.item.firstElementChild.firstElementChild.className);
        var ReturnClassName = e.item.firstElementChild.firstElementChild.className
        if (ReturnClassName == "commonBtn") {
          return false;
        }

        let firstClass = $("." + options.model.SWIMMINGumentlength).attr('class').split(" ")[0];
        var extensionType = {
          "pdfMobile": "pdf",
          "pptMobile": "ppt",
          "xlsMobile": "xls",
          "SWIMMINGumentMobile": "SWIMMING",
          "newDocMobile": "default",
          "mailMobile": "msg"
        };
        var classNames = "pdfMobile pptMobile xlsMobile SWIMMINGumentMobile mailMobile newDocMobile";

        var classes = $("." + options.model.SWIMMINGumentlength).attr('class').split(" ");
        $("#" + options.model.SWIMMINGumentlength).val("." + extensionType[ReturnClassName.split(" ")[0]]);
        options.model.SWIMMINGumentName = "";
        options.model.SWIMMINGumentName = "." + extensionType[ReturnClassName.split(" ")[0]];
        options.model.isElfDoc = false;
        for (var c = 0; c < classes.length; c++) {
          if (classNames.includes(classes[c])) {
            $("." + options.model.SWIMMINGumentlength).removeClass(classes[c]);

          }
        }
        options.model.SWIMMINGumentMobile = ReturnClassName.split(" ")[0];
        $("." + options.model.SWIMMINGumentlength).addClass(e.item.firstElementChild.firstElementChild.className);
        //$("."+options.model.SWIMMINGumentId).addClass("displayInlineBlock");
        $("." + options.model.SWIMMINGumentlength).addClass("SWIMMINGumentMobileDiplay");


        let data_source = that.gridkendo._dataSource.data();
        for (let d = 0; d < data_source.length; d++) {
          if (data_source[d].isElfDoc == true && data_source[d].elfDocID == "") {
            that.gridkendo.enableSaveDocument(false);
          }

        }

      }
    });


}

describe("Our data array", function() {
  it("has four items", function() {
    expect(players()).toBe(0);
  });
});

1 个答案:

答案 0 :(得分:0)

主要问题是JSFiddle没有为您编译TypeScript到JavaScript。

尝试使用TypeScript游乐场,如果需要,将JavaScript复制到JSFiddle。

其他问题

你还没有将公共方法包含在一个类中......将你的players方法包装在一个类中......即。

class Example {
    public players(...) { }
}

您需要创建Example类的实例才能使用该方法,除非您将其设为静态:

const example = new Example();
example.players(...);

您还需要指定属性&#34; selectedoptions&#34;当你突然引用它时,你会惊讶编译器。在课堂内添加:

private selectedoptions: any;

您还需要做一些工作才能使方法返回值。你没有传递任何论据,所以你在整个商店都没有定义。

如果你得到它&#34;运行&#34;,由于options未定义,你会看到测试失败:

http://jsfiddle.net/om4pc7s8/1/

我希望这会有所帮助。