/
githubmirror
/
Leaflet
Обзор
Документация
Войти
/
githubmirror
/
Leaflet
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
spec/suites/control/ControlSpec.js
58 строк
2 KB
Iván Sánchez Ortega
Unit tests for preferCanvas (#10062)
08 янв 2026, 14:28
Не верифицирован
08 янв 2026, 14:28
cab16f4
Код
Авторство
О чём код?
import {expect} from 'chai'; import {Control, DomUtil, LeafletMap} from 'leaflet'; import sinon from 'sinon'; import {createContainer, removeMapContainer} from '../SpecHelper.js'; describe('Control', () => { function onAdd() { return DomUtil.create('div', 'leaflet-test-control'); } let map, container, control; beforeEach(() => { container = createContainer(); map = new LeafletMap(container); map.setView([0, 0], 1); control = new Control(); control.onAdd = onAdd; control.addTo(map); }); afterEach(() => { removeMapContainer(map, container); }); describe('#addTo', () => { it('adds the container to the map', () => { expect(map.getContainer().querySelector('.leaflet-test-control')).to.equal(control.getContainer()); }); it('removes the control from any existing map', () => { control.addTo(map); expect(map.getContainer().querySelectorAll('.leaflet-test-control').length).to.equal(1); expect(map.getContainer().querySelector('.leaflet-test-control')).to.equal(control.getContainer()); }); }); describe('#remove', () => { it('removes the container from the map', () => { control.remove(); expect(map.getContainer().querySelector('.leaflet-test-control')).to.equal(null); }); it('calls onRemove if defined', () => { control.onRemove = sinon.spy(); control.remove(); expect(control.onRemove.called).to.be.true; }); it('is a no-op if the control has not been added', () => { const control = new Control(); expect(control.remove()).to.equal(control); }); }); });