Answer the question
In order to leave comments, you need to log in
How to properly test a function and mock which calls the function?
The original function is here openFormNewItemEdit
I want to check that actionopenFormNewItemEdit received data and it is equal to the date in the test?
I don’t quite understand how to lock correctly
and can it be more correct to take snapshots of the results of such functions?
let props = {
data: {
name: "Мои заметки № 1",
text: "Мои заметки № 1",
time: 1636283818894,
key: "-Mnu6P7dMJTeVv8VESLh",
keychapter: "0"
},
keychapter: "0",
keyitem: "-Mnu6P7dMJTeVv8VESLh",
index: 1,
attrdata: "all",
del: false,
}
let actionopenFormNewItemEdit = jest.fn(data, dispatch){ return data};
или так надо сделать
let actionopenFormNewItemEdit = () => { return { name: props.data.name, text: props.data.text, activ: true, keychapter: props.keychapter, keyitem: props.keyitem } };
expect(instance.openFormNewItemEdit()).toBe({ name: props.data.name, text: props.data.text, activ: true, keychapter: props.keychapter, keyitem: props.keyitem });
openFormNewItemEdit = () => {
let data = { name: this.props.data.name, text: this.props.data.text, activ: true, keychapter: this.props.keychapter, keyitem: this.props.keyitem };
actionopenFormNewItemEdit(data, this.props.dispatch);
}
test('TaskItemContainer openFormNewItemEdit', () => {
instance.openFormNewItemEdit();
expect(actionopenFormNewItemEdit).toBeCalled();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question