Testing Andrew Mead expensify:toEqual参数中的任何值(对象)的测试(jest)通过了吗?
这是我的动作生成器:Testing Andrew Mead expensify:toEqual参数中的任何值(对象)的测试(jest)通过了吗?,testing,react-redux,jestjs,redux-async-actions,Testing,React Redux,Jestjs,Redux Async Actions,这是我的动作生成器: export const addExpense = (expense) => ({ type: "ADD_EXPENSE", expense, }); export const startAddExpense = (expenseData={}) => { return (dispatch) => { const { description = "no description", note = "
export const addExpense = (expense) => ({
type: "ADD_EXPENSE",
expense,
});
export const startAddExpense = (expenseData={}) => {
return (dispatch) => {
const {
description = "no description",
note = "empty",
amount = 0,
createdOn = 0,
} = expenseData;
const expense = { description, note, amount, createdOn };
return database
.ref("expenses")
.push(expense)
.then((ref) => {
dispatch(
addExpense({
id: ref.key,
...expense,
})
);
});
};
};
现在,我对StartDexPense动作生成器的jest测试是:
test("startAddExpense: should add expense to database and store", (done) => {
const store = createMockStore({});
const expenseData = {
description: "Mouse",
amount: 3000,
note: "This one is better",
createdOn: 1000,
};
store
.dispatch(startAddExpense(expenseData))
.then(() => {
const actions = store.getActions();
// expect(actions[0]).toEqual({});
//OR
expect(actions[0]).toEqual({
type: "ADD_EXPENSE",
expense: {
id: expect.any(String),
...expenseData,
},
});
return database.ref(`expenses/${actions[0].expense.id}`).once("value");
})
.then((dataSnapShot) => {
// expect(dataSnapShot.val()).toEqual({});
//OR
expect(dataSnapShot.val()).toEqual({
id: expect.any(String),
...expenseData,
});
});
done();
});
我的问题是,为什么在action[0]和dataSnapShot.val()的toEqual参数中的任何值(对象)的测试(jest)都会通过
您可以看到,在上面的例子中,一旦我传递了一个空对象(已被禁用),另一次我传递了预期的对象,但是测试在这两种情况下都通过了。
我甚至试着在对象内部吐出任何键值对,但它仍然通过了测试???得到了错误;done()应该在第二个then()回调函数中。