我正在使用服务器端渲染 (SSR) 构建单页 Web 应用程序 (SPA)。
我们有一个节点后端 API,它在 SSR 期间从节点服务器调用,在初始渲染后从浏览器调用。
我想编写配置 API 响应的 e2e 测试(例如 with nock
)并同时使用浏览器调用和 SSR 服务器调用。一些伪代码:
it('loads some page (SSR mode)', () => {
mockAPI.response('/some-path', {text: "some text"}); // here i configure the mock server response
browser.load('/some-other-page'); // hit server for SSR response
expect(myPage).toContain('some text');
})
it('loads some other page (SPA mode)', () => {
mockAPI.response('/some-path', {text: "some other text"}); // here i configure another response for the same call
browser.click('#some-link'); // loads another page client side only : no SSR here
expect(myPage).toContain('some other text');
})
目前赛普拉斯允许我在浏览器上模拟获取,但不能在服务器上模拟。
有什么可以实现的吗?最好使用节点库。