From 205d3b4aeb1b01bb326a06b9ac36e79b937bb9cc Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] fix the format and use window.location --- src/snapshot.ts | 2 +- test/snapshot.test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/snapshot.ts b/src/snapshot.ts index 1e6bec85..ec23e7ba 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -107,7 +107,7 @@ function serializeNode(n: Node, doc: Document): serializedNode | false { if (name === 'src' || name === 'href') { attributes[name] = absoluteToDoc(doc, value); } else if (name === 'style') { - attributes[name] = absoluteToStylesheet(value, doc.location.href); + attributes[name] = absoluteToStylesheet(value, location.href); } else { attributes[name] = value; } diff --git a/test/snapshot.test.ts b/test/snapshot.test.ts index 45ce11dc..197fb7ad 100644 --- a/test/snapshot.test.ts +++ b/test/snapshot.test.ts @@ -48,8 +48,14 @@ describe('absolute url to stylesheet', () => { }); it('can handle multiple no quote paths', () => { - expect(absoluteToStylesheet('background-image: url(images/b.jpg); background: #aabbcc url(images/a.jpg) 50% 50% repeat;', href)).to.equal( - `background-image: url('http://localhost/css/images/b.jpg'); background: #aabbcc url('http://localhost/css/images/a.jpg') 50% 50% repeat;`, + expect( + absoluteToStylesheet( + 'background-image: url(images/b.jpg); background: #aabbcc url(images/a.jpg) 50% 50% repeat;', + href, + ), + ).to.equal( + `background-image: url('http://localhost/css/images/b.jpg');` + + `background: #aabbcc url('http://localhost/css/images/a.jpg') 50% 50% repeat;`, ); });