Skip to content

Commit d8f899f

Browse files
authored
Merge pull request #9 from unexpectedjs/ssimonsen/expose-expected-on-move-target
Expose expected value on the move target
2 parents 7d0e226 + afe09ab commit d8f899f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/arrayChanges.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ module.exports = function arrayChanges(actual, expected, equal, similar, options
8080
moves.forEach(function (diffItem) {
8181
var moveFromIndex = offsetIndex(diffItem.from + 1) - 1;
8282
var removed = mutatedArray.slice(moveFromIndex, diffItem.howMany + moveFromIndex);
83-
var added = removed.map(function (v) {
84-
return extend({}, v, { last: false, type: 'moveTarget' });
85-
});
8683
removed.forEach(function (v, index) {
8784
v.type = 'moveSource';
8885
v.expectedIndex = offsetIndex(diffItem.to + index);
8986
v.expected = expected[v.expectedIndex];
9087
v.equal = equal(v.value, v.expected);
9188
});
89+
var added = removed.map(function (v, index) {
90+
return extend({}, v, { last: false, type: 'moveTarget' });
91+
});
9292
var insertIndex = offsetIndex(diffItem.to);
9393
Array.prototype.splice.apply(mutatedArray, [insertIndex, 0].concat(added));
9494
});

test/arrayChanges.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('array-changes', function () {
109109
expect(arrayChanges([1, 2, 3, 0], [0, 1, 2, 3], function (a, b) {
110110
return a === b;
111111
}), 'to equal', [
112-
{ type: 'moveTarget', value: 0, actualIndex: 3, last: false },
112+
{ type: 'moveTarget', value: 0, actualIndex: 3, expected: 0, expectedIndex: 0, equal: true, last: false },
113113
{ type: 'equal', value: 1, actualIndex: 0, expected: 1, expectedIndex: 1 },
114114
{ type: 'equal', value: 2, actualIndex: 1, expected: 2, expectedIndex: 2 },
115115
{ type: 'equal', value: 3, actualIndex: 2, expected: 3, expectedIndex: 3 },
@@ -122,7 +122,7 @@ describe('array-changes', function () {
122122
return a === b;
123123
}), 'to equal', [
124124
{ type: 'equal', value: 0, actualIndex: 0, expected: 0, expectedIndex: 0 },
125-
{ type: 'moveTarget', value: 2, actualIndex: 2, last: false },
125+
{ type: 'moveTarget', value: 2, actualIndex: 2, expected: 2, expectedIndex: 1, equal: true, last: false },
126126
{ type: 'equal', value: 1, actualIndex: 1, expected: 1, expectedIndex: 2 },
127127
{ type: 'moveSource', value: 2, actualIndex: 2, expected: 2, expectedIndex: 1, equal: true },
128128
{ type: 'equal', value: 3, actualIndex: 3, expected: 3, expectedIndex: 3, last: true }
@@ -445,7 +445,15 @@ describe('array-changes', function () {
445445
}, function (a, b) {
446446
return a.kind === b.kind;
447447
}), 'to equal', [
448-
{ type: 'moveTarget', value: { kind: 1, type: 'tag', name: 'p', children: [{ data: 'Hello world 2023', type: 'text' }], attribs: {} }, actualIndex: 1, last: false },
448+
{
449+
type: 'moveTarget',
450+
value: { kind: 1, type: 'tag', name: 'p', children: [{ data: 'Hello world 2023', type: 'text' }], attribs: {} },
451+
expected: { kind: 1, type: 'tag', name: 'p', children: [{ data: 'Hello world 2025', type: 'text' }], attribs: {} },
452+
actualIndex: 1,
453+
expectedIndex: 0,
454+
equal: false,
455+
last: false
456+
},
449457
{
450458
type: 'equal',
451459
value: { kind: 0, type: 'tag', name: 'p', children: [{ data: 'A', type: 'text' }], attribs: {} },

0 commit comments

Comments
 (0)