N
N
Nikolai2020-07-28 08:31:16
JavaScript
Nikolai, 2020-07-28 08:31:16

How to test component attribute if it is a function?

Good afternoon! Please tell me how you can test with jest the changePage attribute which is a function.

<Component 
 changePage = {(page) => callFuntion(page)}
/>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2020-07-28
@bingo347

It's not entirely clear what exactly you want to test, but most likely you need this:
https://jestjs.io/docs/en/mock-functions

R
Robur, 2020-07-28
@Robur

"component attribute" is not tested. Any logic is being tested.
If you want to test the function itself, then separate it into a separate function and write a test for it
like this

function changePage(page) {
callFunction(page)
}

<Component 
 changePage = {changePage}
/>


///где-то в тестах пишете тест для changePage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question