Skip to content

Commit d4abeb3

Browse files
committed
test: Add toToggleLineTo() custom matcher
1 parent cc5c1e6 commit d4abeb3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { diff } from 'jest-diff';
2+
import { fromLine } from '../TestHelpers';
3+
4+
declare global {
5+
namespace jest {
6+
interface Matchers<R> {
7+
toToggleLineTo(expectedLines: string[]): R;
8+
}
9+
10+
interface Expect {
11+
toToggleLineTo(expectedLines: string[]): any;
12+
}
13+
14+
interface InverseAsymmetricMatchers {
15+
toToggleLineTo(expectedLines: string[]): any;
16+
}
17+
}
18+
}
19+
20+
export function toToggleLineTo(line: string, expectedLines: string[]) {
21+
const task = fromLine({ line: line });
22+
const receivedLines = task.toggle().map((t) => t.toFileLineString());
23+
24+
const matches = receivedLines.join('\n') === expectedLines.join('\n');
25+
if (!matches) {
26+
return {
27+
message: () => 'unexpected incorrect new task lines:\n' + diff(expectedLines, receivedLines),
28+
pass: false,
29+
};
30+
}
31+
32+
return {
33+
message: () => `new task lines" should not be: "${receivedLines}"`,
34+
pass: true,
35+
};
36+
}

tests/CustomMatchers/jest.custom_matchers.setup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ expect.extend({
3636
toBeIdenticalTo,
3737
});
3838

39+
// ---------------------------------------------------------------------
40+
// CustomMatchersForTasks
41+
// ---------------------------------------------------------------------
42+
import { toToggleLineTo } from './CustomMatchersForTasks';
43+
expect.extend({
44+
toToggleLineTo,
45+
});
46+
3947
// ---------------------------------------------------------------------
4048
// CustomMatchersForTaskBuilder
4149
// ---------------------------------------------------------------------

0 commit comments

Comments
 (0)