Vue中的单元测试API调用

时间:2018-11-01 17:13:29

标签: unit-testing vue.js moxios

我在api调用后进行单元测试问题,moxios无法调用成功回调

我正在使用业力和moxios进行测试

我的测试方法如下:

it("login()",function() {         
    moxios.stubRequest('/Account', {
        status: 200,
        response: { 
            "userId": 12345,
            "firstName": "Jon",
            "lastName": "Snow",
            "accessToken": "test-token-123.@ertfg",
            "userPermission": ["4", "5"] 
        }
    })

    Auth.login('Test','Test')

    moxios.wait(() => {
        try {
            let request = moxios.requests.mostRecent()
            done()
        } catch (e) {
            done(e)
        }
    })
})

我正在尝试的方法

login (employeeId, password) {
    Api.post('/Account', {
        userId: employeeId,
        password: password
    })
    .then(response => this.loginSuccessful(response))
    .catch(error => this.loginFailed(error.response));
},

测试覆盖率报告如下所示 Coverage report

预先感谢

0 个答案:

没有答案