jest + express + axios单元测试(node接口单元测试)
原创
©著作权归作者所有:来自51CTO博客作者徐同保的博客的原创作品,请联系作者获取转载授权,否则将追究法律责任
装包:
user.test.js:
const { userSum } = require('./user')
const { redisClient } = require('../../redis/index')
const axios = require('axios')
const { Api } = require('../../api/index')
describe('user model tests', () => {
beforeAll(async () => {})
afterAll(async () => {
redisClient.quit()
})
it('求和', async () => {
expect(userSum(1, 2)).toBe(3)
})
it('登录', async () => {
const response = await axios.post(
'http://localhost:85/api/light/user/login',
{
username: 'admin',
password: '123456'
}
)
expect(response.data.code).toEqual(200)
})
it('前台登录-正常登录', async () => {
const response = await Api.h5.login({
username: 'admin',
password: '123456'
})
expect(response.code).toEqual(200)
})
})
package.json:
"scripts": {
"test": "jest"
}