【发布时间】:2019-11-09 12:36:33
【问题描述】:
我想在所有笑话测试之后或之前删除我数据库中的所有条目。
这是我的 setup.js:
import { getConnection, getConnectionManager } from "typeorm"
beforeAll(async () => {
const connectionManager = getConnectionManager()
const connection = connectionManager.create({
"type": "postgres",
"host": "localhost",
"port": 54320,
"username": "test",
"password": "test",
"database": "test",
"entities": ["../src/entities/*.ts"],
"logging": false,
"synchronize": true
})
await connection.connect()
})
afterAll(async () => {
await getConnection().close()
})
我在 typeorm 文档中读到“同步”选项会用空的新表覆盖旧表,但它似乎不起作用。
这是我做的测试:
describe('POST /create', () => {
it('Create a user', async () => {
const user: IStringTMap<string> = {
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@test.com',
password: 'test123!',
}
const res: Response = await request(app)
.post('/create')
.send(user)
.expect(200)
expect(res.type).toEqual('application/json')
expect(res.body.email).toBe('john.doe@test.com')
expect(res.body.password).toBe(undefined)
})
})
第一个 yarn test 有效,但下一个无效(电子邮件已存在)
有什么想法吗?
【问题讨论】:
标签: javascript testing jestjs typeorm