Files
leaflet/spec/suites/core/ClassSpec.js
johnd0e e7a5c6ffbf Add more browser profiles and fix some tests (#7115)
* MapSpec.js: fix: mocked function must be restored

Otherwise it will break crs.project test in CRSSpec.js

* MapSpec.js: skip broken test

crsMock.verify() call is mandatory here, but it shows that crs.project is never called,
thus the test is not ever valid.

* MapSpec.js: fix non-valid test

Revert 50a4845a78 and 1b1d96a4c4,
and refactor a bit (rather cosmetical changes)

* MapSpec.js: fix more tests

Refactor before/afterEach hooks for more careful setup/cleanup.

Fix some non-valid tests:
* #remove
  - "undefines container._leaflet"
  - "unbinds events"
* #removeLayer
  - "when the last tile layer on a map is removed"
  - "when a tile layer is removed from a map and it had greater zoom level coverage than the remainding layer"
  - "when a tile layer is removed from a map it and it had lesser or the sa,e zoom level coverage as the remainding layer(s)"

* GridLayerSpec.js: fix some tests

Refactor before/afterEach hooks for more careful setup/cleanup.

Fix some non-valid tests:
* "when a tilelayer is added to a map that already has a tilelayer"

* spec/suites/**: refactor for more careful setup/cleanup

Refactor before/afterEach hooks
Other minor changes

* SpecHelper.js: rename skipIn(non)Phantom to skipIf(No)3d

..to make things more clear

Remove unused helper functions

* Update testing deps

sinon.js: left on 7.5.0 (latest still working on PhantomJS)

karma-rollup-preprocessor: left on 6.1.2 (latest still supporting rollup < 1.0.0)

* CRSSpec.js: workaround round-off error in Chrome

L.CRS.zoom(L.CRS.scale(2.5)) results 2.4999999999999996 in Chrome

Note: comparing floating point numbers properly is hard,
e.g. see https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

* Fix touch tests failing in Chrome

* karma.conf.js: add custom Chrome config to make some tests pass

npm run test-nolint -- --browsers Chrome1280x1024

* spec/.eslintrc: do not forbid no-unused-vars rule

* spec/.eslintrc: do not forbid more rules

no-extend-native
no-irregular-whitespace
no-shadow

* Add karma-edge-launcher

* Add karma-ie-launcher

Some test fails atm, see log:

> karma start ./spec/karma.conf.js "--browsers" "IE"

................................................................................
.....
WARN: 'Deprecated include of L.Mixin.Events: this property will be removed in future releases, please inherit from L.Evented instead.', undefined
................................................................................
................................................................................
...............................................................
IE 11.0 (Windows 10) ImageOverlay _image when loaded should raise the load event FAILED
	TypeError: Argument not optional
	   at raiseImageEvent (spec/suites/layer/ImageOverlaySpec.js:66:4)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:74:5)
IE 11.0 (Windows 10) ImageOverlay _image when load fails should raise the error event FAILED
	TypeError: Argument not optional
	   at raiseImageEvent (spec/suites/layer/ImageOverlaySpec.js:66:4)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:83:5)
IE 11.0 (Windows 10) ImageOverlay _image when load fails should change the image to errorOverlayUrl FAILED
	TypeError: Argument not optional
	   at raiseImageEvent (spec/suites/layer/ImageOverlaySpec.js:66:4)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:88:5)
..
IE 11.0 (Windows 10) ImageOverlay #setZIndex should update the z-index of the image if it has allready been added to the map FAILED
	Error: expected 1 to equal '1'
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (node_modules/expect.js/index.js:69:13)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:111:4)
IE 11.0 (Windows 10) ImageOverlay #setZIndex should set the z-index of the image when it is added to the map FAILED
	Error: expected 10 to equal '10'
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (node_modules/expect.js/index.js:69:13)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:121:4)
IE 11.0 (Windows 10) ImageOverlay #setZIndex should use the z-index specified in options FAILED
	Error: expected 20 to equal '20'
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (node_modules/expect.js/index.js:69:13)
	   at Anonymous function (spec/suites/layer/ImageOverlaySpec.js:127:4)
........................................................................
IE 11.0 (Windows 10) Marker.Drag drag in CSS scaled container drags a marker with mouse, compensating for CSS scale FAILED
	expected 0 to be within -50..-30 (node_modules/expect.js/index.js:102)
................................................................................
...........................................................
WARN: 'Deprecated use of _flat, please use L.LineUtil.isFlat instead.'
.
WARN: 'Deprecated use of _flat, please use L.LineUtil.isFlat instead.'
.......................................................................... 05 2020 15:25:48.917:WARN [web-server]: : /000
 05 2020 15:25:48.938:WARN [web-server]: : /000
......
..
IE 11.0 (Windows 10) Map #invalidateSize pans by the right amount when growing in 1px increments FAILED
	Error: expected 0 to equal 1
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (node_modules/expect.js/index.js:69:13)
	   at Anonymous function (spec/suites/map/MapSpec.js:649:4)
IE 11.0 (Windows 10) Map #invalidateSize pans by the right amount when shrinking in 1px increments FAILED
	Error: expected 0 to equal -1
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (node_modules/expect.js/index.js:69:13)
	   at Anonymous function (spec/suites/map/MapSpec.js:667:4)
..
IE 11.0 (Windows 10) Map #invalidateSize emits a move event if the size has changed FAILED
	Error: expected false to be truthy
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.ok (node_modules/expect.js/index.js:115:5)
	   at Anonymous function (node_modules/expect.js/index.js:499:7)
	   at Anonymous function (spec/suites/map/MapSpec.js:700:4)
IE 11.0 (Windows 10) Map #invalidateSize emits a moveend event if the size has changed FAILED
	Error: expected false to be truthy
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.ok (node_modules/expect.js/index.js:115:5)
	   at Anonymous function (node_modules/expect.js/index.js:499:7)
	   at Anonymous function (spec/suites/map/MapSpec.js:710:4)
IE 11.0 (Windows 10) Map #invalidateSize debounces the moveend event if the debounceMoveend option is given FAILED
	Error: expected false to be truthy
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.ok (node_modules/expect.js/index.js:115:5)
	   at Anonymous function (node_modules/expect.js/index.js:499:7)
	   at Anonymous function (spec/suites/map/MapSpec.js:724:4)
IE 11.0 (Windows 10) Map #invalidateSize correctly adjusts for new container size when view is set during map initialization (#6165) FAILED
	Error: expected 0 to equal 100
	   at Assertion.prototype.assert (node_modules/expect.js/index.js:102:7)
	   at Assertion.prototype.equal (node_modules/expect.js/index.js:216:5)
	   at Anonymous function (spec/suites/map/MapSpec.js:745:4)
................
IE 11.0 (Windows 10) Map #fitBounds after layers set Snaps to a number after adding tile layer FAILED
	Error: Access is denied.

	   at createTile (src/Leaflet.js:11698:3)
	   at _addTile (src/Leaflet.js:11433:3)
	   at _update (src/Leaflet.js:11330:5)
	   at _setView (src/Leaflet.js:11191:5)
	   at _resetView (src/Leaflet.js:11146:3)
	   at onAdd (src/Leaflet.js:10784:3)
	   at _layerAdd (src/Leaflet.js:6580:3)
	   at Events.fire (src/Leaflet.js:588:6)
	   at _resetView (src/Leaflet.js:4184:4)
	   at setView (src/Leaflet.js:3181:3)
..............................
IE 11.0 (Windows 10) Map.Drag mouse events in CSS scaled container change the center of the map, compensating for CSS scale FAILED
	expected 31.952162238024975 to be within 21.943..21.9431 (node_modules/expect.js/index.js:102)
IE 11.0 (Windows 10) Map.Drag touch events change the center of the map FAILED
	Object doesn't support this action (node_modules/prosthetic-hand/dist/prosthetic-hand.js:624)
IE 11.0 (Windows 10) Map.Drag touch events does not change the center of the map when finger is moved less than the drag threshold FAILED
	Object doesn't support this action (node_modules/prosthetic-hand/dist/prosthetic-hand.js:624)
IE 11.0 (Windows 10) Map.Drag touch events reset itself after touchend FAILED
	Object doesn't support this action (node_modules/prosthetic-hand/dist/prosthetic-hand.js:624)
.............
IE 11.0 (Windows 10) Map.TouchZoom Increases zoom when pinching out FAILED
	Object doesn't support this action (node_modules/prosthetic-hand/dist/prosthetic-hand.js:624)
IE 11.0 (Windows 10) Map.TouchZoom Decreases zoom when pinching in FAILED
	Object doesn't support this action (node_modules/prosthetic-hand/dist/prosthetic-hand.js:624)
IE 11.0 (Windows 10): Executed 685 of 688 (20 FAILED) (skipped 3) (25.993 secs / 22.211 secs)

* karma.conf.js: additional Firefox configs

- FirefoxPointer
- FirefoxTouch
- FirefoxPointerTouch

* .travis.yml: run CI tests with different Firefox configs

Use FirefoxHeadless

* karma.conf.js: change reporter to default ('progress')

Because 'dots' is confusing when mixed up with different warnings.

But for CI script 'dots' fits better due to travis-ci log qualities.

* .travis.yml: run CI tests with Chrome too
2020-05-04 14:19:14 +03:00

200 lines
4.3 KiB
JavaScript

/* eslint no-new: 0 */
describe("Class", function () {
describe("#extend", function () {
var Klass,
constructor,
method;
beforeEach(function () {
constructor = sinon.spy();
method = sinon.spy();
Klass = L.Class.extend({
statics: {bla: 1},
includes: {mixin: true},
initialize: constructor,
foo: 5,
bar: method
});
});
it("creates a class with the given constructor & properties", function () {
var a = new Klass();
expect(constructor.called).to.be.ok();
expect(a.foo).to.eql(5);
a.bar();
expect(method.called).to.be.ok();
});
it("inherits parent classes' constructor & properties", function () {
var Klass2 = Klass.extend({baz: 2});
var b = new Klass2();
expect(b instanceof Klass).to.be.ok();
expect(b instanceof Klass2).to.be.ok();
expect(constructor.called).to.be.ok();
expect(b.baz).to.eql(2);
b.bar();
expect(method.called).to.be.ok();
});
it("supports static properties", function () {
expect(Klass.bla).to.eql(1);
});
it("inherits parent static properties", function () {
var Klass2 = Klass.extend({});
expect(Klass2.bla).to.eql(1);
});
it("overrides parent static properties", function () {
var Klass2 = Klass.extend({statics: {bla: 2}});
expect(Klass2.bla).to.eql(2);
});
it("includes the given mixin", function () {
var a = new Klass();
expect(a.mixin).to.be.ok();
});
it("includes multiple mixins", function () {
var Klass2 = L.Class.extend({
includes: [{mixin: true}, {mixin2: true}]
});
var a = new Klass2();
expect(a.mixin).to.be.ok();
expect(a.mixin2).to.be.ok();
});
it("grants the ability to include the given mixin", function () {
Klass.include({mixin2: true});
var a = new Klass();
expect(a.mixin2).to.be.ok();
});
it("merges options instead of replacing them", function () {
var KlassWithOptions1 = L.Class.extend({
options: {
foo1: 1,
foo2: 2
}
});
var KlassWithOptions2 = KlassWithOptions1.extend({
options: {
foo2: 3,
foo3: 4
}
});
var a = new KlassWithOptions2();
expect(a.options.foo1).to.eql(1);
expect(a.options.foo2).to.eql(3);
expect(a.options.foo3).to.eql(4);
});
it("gives new classes a distinct options object", function () {
var K1 = L.Class.extend({options: {}});
var K2 = K1.extend({});
expect(K2.prototype.options).not.to.equal(K1.prototype.options);
});
it("inherits options prototypally", function () {
var K1 = L.Class.extend({options: {}});
var K2 = K1.extend({options: {}});
K1.prototype.options.foo = 'bar';
expect(K2.prototype.options.foo).to.eql('bar');
});
it("adds constructor hooks correctly", function () {
var spy1 = sinon.spy();
Klass.addInitHook(spy1);
Klass.addInitHook('bar', 1, 2, 3);
new Klass();
expect(spy1.called).to.be.ok();
expect(method.calledWith(1, 2, 3));
});
it("inherits constructor hooks", function () {
var spy1 = sinon.spy(),
spy2 = sinon.spy();
var Klass2 = Klass.extend({});
Klass.addInitHook(spy1);
Klass2.addInitHook(spy2);
new Klass2();
expect(spy1.called).to.be.ok();
expect(spy2.called).to.be.ok();
});
it("does not call child constructor hooks", function () {
var spy1 = sinon.spy(),
spy2 = sinon.spy();
var Klass2 = Klass.extend({});
Klass.addInitHook(spy1);
Klass2.addInitHook(spy2);
new Klass();
expect(spy1.called).to.be.ok();
expect(spy2.called).to.eql(false);
});
it("calls parent constructor hooks when child has none", function () {
var spy1 = sinon.spy();
Klass.addInitHook(spy1);
var Klass2 = Klass.extend({});
new Klass2();
expect(spy1.called).to.be.ok();
});
});
describe("#include", function () {
var Klass;
beforeEach(function () {
Klass = L.Class.extend({});
});
it("returns the class with the extra methods", function () {
var q = sinon.spy();
var Qlass = Klass.include({quux: q});
var a = new Klass();
var b = new Qlass();
a.quux();
expect(q.called).to.be.ok();
b.quux();
expect(q.called).to.be.ok();
});
});
// TODO Class.mergeOptions
});