Commit 27f04b76 authored by Robert Knight's avatar Robert Knight

Adapt to API change in dom-anchor-text-quote v4.x

Adapt to `toRange` returning null in 4.x rather than throwing an
exception if the quote is not found and add a test case for quote
anchoring failing.

See https://github.com/tilgovi/dom-anchor-text-quote/issues/10
parent 80863344
'use strict'; 'use strict';
var html = require('../html'); var html = require('../html');
var unroll = require('../../../test/util').unroll;
var toResult = require('../../../test/promise-util').toResult;
var unroll = require('../../../test/util').unroll;
var fixture = require('./html-anchoring-fixture.html'); var fixture = require('./html-anchoring-fixture.html');
/** Return all text node children of `container`. */ /** Return all text node children of `container`. */
...@@ -190,6 +191,19 @@ describe('HTML anchoring', function () { ...@@ -190,6 +191,19 @@ describe('HTML anchoring', function () {
return Promise.all(anchored); return Promise.all(anchored);
}, testCases); }, testCases);
describe('When anchoring fails', function () {
it('throws an error if anchoring using a quote fails', function () {
var quoteSelector = {
type: 'TextQuoteSelector',
exact: 'This text does not appear in the web page',
};
return toResult(html.anchor(container, [quoteSelector])).then(function (result) {
assert.equal(result.error.message, 'Quote not found');
});
});
});
describe('Web page baselines', function () { describe('Web page baselines', function () {
var fixtures = require('./html-baselines'); var fixtures = require('./html-baselines');
var frame; var frame;
......
...@@ -101,7 +101,10 @@ class TextQuoteAnchor ...@@ -101,7 +101,10 @@ class TextQuoteAnchor
} }
toRange: (options = {}) -> toRange: (options = {}) ->
domAnchorTextQuote.toRange(@root, this.toSelector(), options) range = domAnchorTextQuote.toRange(@root, this.toSelector(), options)
if range == null
throw new Error('Quote not found')
range
exports.RangeAnchor = RangeAnchor exports.RangeAnchor = RangeAnchor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment