import {Map, Popup} from '@vis.gl/react-mapbox'; import * as React from 'react'; import {createRoot} from 'react-dom/client'; import test from 'tape-promise/tape'; import {sleep, waitForMapLoad} from '../utils/test-utils'; import {MapboxAccessToken} from '../utils/token'; test('Popup', async t => { const rootContainer = document.createElement('div'); const root = createRoot(rootContainer); const mapRef = {current: null}; const popupRef = {current: null}; root.render( You are here ); await waitForMapLoad(mapRef); await sleep(1); t.ok(rootContainer.querySelector('.mapboxgl-popup'), 'Popup is attached to DOM'); t.ok(popupRef.current, 'Popup is created'); const popup = popupRef.current; const {anchor, offset, maxWidth} = popup.options; root.render( ); await sleep(1); t.is(offset, popup.options.offset, 'offset did not change deeply'); t.ok(rootContainer.querySelector('#popup-content'), 'content is rendered'); root.render( ); await sleep(1); t.not(offset, popup.options.offset, 'offset is updated'); t.not(anchor, popup.options.anchor, 'anchor is updated'); t.not(maxWidth, popup.options.maxWidth, 'maxWidth is updated'); root.render( ); await sleep(1); t.ok(popup._container.classList.contains('classA'), 'className is updated'); root.unmount(); t.end(); });