Testcafe - 如何断言两个不同的 location.pathname

Testcafe - How to assert two different location.pathname

我正在使用 testcafe 并且我有两个平台(Live 和 UAT)。我想将这两个路径名都包含在我的断言中,我尝试使用下面的路径名,但它不起作用。有什么想法吗?

//Live pathname = /next
//UAT pathname = /

Code:

import { Selector, ClientFunction} from 'testcafe';
import { essUser, companyUser } from '../roles';
const getWindowLocation = ClientFunction(() => window.location.pathname.toString());

fixture('Validate login');
test('can successfully login as a user', async t => {
    await t.useRole(essUser);

    const location = await getWindowLocation();

    await t.expect(location).match(/\/next||\//);
});



// I am trying to use the OR but even though I am changing the /next to /neee, it is still passing which is not correct. 

你的正则表达式是错误的,应该是:

await t.expect(location).match(/(\/next|\/)$/);

您对组使用 (),对逻辑或使用 |

编辑: 正则表达式现在仅匹配 string/url 末尾的模式,这在评论部分已明确说明。