'Can you import a function from a react component into a test file?
Is there a way to import a function from a react component into a test file?
for example:
component:
const funcToExport = () => {
let a = 1;
let b = 2;
let value = a + b;
return value
}
test file:
import funcToExport from './component';
can this be done, so you can use the function in the test file?
Solution 1:[1]
First of all you have to declare your function globally then add the keyword "export" so you can import it in other files.
export const funcToExport = () => {
let a = 1;
let b = 2;
let value = a + b;
return value
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ossama Ismaili |
