Skip to content

Commit 1e881d0

Browse files
committed
Fix browser tests
1 parent b3a80b5 commit 1e881d0

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"babel-core": "^7.0.0-bridge.0",
2929
"babel-eslint": "^10.0.0",
3030
"babel-jest": "^23.4.2",
31-
"bowser": "^2.0.0",
3231
"eslint": "^5.0.0",
3332
"eslint-config-airbnb-base": "^13.0.0",
3433
"eslint-plugin-import": "^2.0.0",

src/index.test.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import bowser from 'bowser';
21
import h from 'hastscript';
32

43
import { serializeNodeToHtmlString } from './utils';
@@ -54,13 +53,14 @@ describe('hast-util-to-dom', () => {
5453
}],
5554
}],
5655
};
57-
const htmlActual = serializeNodeToHtmlString(toDOM(tree));
58-
let htmlExpected = '<!DOCTYPE html><html><head></head><body></body></html>';
59-
if (!bowser.x) {
60-
if (bowser.gecko) {
61-
htmlExpected = '<!DOCTYPE html>\n<html><head></head><body></body></html>';
62-
}
56+
const doctype = '<!DOCTYPE html>';
57+
const htmlExpected = `${doctype}<html><head></head><body></body></html>`;
58+
let htmlActual = serializeNodeToHtmlString(toDOM(tree));
59+
60+
if (htmlActual.charAt(doctype.length) === '\n') {
61+
htmlActual = htmlActual.slice(0, doctype.length) + htmlActual.slice(doctype.length + 1);
6362
}
63+
6464
expect(htmlActual).toEqual(htmlExpected);
6565
});
6666

@@ -100,16 +100,15 @@ describe('hast-util-to-dom', () => {
100100
disabled: true,
101101
value: 'foo',
102102
});
103-
const htmlActual = serializeNodeToHtmlString(toDOM(tree));
104-
let htmlExpected = '<input disabled="" value="foo">';
105-
// Specific non-JSDOM environments
106-
if (!bowser.x) {
107-
if (bowser.webkit || bowser.blink) {
108-
htmlExpected = '<input disabled="" value="foo" />';
109-
} else if (bowser.gecko) {
110-
htmlExpected = '<input disabled="disabled" value="foo" />';
111-
}
103+
const htmlExpected = '<input disabled="disabled" value="foo">';
104+
let htmlActual = serializeNodeToHtmlString(toDOM(tree));
105+
106+
htmlActual = htmlActual.replace(/disabled=""/, 'disabled="disabled"');
107+
108+
if (htmlActual.slice(-3) === ' />') {
109+
htmlActual = `${htmlActual.slice(0, -3)}>`;
112110
}
111+
113112
expect(htmlActual).toEqual(htmlExpected);
114113
});
115114

@@ -123,13 +122,13 @@ describe('hast-util-to-dom', () => {
123122
it('handles comma-separated attributes correctly', () => {
124123
const img = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=';
125124
const tree = h('img', { srcSet: [`${img} 1x`, `${img} 2x`] });
126-
const htmlActual = serializeNodeToHtmlString(toDOM(tree));
127-
let htmlExpected = `<img srcset="${img} 1x, ${img} 2x">`;
128-
if (!bowser.x) {
129-
if (bowser.webkit || bowser.blink || bowser.gecko) {
130-
htmlExpected = `<img srcset="${img} 1x, ${img} 2x" />`;
131-
}
125+
const htmlExpected = `<img srcset="${img} 1x, ${img} 2x">`;
126+
let htmlActual = serializeNodeToHtmlString(toDOM(tree));
127+
128+
if (htmlActual.slice(-3) === ' />') {
129+
htmlActual = `${htmlActual.slice(0, -3)}>`;
132130
}
131+
133132
expect(htmlActual).toEqual(htmlExpected);
134133
});
135134

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,11 +1371,6 @@ body-parser@^1.16.1:
13711371
raw-body "2.3.3"
13721372
type-is "~1.6.16"
13731373

1374-
bowser@^2.0.0:
1375-
version "2.4.0"
1376-
resolved "https://registry.yarnpkg.com/bowser/-/bowser-2.4.0.tgz#fcfbca3d7659ba88afabbb8a45b33d2e4876a90c"
1377-
integrity sha512-DA9Opnb8S8TBLPPszrHDtCCATbAMkrxF+AxPs/d95r99frBioGpNwL1cbG3AHeV3FnoZW655vEvEryBHFeGrMg==
1378-
13791374
brace-expansion@^1.1.7:
13801375
version "1.1.11"
13811376
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"

0 commit comments

Comments
 (0)