Skip to content

Commit c0d8399

Browse files
author
Philipp Loose
committed
Use CommandSource as input to second call of getNamesAndValues
In the picker unit tests two calls to getNamesAndValues are used to extract values from enums. The second call used a generic with type 'CommandSource' but as input a Type object. To be more meaningful this has been changed to 'CommandSource' so that the test checks different TestItem types against different command sources. Otherwise it would test TestItem types against TestItem types. Furthermore extracting name and value of CommandSource.commandpalette with getNamesAndValues was not successful and returned undefined. This has been fixed by assigning CommandSource.commandpalette directly to commandSource.value when this command source is evaluated.
1 parent e1d0ad5 commit c0d8399

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/test/testing/display/picker.unit.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ import { onItemSelected, Type } from '../../../client/testing/display/picker';
1616

1717
suite('Unit Tests - Picker (execution of commands)', () => {
1818
getNamesAndValues<Type>(Type).forEach(item => {
19-
getNamesAndValues<CommandSource>(Type).forEach(commandSource => {
19+
getNamesAndValues<CommandSource>(CommandSource).forEach(commandSource => {
2020
[true, false].forEach(debug => {
2121
test(`Invoking command for selection ${item.name} from ${commandSource.name} (${debug ? 'Debug' : 'No debug'})`, async () => {
2222
const commandManager = mock(CommandManager);
2323
const workspaceUri = Uri.file(__filename);
2424

2525
const testFunction = 'some test Function';
26-
const selection = { type: item.value, fn: { testFunction } };
26+
// Getting the value of CommandSource.commandPalette in getNamesAndValues(CommandSource)
27+
// fails because the names and values object is build by accessing the CommandSource enum
28+
// properties by value. In case of commandpalette the property is commandPalette and the
29+
// respective value is commandpalette which do not match and thus return undefined for value.
30+
if (commandSource.name === 'commandpalette') {
31+
commandSource.value = CommandSource.commandPalette;
32+
}
33+
2734
onItemSelected(instance(commandManager), commandSource.value, workspaceUri, selection as any, debug);
2835

2936
switch (selection.type) {

0 commit comments

Comments
 (0)