【发布时间】:2019-07-16 05:02:40
【问题描述】:
我有一个简单的 Jest 案例,我需要在开始时创建表,填充它,然后运行一些测试。所有测试完成后,我需要删除 DynamoDB 中的表。
我尝试使用 beforeAll 创建表,然后进行测试,然后使用 afterAll 删除表。 然而,它的运行是不确定的,因此总体会在创建表之前尝试运行,或者在创建表之前尝试删除表。
我的代码
beforeAll(() => {
await createTable();
populateTable();
//setupLDAPConnection();
});
afterAll(() => {
deleteTable();
});
describe('The program gets list of AD groups', function () {
it('should get a list of user groups in the Active Directory', async () => {
//const result = await userSyncFunction.handler(undefined);
//expect(result).to.be.an('object');
//console.log('2');
});
});
populateTable = () => {
agents.forEach((agent) => {
docClient.put(agent, (err, data) => {
if (err) {
console.log("Error", err);
} else {
console.log("Agent inserted", data);
}
});
});
};
createTable = async () => {
dynamoDb.createTable(agent_table, (err, data) => {
if (err) {
console.log("Error", err);
} else {
console.log("Table created");
}
});
};
deleteTable = () => {
dynamoDb.deleteTable( { TableName: 'AGENT_LIST' }, function(err, data) {
if (err)
console.log(err, err.stack);
else {
console.log('Table deleted');
}
});
};
有什么想法吗?
谢谢。
【问题讨论】:
标签: node.js testing amazon-dynamodb jestjs teardown