Skip to content

Commit 0ed5313

Browse files
committed
Fix XML unit tests (proper XML parsing)
1 parent eb4fd05 commit 0ed5313

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

test/osm_test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ describe("L.OSM.TracestrackTopo", function () {
6969

7070
describe("L.OSM.DataLayer", function () {
7171
function fixture(name) {
72-
var fs = require("fs"),
73-
data = document.createElement("div");
74-
data.innerHTML = fs.readFileSync(__dirname + "/fixtures/" + name + ".xml");
75-
return data;
72+
var fs = require("fs");
73+
var contents = fs.readFileSync(__dirname + "/fixtures/" + name + ".xml", "utf8");
74+
var dom = new jsdom.JSDOM(contents, { contentType: "text/xml"});
75+
return dom.window.document;
7676
}
7777

7878
function layers(layerGroup) {
@@ -93,14 +93,14 @@ describe("L.OSM.DataLayer", function () {
9393

9494
it("creates a Polyline for a way", function () {
9595
var osm = new L.OSM.DataLayer(fixture("way"));
96-
layers(osm).length.should.eq(21);
97-
layers(osm)[20].should.be.an.instanceof(L.Polyline);
96+
layers(osm).length.should.eq(1);
97+
layers(osm)[0].should.be.an.instanceof(L.Polyline);
9898
});
9999

100100
it("creates a Polygon for an area", function () {
101101
var osm = new L.OSM.DataLayer(fixture("area"));
102-
layers(osm).length.should.eq(15);
103-
layers(osm)[14].should.be.an.instanceof(L.Polygon);
102+
layers(osm).length.should.eq(1);
103+
layers(osm)[0].should.be.an.instanceof(L.Polygon);
104104
});
105105

106106
it("creates a CircleMarker for an interesting node", function () {
@@ -123,12 +123,12 @@ describe("L.OSM.DataLayer", function () {
123123

124124
it("sets a way's style", function () {
125125
var osm = new L.OSM.DataLayer(fixture("way"), {styles: {way: {color: "red"}}});
126-
layers(osm)[20].options.should.have.property("color", "red");
126+
layers(osm)[0].options.should.have.property("color", "red");
127127
});
128128

129129
it("sets an area's style", function () {
130130
var osm = new L.OSM.DataLayer(fixture("area"), {styles: {area: {color: "green"}}});
131-
layers(osm)[14].options.should.have.property("color", "green");
131+
layers(osm)[0].options.should.have.property("color", "green");
132132
});
133133

134134
it("sets a node's style", function () {
@@ -150,15 +150,15 @@ describe("L.OSM.DataLayer", function () {
150150
it("creates a Polyline for a way", async function () {
151151
var osm = new L.OSM.DataLayer(fixture("way"), {asynchronous: true});
152152
await sleep(1);
153-
layers(osm).length.should.eq(21);
154-
layers(osm)[20].should.be.an.instanceof(L.Polyline);
153+
layers(osm).length.should.eq(1);
154+
layers(osm)[0].should.be.an.instanceof(L.Polyline);
155155
});
156156

157157
it("creates a Polygon for an area", async function () {
158158
var osm = new L.OSM.DataLayer(fixture("area"), {asynchronous: true});
159159
await sleep(1);
160-
layers(osm).length.should.eq(15);
161-
layers(osm)[14].should.be.an.instanceof(L.Polygon);
160+
layers(osm).length.should.eq(1);
161+
layers(osm)[0].should.be.an.instanceof(L.Polygon);
162162
});
163163

164164
it("creates a CircleMarker for an interesting node", async function () {
@@ -185,13 +185,13 @@ describe("L.OSM.DataLayer", function () {
185185
it("sets a way's style", async function () {
186186
var osm = new L.OSM.DataLayer(fixture("way"), {styles: {way: {color: "red"}}, asynchronous: true});
187187
await sleep(1);
188-
layers(osm)[20].options.should.have.property("color", "red");
188+
layers(osm)[0].options.should.have.property("color", "red");
189189
});
190190

191191
it("sets an area's style", async function () {
192192
var osm = new L.OSM.DataLayer(fixture("area"), {styles: {area: {color: "green"}}, asynchronous: true});
193193
await sleep(1);
194-
layers(osm)[14].options.should.have.property("color", "green");
194+
layers(osm)[0].options.should.have.property("color", "green");
195195
});
196196

197197
it("sets a node's style", async function () {
@@ -210,8 +210,8 @@ describe("L.OSM.DataLayer", function () {
210210

211211
it("builds a way object", function () {
212212
var features = new L.OSM.DataLayer().buildFeatures(fixture("way"));
213-
features.length.should.eq(21);
214-
features[20].type.should.eq("way");
213+
features.length.should.eq(1);
214+
features[0].type.should.eq("way");
215215
});
216216
});
217217

0 commit comments

Comments
 (0)