Skip to content

Commit

Permalink
Adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVolland committed Apr 10, 2019
1 parent c02c258 commit 141cbcf
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions src/ShapefileDataParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,55 @@ beforeEach(() => {
parser = new ShapefileDataParser();
});

it('ShapefileDataParser is defined', () => {
expect(ShapefileDataParser).toBeDefined();
});
describe('ShapefileDataParser', () => {

it('…is defined', () => {
expect(ShapefileDataParser).toBeDefined();
});

describe('ShapefileDataParser implements DataParser', () => {
describe('implements DataParser', () => {

it('…readData is defined', () => {
expect(parser.readData).toBeDefined();
});

it('readData is defined', () => {
expect(parser.readData).toBeDefined();
});

});
describe('constructor', () => {

describe('readData implementation', () => {
it('…creates a GeoJsonDataParser with the passed projections', () => {
const parserWithProjection = new ShapefileDataParser('EPSG:3857', 'EPSG:4326');
expect(parserWithProjection._geoJsonParser.sourceProjection).toBe('EPSG:3857');
expect(parserWithProjection._geoJsonParser.targetProjection).toBe('EPSG:4326');
});

it('can read a Buffer', async () => {
const buffer = readFileSync(path.resolve(__dirname, '../data/point.zip'));
const data = await parser.readData(buffer);
expect(data).toEqual(expectedData);
});

describe('readData implementation', () => {

it('…can read a Buffer', async () => {
const buffer = readFileSync(path.resolve(__dirname, '../data/point.zip'));
const data = await parser.readData(buffer);
expect(data).toEqual(expectedData);
});

it('…rejects the promise if called with invalid (Array)Buffer', (done) => {
expect.assertions(1);
const buffer = new ArrayBuffer(0);
parser.readData(buffer)
.catch((e) => {
expect(e).toBeDefined();
}).finally(done);
});

it('…rejects the promise if called with invalid Argument', (done) => {
expect.assertions(1);
const buffer = undefined as unknown as ArrayBuffer;
parser.readData(buffer)
.catch((e) => {
expect(e).toBeDefined();
}).finally(done);
});

});
});

0 comments on commit 141cbcf

Please sign in to comment.