假设您有以下操作
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 数据库中插入数据完成?
谢谢 西奥
潇湘沐
相关分类