In this example, why does the variable foo
not raise a ReferenceError
? There is no variable declaration, but it's clearly in scope after the DOM is rendered. What's the relationship between the DOM node id and the javascript namespace? I'm running this with jest
.
import React from 'react';
import { render } from '@testing-library/react'
test('renders a div', () => {
const { utils } = render(<div id="foo"/>)
expect(foo).toBe(true)
})
Jest reports:
Expected: true
Received: <div id="foo" />
I really wish the test would crash instead, because in my real example I accidentally passed an undefined variable to expect()
, which just happened to share the name of a rendered DOM node's id.