I am in the process of creating unit tests for my component dateFormat.js using Jest. The focus is on testing the function formatDateGlobal. Here is an excerpt from the test:
import DateFormat from '../dateFormat';
describe('dateFormat.js', () => {
let date1;
beforeEach(() => {
date1 = {
date: '',
};
});
it('This test should return an empty string', () => {
// Act
const returnedDate = DateFormat.formatDateGlobal(date1);
// Assert
expect(returnedDate).toBe('');
});
In dateFormat, I'm exporting the formatDateGlobal function like this:
export default formatDateGlobal;
The tests are structured correctly, but I encountered an error:
TypeError: _dateFormat.default.formatDateGlobal is not a function
27 | it('Then it should return an empty string', () => {
28 | // Act
> 29 | const returnedDate = DateFormat.formatDateGlobal(date1);
| ^
30 | // Assert
31 | expect(returnedDate).toBe('');
32 | });
Currently unsure about the cause of this issue, but I suspect it has something to do with the way I'm exporting the function.