I am trying to use a pure function that is using For Each, the function will change input array to return 'x'. Can someone help me explain why I am getting this error?
Functions:
let functions = {
helper: (x) => {
return x;
},
changeArray: (x) => {
let arr1 = [x];
arr1.forEach(functions.helper);
return arr1[0];
}
};
Test file:
test('For Each', () => {
expect(syntax.changeArray(['hey', 'hi']).toBe(['x','x']));
})
Result/Error:
TypeError: _syntax.default.changeArray is not a function
73 |
74 | test('For Each', () => {
> 75 | expect(syntax.changeArray(['hey', 'hi']).toBe(['x','x']));
| ^
76 | })
CHANGES:
const syntax{
helper: (x) => x,
changeArray: (arr) => {
return arr.map(syntax.helper);
}
}
TEST FILE:
test('For Each', () => {
expect(syntax.changeArray(['hey', 'hi'])).toBe(['x','x']);
})
RESULT:
expect(received).toBe(expected) // Object.is equality
- Expected
+ Received
Array [
- "x",
- "x",
+ "hey",
+ "hi",
]