Skip to content

Commit a9aad3c

Browse files
author
Arindam Bose
committed
Update controls test so they read form a stub of Map's effective width
1 parent cfde0d9 commit a9aad3c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

test/unit/ui/control/attribution.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('AttributionControl appears in the position specified by the position optio
3737

3838
test('AttributionControl appears in compact mode if compact option is used', (t) => {
3939
const map = createMap(t);
40-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
40+
const stub = t.stub(map, 'getEffectiveWidth').returns(700);
4141

4242
let attributionControl = new AttributionControl({
4343
compact: true
@@ -49,7 +49,7 @@ test('AttributionControl appears in compact mode if compact option is used', (t)
4949
t.equal(container.querySelectorAll('.mapboxgl-ctrl-attrib.mapboxgl-compact').length, 1);
5050
map.removeControl(attributionControl);
5151

52-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
52+
stub.returns(600);
5353
attributionControl = new AttributionControl({
5454
compact: false
5555
});
@@ -61,14 +61,14 @@ test('AttributionControl appears in compact mode if compact option is used', (t)
6161

6262
test('AttributionControl appears in compact mode if container is less then 640 pixel wide', (t) => {
6363
const map = createMap(t);
64-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
64+
const stub = t.stub(map, 'getEffectiveWidth').returns(700);
6565
map.addControl(new AttributionControl());
6666

6767
const container = map.getContainer();
6868

6969
t.equal(container.querySelectorAll('.mapboxgl-ctrl-attrib:not(.mapboxgl-compact)').length, 1);
7070

71-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
71+
stub.returns(600);
7272
map.resize();
7373

7474
t.equal(container.querySelectorAll('.mapboxgl-ctrl-attrib.mapboxgl-compact').length, 1);

test/unit/ui/control/logo.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ test('LogoControl appears in compact mode if container is less then 250 pixel wi
9292
const map = createMap(t);
9393
const container = map.getContainer();
9494

95-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 255, configurable: true});
95+
const stub = t.stub(map, 'getEffectiveWidth').returns(255);
9696
map.resize();
9797
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo:not(.mapboxgl-compact)').length, 1);
9898

99-
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 245, configurable: true});
99+
stub.returns(245);
100100
map.resize();
101101
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo.mapboxgl-compact').length, 1);
102102

0 commit comments

Comments
 (0)