Skip to content

Commit aa17c4f

Browse files
committed
Relocate real world example diff into "to satisfy" test file.
1 parent 42e341c commit aa17c4f

File tree

2 files changed

+87
-85
lines changed

2 files changed

+87
-85
lines changed

test/assertions/to-satisfy.spec.js

+87
Original file line numberDiff line numberDiff line change
@@ -1200,4 +1200,91 @@ describe('"to satisfy" assertion', () => {
12001200
});
12011201
});
12021202
});
1203+
1204+
describe('when used in a real world example', () => {
1205+
it('should produce a good satisfy diff', () => {
1206+
const element = parseHtml(
1207+
'<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">' +
1208+
'<li class="selected" data-index="0">' +
1209+
'<span class="before"></span>' +
1210+
'<strong class="match">pr</strong>' +
1211+
'<span class="after">ivate</span>' +
1212+
'</li>' +
1213+
'<li data-index="1">' +
1214+
'<span class="before"></span>' +
1215+
'<strong class="match">pr</strong>' +
1216+
'<span class="after">otected</span>' +
1217+
'</li>' +
1218+
'</ul>'
1219+
);
1220+
1221+
expect(
1222+
() => {
1223+
expect(element, 'to satisfy', {
1224+
attributes: {
1225+
style: { display: 'block' },
1226+
class: ['knockout-autocomplete', 'floating-menu']
1227+
},
1228+
children: [
1229+
{
1230+
attributes: { 'data-index': '0', class: 'selected' },
1231+
children: [
1232+
{ attributes: { class: 'before' }, children: [] },
1233+
{ attributes: { class: 'match' }, children: ['pr'] },
1234+
{ attributes: { class: 'after' }, children: ['ivate'] }
1235+
]
1236+
},
1237+
{
1238+
attributes: { 'data-index': '1', class: undefined },
1239+
children: [
1240+
{ attributes: { class: 'before' }, children: [] },
1241+
{ attributes: { class: 'match' }, children: ['pr'] },
1242+
{ attributes: { class: 'after' }, children: ['odtected'] }
1243+
]
1244+
}
1245+
]
1246+
});
1247+
},
1248+
'to throw an error satisfying to equal snapshot',
1249+
expect.unindent`
1250+
expected
1251+
<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">
1252+
<li class="selected" data-index="0">
1253+
<span class="before"></span>
1254+
<strong class="match">...</strong>
1255+
<span class="after">...</span>
1256+
</li>
1257+
<li data-index="1">
1258+
<span class="before"></span>
1259+
<strong class="match">...</strong>
1260+
<span class="after">...</span>
1261+
</li>
1262+
</ul>
1263+
to satisfy
1264+
{
1265+
attributes: { style: { display: 'block' }, class: [ 'knockout-autocomplete', 'floating-menu' ] },
1266+
children: [ { attributes: ..., children: ... }, { attributes: ..., children: ... } ]
1267+
}
1268+
1269+
<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">
1270+
<li class="selected" data-index="0">
1271+
<span class="before"></span>
1272+
<strong class="match">...</strong>
1273+
<span class="after">...</span>
1274+
</li>
1275+
<li data-index="1">
1276+
<span class="before"></span>
1277+
<strong class="match">pr</strong>
1278+
<span class="after">
1279+
otected // should equal 'odtected'
1280+
//
1281+
// -otected
1282+
// +odtected
1283+
</span>
1284+
</li>
1285+
</ul>
1286+
`
1287+
);
1288+
});
1289+
});
12031290
});

test/index.spec.js

-85
Original file line numberDiff line numberDiff line change
@@ -818,89 +818,4 @@ describe('unexpected-dom', () => {
818818
});
819819
});
820820
});
821-
822-
it('should produce a good satisfy diff in a real world example', () => {
823-
const body = parseHtml('<div></div>').parentElement;
824-
body.innerHTML =
825-
'<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">' +
826-
'<li class="selected" data-index="0">' +
827-
'<span class="before"></span>' +
828-
'<strong class="match">pr</strong>' +
829-
'<span class="after">ivate</span>' +
830-
'</li>' +
831-
'<li data-index="1">' +
832-
'<span class="before"></span>' +
833-
'<strong class="match">pr</strong>' +
834-
'<span class="after">otected</span>' +
835-
'</li>' +
836-
'</ul>';
837-
838-
expect(
839-
() => {
840-
expect(body.firstChild, 'to satisfy', {
841-
attributes: {
842-
style: { display: 'block' },
843-
class: ['knockout-autocomplete', 'floating-menu']
844-
},
845-
children: [
846-
{
847-
attributes: { 'data-index': '0', class: 'selected' },
848-
children: [
849-
{ attributes: { class: 'before' }, children: [] },
850-
{ attributes: { class: 'match' }, children: ['pr'] },
851-
{ attributes: { class: 'after' }, children: ['ivate'] }
852-
]
853-
},
854-
{
855-
attributes: { 'data-index': '1', class: undefined },
856-
children: [
857-
{ attributes: { class: 'before' }, children: [] },
858-
{ attributes: { class: 'match' }, children: ['pr'] },
859-
{ attributes: { class: 'after' }, children: ['odtected'] }
860-
]
861-
}
862-
]
863-
});
864-
},
865-
'to throw an error satisfying to equal snapshot',
866-
expect.unindent`
867-
expected
868-
<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">
869-
<li class="selected" data-index="0">
870-
<span class="before"></span>
871-
<strong class="match">...</strong>
872-
<span class="after">...</span>
873-
</li>
874-
<li data-index="1">
875-
<span class="before"></span>
876-
<strong class="match">...</strong>
877-
<span class="after">...</span>
878-
</li>
879-
</ul>
880-
to satisfy
881-
{
882-
attributes: { style: { display: 'block' }, class: [ 'knockout-autocomplete', 'floating-menu' ] },
883-
children: [ { attributes: ..., children: ... }, { attributes: ..., children: ... } ]
884-
}
885-
886-
<ul class="knockout-autocomplete menu scrollable floating-menu" style="left: 0px; top: 0px; bottom: auto; display: block">
887-
<li class="selected" data-index="0">
888-
<span class="before"></span>
889-
<strong class="match">...</strong>
890-
<span class="after">...</span>
891-
</li>
892-
<li data-index="1">
893-
<span class="before"></span>
894-
<strong class="match">pr</strong>
895-
<span class="after">
896-
otected // should equal 'odtected'
897-
//
898-
// -otected
899-
// +odtected
900-
</span>
901-
</li>
902-
</ul>
903-
`
904-
);
905-
});
906821
});

0 commit comments

Comments
 (0)