I’m coding a test with Jest and I have a long input at the bottom of my test file.
When trying to access my input within an it
function, the input is initialised, but not when trying to access it from the body of a describe
function. Does anybody know why this is happening within describe
and not it
?
I know I could move the input higher, but that does not explain why this is happening for the describe
and not the it
import myFunction from './my-function';
describe('myFunction', () => {
/**
* Accessing myVeryLongInput from here throws ❌
* ReferenceError: Cannot access 'myVeryLongInput' before initialization
*/
const result1 = myFunction(myVeryLongInput);
it('should update property 2310 to 2319 to be like so', () => {
/**
* Accessing myVeryLongInput from here is fine ✅
*/
const result2 = myFunction(myVeryLongInput);
expect(result2['2310']).toBe('like so');
expect(result2['2319']).toBe('like so');
});
});
const myVeryLongInput = {
/// 2330 lines of data
}
New contributor
Supman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1