首页 > 解决方案 > 摩卡异步测试没有被调用

问题描述

我对 mocha 比较陌生,并尝试运行异步测试。但是在产生测试结果之前运行 after 方法。我一定做错了什么,但我找不到什么。

任何帮助表示赞赏

这是我的代码


    before( done => {
        server.start()
            .then(() => {
                done()
            })
    })
    after( done => {
       server.stop()
            .then(() => { 
                done()
            })
    })

     it('should start webservice api and not throw', done => {
        const ws = new Webservice('ws', 1, 'test')

        ws.start()
            .then(axios.post(`http://localhost:${process.env.WORKFLOW_PORT}/test`))
            .then(ws.stop())
            .then(() => {
                done()
            })  
    })
    
    it('should start 2 webservice api and not throw', done => {
        const ws = new Webservice('ws', 1, 'test2')
        const ws2 = new Webservice('ws', 2, 'test3')

        ws.start()
            .then(ws2.start())
            .then(axios.post(`http://localhost:${process.env.WORKFLOW_PORT}/test2`))
            .then(axios.post(`http://localhost:${process.env.WORKFLOW_PORT}/test3`))
            .then(ws.stop())
            .then(ws2.stop())    
            .then(() => {
                done()
            })  
    })````

标签: javascripttestingmocha.js

解决方案


推荐阅读