This is my action generators:
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,
})
);
});
};
};
Now my jest testing for startAddExpense action generator is:
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();
});
My question is why does the test(jest) passes for any value(object) inside the toEqual argument of both action[0] and dataSnapShot.val()??
You can see that in the above case,once i have passed an empty object(which has been muted) and another time i have passed the expected object, but the test passes for both the case. I even tried puuting any key-value pair inside the object and it still passes the test???
Aucun commentaire:
Enregistrer un commentaire