Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expect-maptalks

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-maptalks - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

14

index.js

@@ -125,3 +125,3 @@ 'use strict';

function isCenterDrawn(layer, dx, dy) {
function isCenterDrawn(layer, dx, dy, color) {
if (!dx) {

@@ -142,9 +142,13 @@ dx = 0;

var canvas = image.image;
return isDrawn(parseInt(size.width) / 2 - image.point.x + dx, parseInt(size.height) / 2 - image.point.y + dy, canvas);
return isDrawn(parseInt(size.width) / 2 - image.point.x + dx, parseInt(size.height) / 2 - image.point.y + dy, canvas, color);
}
function isDrawn(x, y, canvas) {
function isDrawn(x, y, canvas, color) {
var context = canvas.getContext('2d');
var imgData = context.getImageData(x, y, 1, 1).data;
if (imgData[3] > 0) {
if (color) {
return imgData[0] === color[0] && imgData[1] === color[1] &&
imgData[2] === color[2];
}
return true;

@@ -155,6 +159,6 @@ }

expect.Assertion.prototype.painted = function (dx, dy) {
expect.Assertion.prototype.painted = function (dx, dy, color) {
var expectation = false;
if (('maptalks' in global) && (this.obj instanceof maptalks.Layer)) {
expectation = isCenterDrawn(this.obj, dx, dy);
expectation = isCenterDrawn(this.obj, dx, dy, color);
}

@@ -161,0 +165,0 @@ this.assert(

{
"name": "expect-maptalks",
"version": "0.1.1",
"version": "0.2.0",
"description": "A plugin of expect.js(https://github.com/Automattic/expect.js) for maptalks with assertions for Coordinate/GeoJSON/Layer",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -6,1 +6,63 @@ # expect-maptalks

A plugin of expect.js(https://github.com/Automattic/expect.js) for maptalks with assertions for Coordinate/GeoJSON/Layer
## Usage
```bash
npm install expect-maptalks --save-dev
```
### with Karma
Install [karma-expect-maptalks](https://github.com/MapTalks/karma-expect-maptalks)
```bash
npm install karma-expect-maptalks --save-dev
```
In karma.conf.js, Attention: **always declare expect-maptalks behind expect**
```javascript
frameworks: [
'mocha',
'expect',
'expect-maptalks'
],
plugins: [
'karma-expect',
'karma-expect-maptalks'
],
```
## Methods
**approx**: asserts that the value is approximately equal or not
```js
expect(1.000001).to.be.approx(1);
expect(1.001).to.be.approx(1, 1E-2);
```
**closeTo**: asserts that whether the coordinate is closeTo another (approx with a delta of 1E-6)
```js
expect([1, 1]).to.be.closeTo([1 + 1E-7, 1 - 1E-7]);
expect({x : 1, y : 1}).to.be.closeTo([1 + 1E-7, 1 - 1E-7]);
```
**eqlGeoJSON**: asserts that whether a GeoJSON object is equal with another (true if the coordinates are closeTo another's)
```js
//true
expect({ "type": "Point", "coordinates": [0.0, 0.0] })
.to.be.eqlGeoJSON({ "type": "Point", "coordinates": [0.000001, 0.000001] });
```
**painted**: asserts the given layer is painted in the center with a offset.
```js
var v = new maptalks.VectorLayer('v').addGeometries(geos).addTo(map);
//asserts layer is painted in the center
expect(v).to.be.painted();
//whether the layer is painted with an offset {x:5, y:3} from the center.
//a negative x to the left and a positive to the right.
//a negative y to the top and a positive to the bottom.
expect(v).to.be.painted(5, 3);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc