茉莉花 toMatch url + uuid

Jasmine toMatch url + uuid

发送导致创建新资源的点击后,我使用它来等待浏览器重定向到新创建的资源:

browser.driver.wait(function() {
        return browser.driver.getCurrentUrl().then(function(url) {
            return url == 'https://dev.mysite.com/resource/'+/^[0-9a-fA-F]{24}$/
        });
    });

问题是我无法将 url==/myUrl 解析为 true

这是一个示例 url 我正在尝试 return 正确, resource/ 之后的部分随每次测试而变化:

https://dev.mysite.com/resource/54d4ee554bf01d2a7e4e8058

谢谢!

你需要使用match():

browser.driver.wait(function() {
    return browser.driver.getCurrentUrl().then(function(url) {
        var re = /resource\/[0-9a-fA-F]{24}$/;
        return url.match(re);
    });
});

请注意 url 中的斜杠必须使用反斜杠进行转义。