Skip to content

Commit

Permalink
Add tests for asFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
phloose committed May 20, 2020
1 parent db04e06 commit ca6d415
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions spec/suites/layer/GeoJSONSpec.js
Expand Up @@ -842,6 +842,57 @@ describe("L.GeoJSON functions", function () {
const coords = L.GeoJSON.latLngsToCoords(latLngs);
expect(coords).to.eql([[0, 0, 0], [1, 1, 1]]);
});
});

describe("#asFeature", function () {
const geometry1 = {
type: "Point",
coordinates: [0, 0]
};

const geometry2 = {
type: "Point",
coordinates: [1, 1]
};

const feature1 = {
type: "Feature",
geometry: geometry1,
properties: {a: 1}
};

const feature2 = {
type: "Feature",
geometry: geometry2,
properties: {b: 2}
};

const featureCollection = {
type: "FeatureCollection",
features: [
feature1,
feature2
]
};

it.only("given a bare geometry returns a GeoJSON like feature", function () {
const ret = L.GeoJSON.asFeature(geometry1);
const expected = {
type: "Feature",
properties: {},
geometry: geometry1
};
expect(ret).to.eql(expected);
});

it.only("given a GeoJSON feature directly returns it", function () {
const ret = L.GeoJSON.asFeature(feature1);
expect(ret).to.eql(feature1);
});

it.only("given a GeoJSON feature collection directly returns it", function () {
const ret = L.GeoJSON.asFeature(featureCollection);
expect(ret).to.eql(featureCollection);
});
});
});

0 comments on commit ca6d415

Please sign in to comment.