Skip to content

Commit e4e3f79

Browse files
committed
Fix: Filter undefined values when showing calls
When generating the message to display actually received calls on a mock, we filtered out null values when joining our message lines. Instead we should filter undefined as this is a possible return value of `context.utils.diff`
1 parent 58064ee commit e4e3f79

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Diff for: src/matcher.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { AwsCommand, AwsStub } from 'aws-sdk-client-mock';
77

88
import { ObjectContaining } from '@vitest/expect';
99

10-
import { notNull, ordinalOf } from './utils.js';
10+
import { notUndefined, ordinalOf } from './utils.js';
1111

1212
/**
1313
* We define some aliases
@@ -125,7 +125,7 @@ function formatCalls<Input extends object, Output extends MetadataBearer>(
125125
.map(line => ` ${line}`)
126126
.join('\n'),
127127
'',
128-
].filter(notNull);
128+
].filter(notUndefined);
129129
}),
130130
`Number of calls: ${calls.length.toString()}`,
131131
].join('\n');

Diff for: src/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export function notNull<T>(obj: null | T): obj is T {
22
return obj !== null;
33
}
44

5+
export function notUndefined<T>(obj: T | undefined): obj is T {
6+
return obj !== undefined;
7+
}
8+
59
export function ordinalOf(n: number): string {
610
const j = n % 10;
711
const k = n % 100;

Diff for: tests/utils.test.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { notNull, ordinalOf } from '../src/utils.js';
3+
import { notNull, notUndefined, ordinalOf } from '../src/utils.js';
44

55
describe('notNull', () => {
66
it('returns true when not null', () => {
7-
expect(notNull('Hi')).toBe(true);
7+
expect(notNull('Hi')).toBeTruthy();
88
});
99

1010
it('returns false when null', () => {
11-
expect(notNull(null)).toBe(false);
11+
expect(notNull(null)).toBeFalsy();
1212
});
1313

1414
it('returns true when undefined', () => {
15-
expect(notNull(undefined)).toBe(true);
15+
expect(notNull(undefined)).toBeTruthy();
16+
});
17+
});
18+
19+
describe('notUndefined', () => {
20+
it('returns true when not undefined', () => {
21+
expect(notUndefined('Hi')).toBeTruthy();
22+
});
23+
24+
it('returns false when undefined', () => {
25+
expect(notUndefined(undefined)).toBeFalsy();
26+
});
27+
28+
it('returns true when null', () => {
29+
expect(notUndefined(null)).toBeTruthy();
1630
});
1731
});
1832

0 commit comments

Comments
 (0)