forked from publiclab/Leaflet.DistortableImage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecHelper.js
51 lines (42 loc) · 1.55 KB
/
SpecHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
beforeEach(function() {
/* Make expect function available in all tests. */
window.expect = chai.expect;
});
/* Chain global testing utilites below to chai*/
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*
* Mouse Events is a dictionary of "Events" and their properties.
* Other events include 'click', 'dblick', 'mouseup', 'mouseover', 'mouseout', 'mousemove'
* Properties can take in properties of MouseEvent.
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent
*/
chai.simulateEvent = function simulateEventFn(el, type, params) {
params = params || {
bubbles: type != 'mouseleave' && type != 'mouseeenter',
cancelable: type != 'mousemove' && type != 'mouseleave' && type != 'mouseeenter',
};
let e = new MouseEvent(type, params);
return el.dispatchEvent(e);
};
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*
* Asserts that two latlngs are close.
* For example:
* > expect(L.latLng(0, 0.00005)).to.be.closeToLatLng(L.latLng(0, 0))
* > true
*/
chai.use(function(chai, utils) {
let Assertion = chai.Assertion;
Assertion.addMethod('closeToLatLng', function(actual, delta, message) {
let obj = utils.flag(this, 'object');
delta = delta || 1e-4;
expect(obj).to.have.property('lat');
expect(obj).to.have.property('lng');
let lat = new Assertion(obj.lat);
let lng = new Assertion(obj.lng);
utils.transferFlags(this, lat, false);
utils.transferFlags(this, lng, false);
lat.to.be.closeTo(actual.lat, delta, message);
lng.to.be.closeTo(actual.lng, delta, message);
});
});