Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

複製鈕不容易測試複製內容 #34

@a8568730

Description

@a8568730

希望能夠測試複製內容的正確性

it("copys the same as original text", () => {
      let 欲複製字串 = "A-hí--á láu --tio̍h,";
      const { wrapper, button, oncopy } = mountSetup(欲複製字串);
      button.simulate('click');
      expect(wrapper.find("textarea").innerText).to.equal(true);
});

但是因為複製方式是寫在同一个函式裡頭,建立臨時的<textarea/>,複製完就移除它。
所以沒辦法在移除之前測試複製內容。

copy() {
    const { 複製內容 } = this.props;
    //建立一个臨時的複製區塊
    const textField = document.createElement("textarea");
    textField.innerText = 複製內容;//.toString().replace(/ --/g, "--");
    document.body.appendChild(textField);
    textField.select();
    document.execCommand("copy");
    // 馬上移除掉
    textField.remove();
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions