且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

s-s-r的模拟服务器使用cypress.io反应应用程序e2e测试

更新时间:2021-08-24 03:11:14

MockTTP 可以做到这一点.摘录自doc:

MockTTP can do that. Excerpt from the doc :

const superagent = require("superagent");
const mockServer = require("mockttp").getLocal();

describe("Mockttp", () => {
    // Start your server
    beforeEach(() => mockServer.start(8080));
    afterEach(() => mockServer.stop());

    it("lets you mock requests, and assert on the results", () =>
        // Mock your endpoints
        mockServer.get("/mocked-path").thenReply(200, "A mocked response")
        .then(() => {
            // Make a request
            return superagent.get("http://localhost:8080/mocked-path");
        }).then(() => {
            // Assert on the results
            expect(response.text).to.equal("A mocked response");
        });
    );
});