Skip to content

Commit 3e3d7e4

Browse files
committed
Merge pull request #159 from robertknight/anchor-override-tostring
wombat: Override HTMLAnchorElement.prototype.toString()
2 parents 04104f0 + 34721a6 commit 3e3d7e4

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

karma-tests/wombat.spec.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function runWombatTest(testCase, done) {
3434
window.assert = {
3535
equal: function (a, b) {
3636
if (a !== b) {
37-
x.equal(a, b);
3837
console.error('Mismatch between', a, 'and', b);
3938
throw new Error('AssertionError');
4039
}
@@ -133,8 +132,9 @@ describe('WombatJS', function () {
133132
});
134133

135134
describe('anchor rewriting', function () {
136-
it('should rewrite links in dynamically injected <a> tags', function (done) {
137-
runWombatTest({
135+
var config;
136+
beforeEach(function () {
137+
config = {
138138
initScript: function () {
139139
wbinfo = {
140140
wombat_opts: {},
@@ -144,13 +144,28 @@ describe('WombatJS', function () {
144144
},
145145
wombatScript: wombatScript,
146146
html: '<a href="foobar.html" id="link">A link</a>',
147-
testScript: function () {
147+
};
148+
});
149+
150+
it('should rewrite links in dynamically injected <a> tags', function (done) {
151+
config.testScript = function () {
152+
if (domTests.areDOMPropertiesConfigurable()) {
148153
var link = document.getElementById('link');
149-
if (domTests.areDOMPropertiesConfigurable()) {
150-
assert.equal(link.href, 'http:///base/karma-tests/foobar.html');
151-
}
152-
},
153-
}, done);
154+
assert.equal(link.href, 'http:///base/karma-tests/foobar.html');
155+
}
156+
};
157+
158+
runWombatTest(config, done);
159+
});
160+
161+
it('toString() should return the rewritten URL', function (done) {
162+
config.testScript = function () {
163+
if (domTests.areDOMPropertiesConfigurable()) {
164+
var link = document.getElementById('link');
165+
assert.equal(link.href, link.toString());
166+
}
167+
};
168+
runWombatTest(config, done);
154169
});
155170
});
156171

pywb/static/wombat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,9 @@ var wombat_internal = function($wbwindow) {
13971397
}
13981398

13991399
init_loc_override($wbwindow.HTMLAnchorElement.prototype, anchor_setter, anchor_getter);
1400+
$wbwindow.HTMLAnchorElement.prototype.toString = function () {
1401+
return this.href;
1402+
};
14001403
}
14011404

14021405

0 commit comments

Comments
 (0)