假设您有以下操作export const startAddExpense = (expenseData = {}) => { return (dispatch) => { const { description = '', note = '', amount = 0, createdAt = 0 } = expenseData; const expense = { description, note, amount, createdAt }; return database.ref('expenses').push(expense).then((ref) => { dispatch(addExpense({ id: ref.key, ...expense })); }); };};我将费用数据存储到数据库(在我的情况下是火库),然后将addExpense函数发送到商店这是对它的测试。test('should add expense to database and store', (done) => { const store = createMockStore({}); const expenseData = { description: 'Mouse', amount: 3000, note: 'This one is better', createdAt: 1000 }; store.dispatch(startAddExpense(expenseData)).then(() => { expect(1).toBe(1); done(); });});done() 函数的含义是什么?这是否意味着回调函数应该等到在 firebase 数据库中插入数据完成?谢谢 西奥
1 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
done
表示测试函数具有异步代码。因此,您应该在获得异步结果时手动调用。此外,异步测试具有第三个参数,这些参数在该函数被视为失败后定义超时。https://jasmine.github.io/tutorials/async#callbacksdone
添加回答
举报
0/150
提交
取消