@@ -12,7 +12,7 @@ import { expect } from 'chai';
1212
1313import { CommandRegistry } from '@lumino/commands' ;
1414
15- import { JSONObject } from '@lumino/coreutils' ;
15+ import { JSONObject , ReadonlyJSONObject } from '@lumino/coreutils' ;
1616
1717import { Platform } from '@lumino/domutils' ;
1818
@@ -329,7 +329,7 @@ describe('@lumino/commands', () => {
329329 } ) ;
330330
331331 describe ( '#describedBy()' , ( ) => {
332- it ( 'should get the description for a specific command' , ( ) => {
332+ it ( 'should get the description for a specific command' , async ( ) => {
333333 const description = {
334334 args : {
335335 properties : { } ,
@@ -344,16 +344,79 @@ describe('@lumino/commands', () => {
344344 describedBy : description
345345 } ;
346346 registry . addCommand ( 'test' , cmd ) ;
347- expect ( registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
347+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
348348 } ) ;
349349
350- it ( 'should return an empty description if the command is not registered' , ( ) => {
351- expect ( registry . describedBy ( 'foo' ) ) . to . deep . equal ( { args : null } ) ;
350+ it ( 'should accept a function' , async ( ) => {
351+ const description = {
352+ args : {
353+ properties : { } ,
354+ additionalProperties : false ,
355+ type : 'object'
356+ }
357+ } ;
358+
359+ let cmd = {
360+ execute : ( args : JSONObject ) => {
361+ return args ;
362+ } ,
363+ describedBy : ( ) => description
364+ } ;
365+ registry . addCommand ( 'test' , cmd ) ;
366+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
352367 } ) ;
353368
354- it ( 'should default to an empty description for a command' , ( ) => {
369+ it ( 'should accept an asynchronous function' , async ( ) => {
370+ const description = {
371+ args : {
372+ properties : { } ,
373+ additionalProperties : false ,
374+ type : 'object'
375+ }
376+ } ;
377+
378+ let cmd = {
379+ execute : ( args : JSONObject ) => {
380+ return args ;
381+ } ,
382+ describedBy : ( ) => Promise . resolve ( description )
383+ } ;
384+ registry . addCommand ( 'test' , cmd ) ;
385+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( description ) ;
386+ } ) ;
387+
388+ it ( 'should accept args' , async ( ) => {
389+ const description = {
390+ properties : { } ,
391+ additionalProperties : false ,
392+ type : 'object'
393+ } ;
394+
395+ let cmd = {
396+ execute : ( args : JSONObject ) => {
397+ return args ;
398+ } ,
399+ describedBy : ( args : ReadonlyJSONObject ) => {
400+ return {
401+ args
402+ } ;
403+ }
404+ } ;
405+ registry . addCommand ( 'test' , cmd ) ;
406+ expect (
407+ await registry . describedBy ( 'test' , description as any )
408+ ) . to . deep . equal ( { args : description } ) ;
409+ } ) ;
410+
411+ it ( 'should return an empty description if the command is not registered' , async ( ) => {
412+ expect ( await registry . describedBy ( 'foo' ) ) . to . deep . equal ( { args : null } ) ;
413+ } ) ;
414+
415+ it ( 'should default to an empty description for a command' , async ( ) => {
355416 registry . addCommand ( 'test' , NULL_COMMAND ) ;
356- expect ( registry . describedBy ( 'test' ) ) . to . deep . equal ( { args : null } ) ;
417+ expect ( await registry . describedBy ( 'test' ) ) . to . deep . equal ( {
418+ args : null
419+ } ) ;
357420 } ) ;
358421 } ) ;
359422
0 commit comments