Skip to content

Commit

Permalink
FIX: microsoft edge xpath evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
savarex committed Nov 29, 2017
1 parent 66458ae commit d708125
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@ describe('XmlLoaderComponent', () => {
fixture = TestBed.createComponent(XmlLoaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
spyOn(component.loaded, 'emit').and.callThrough();
});

it('should create', () => {
expect(component).toBeTruthy();
});

describe('when onFileChange', () => {
it('should not fire loaded if files is empty ', () => {
it('should not fire loaded if files is empty ', (done) => {
spyOn(component.loaded, 'emit').and.callThrough();
return component.onFileChange({ target: { files: [] } })
.then( () => {
expect(component.loaded.emit).not.toHaveBeenCalled();
done();
});
});

it('should fire loaded if files is not empty ', () => {
it('should fire loaded if files is not empty ', (done) => {
const blob = new Blob(['<root></root>'], { type: 'text/xml' });
return component
spyOn(component.loaded, 'emit').and.callThrough();
component
.onFileChange({ target: { files: [ blob ] } })
.then( () => {
expect(component.loaded.emit).toHaveBeenCalledTimes(1);
done();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TestBed, inject } from '@angular/core/testing';

import { XmlParserService } from './xml-parser.service';

describe('XmlParserService', () => {
Expand Down Expand Up @@ -65,6 +64,16 @@ describe('XmlParserService', () => {
expect(actual).toBeUndefined();
});
});

describe('a valid xpath', () => {
it('should be called in a way that works on Chrome, Edge and Firefox', () => {
spyOn(xml, 'evaluate').and.callThrough();
const xpath = '//multiProp';
const actual = service.getText(xml, xpath);
expect(xml.evaluate)
.toHaveBeenCalledWith(xpath + '/text()', xml, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
});
});
});

describe('when you call hasNode with', () => {
Expand Down Expand Up @@ -127,11 +136,8 @@ describe('XmlParserService', () => {
describe('an xpath that doesn\'t match a valid date', () => {
it('should be returned undefined', () => {
const actual = service.getDate(xml, '/root/propB');
console.log(actual);
expect(actual).toBeUndefined();
});
});

});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class XmlParserService {

public getText(xml: Document, xpath: string) {
xpath += '/text()';
const value = xml.evaluate(xpath, xml, undefined, undefined, undefined);
const value = xml.evaluate(xpath, xml, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

let textNode: Node;
let result: string;
Expand Down

0 comments on commit d708125

Please sign in to comment.