代码之家  ›  专栏  ›  技术社区  ›  shamon shamsudeen

Jest检测到以下1个打开句柄可能会阻止Jest退出

  •  1
  • shamon shamsudeen  · 技术社区  · 6 年前

    这是我的HTTP路由

     app.get('/', (req, res) => {
        res.status(200).send('Hello World!')
    })
    
    app.post('/sample', (req, res) => {
        res.status(200).json({
            x:1,y:2
        });
    })
    

    (一) GET

    2) 在 /sample x y

    const request = require('supertest');
    const app = require('../app');
    
    describe('Test the root path', () => {
        test('It should response the GET method', () => {
            return request(app).get('/').expect(200);
        });
    })
    
    describe('Test the post path', () => {
        test('It should response the POST method', (done) => {
            return request(app).post('/sample').expect(200).end(err,data=>{
                expect(data.body.x).toEqual('1');
    
            });
        });
    })
    

    Jest检测到以下1个打开句柄可能会保留Jest 退出:

    2 回复  |  直到 6 年前
        1
  •  6
  •   Nenoj    6 年前

    done() end() 方法

    const request = require("supertest");
    const app = require("../app");
    
    let server = request(app);
    
    it("should return 404", done =>
        server
            .get("/")
            .expect(404)
            .end(done);
    });
    
    
        2
  •  -1
  •   Shraddha Goel    6 年前

    describe('Test the post path', () => {
        test('It should response the POST method', () => {
            return request(app).post('/sample').expect(200).toEqual({ x:1,y:2
            });
        });
    })
    

    有很多方法可以使用相反,你可以去扔涵盖每个笑话功能的官方文件 https://jestjs.io/docs/en/expect