我是 UI 开发的新手,最近我开始使用 Typescript 在 React 中编写代码。我创建了一个按钮,单击该按钮后,它会打开一个菜单,其中包含一些可供选择的选项。如果我单击其中一个选项,将打开一个带有某个目标 URL 的新选项卡。我正在使用
window.open(target_URL, "_blank");
来实现这一点。
现在我正在为我的代码编写测试用例,我想编写一个测试用例来检查如果我单击该选项,它会打开一个带有 target_URL 的新选项卡。
const myButton: HTMLElement = TestUtils.findRenderedDOMComponentWithClass(renderedComponent, "my-button") as HTMLElement;
expect(myButton).to.not.be.undefined;
// Click the Button and check number of options displayed
TestUtils.Simulate.click(myButton);
const menuItems: HTMLElement[] = TestUtils.scryRenderedDOMComponentsWithClass(renderedComponent, "ms-ContextualMenu-item") as HTMLElement[];
expect(menuItems).to.not.be.undefined;
expect(menuItems.length).to.be.equal(4, "4 options dispalyed");
const menuItem1: HTMLElement = TestUtils.findRenderedDOMComponentWithClass(renderedComponent, "menu-item-1") as HTMLElement;
TestUtils.Simulate.click(menuItem1);
Run Code Online (Sandbox Code Playgroud)
我已经编写了上面的代码,但我不确定如何完成此代码以检查在浏览器中打开新选项卡的情况。
我需要从ArrayList中删除一些元素.我用的removeAll(List)方法.但问题是它也删除了重复项.我如何保留重复项?
考虑下面的例子 -
我有一个 List a1 = {2, 3, 4, 5, 2, 2, 3}
现在我有了另一个
List a2 = {2, 3}
Run Code Online (Sandbox Code Playgroud)
当我使用时,a1.removeAll(a2)我将a1 = {4, 5}
删除所有2和3的实例.
我需要的是a1 = {4, 5, 2, 2, 3}
a2中存在的实例数应该从a1中删除.
我怎样才能做到这一点?