我有一个正在运行的单页应用程序http://localhost:3001
,并且我已经进行了这样的设置baseUrl
。
现在,我想拦截所有外部调用,也就是那些去往其他地方的调用localhost:3001
。如何在 Cypress 中编写这种单一拦截?或者,从设计角度来看,我是否以某种“错误”的方式执行此操作?
我尝试过以下拦截,但它们都导致拦截http://localhost:3001/_nuxt
文件等。
cy.intercept("**!(localhost:3001)*", (req) => {
cy.intercept("**!(localhost:3001)**", (req) => {
cy.intercept(/^((?!http:\/\/localhost:3001).+)$/, (req) => {
cy.intercept({ url: /^((?!.*localhost:3001).+)$/ }, (req) => {
奇怪的是,正则表达式/^((?!.*localhost:3001).+)$/
是正确的。但它与 localhost 文件不匹配。
/^((?!.*localhost:3001).+)$/.exec("http://localhost:3001/_nuxt/components/Component.vue") => null
as it should be, and then
/^((?!.*localhost:3001).+)$/.exec("https://www.example.com")
(2) ['https://www.example.com', 'https://www.example.com', index: 0, input: 'https://www.example.com', groups: undefined]
那么,Cypressintercept
所做的事情是否不仅仅是一个简单的正则表达式执行,还是我在这里遗漏了一些明显的东西?