1- import * as Sinon from "sinon" ;
2- import { expect } from "chai" ;
31import { workspace } from "vscode" ;
42
53import {
64 CliConfigListener ,
5+ ConfigListener ,
76 QueryHistoryConfigListener ,
87 QueryServerConfigListener ,
98} from "../../config" ;
109
11- describe ( "config listeners" , function ( ) {
12- // Because we are adding some extra waiting, need to bump the test timeouts.
13- this . timeout ( 5000 ) ;
14-
15- let sandbox : Sinon . SinonSandbox ;
16- beforeEach ( ( ) => {
17- sandbox = Sinon . createSandbox ( ) ;
18- } ) ;
19-
20- afterEach ( ( ) => {
21- sandbox . restore ( ) ;
22- } ) ;
23-
10+ describe ( "config listeners" , ( ) => {
2411 interface TestConfig < T > {
25- clazz : new ( ) => unknown ;
12+ clazz : new ( ) => ConfigListener ;
2613 settings : {
2714 name : string ;
2815 property : string ;
@@ -95,23 +82,14 @@ describe("config listeners", function () {
9582
9683 testConfig . forEach ( ( config ) => {
9784 describe ( config . clazz . name , ( ) => {
98- let listener : any ;
99- let spy : Sinon . SinonSpy ;
100- beforeEach ( ( ) => {
101- listener = new config . clazz ( ) ;
102- spy = Sinon . spy ( ) ;
103- listener . onDidChangeConfiguration ( spy ) ;
104- } ) ;
105-
10685 config . settings . forEach ( ( setting ) => {
107- let origValue : any ;
86+ let origValue : string | number | boolean | undefined ;
10887 beforeEach ( async ( ) => {
10988 origValue = workspace . getConfiguration ( ) . get ( setting . name ) ;
11089 await workspace
11190 . getConfiguration ( )
11291 . update ( setting . name , setting . values [ 0 ] ) ;
11392 await wait ( ) ;
114- spy . resetHistory ( ) ;
11593 } ) ;
11694
11795 afterEach ( async ( ) => {
@@ -120,12 +98,17 @@ describe("config listeners", function () {
12098 } ) ;
12199
122100 it ( `should listen for changes to '${ setting . name } '` , async ( ) => {
101+ const listener = new config . clazz ( ) ;
102+ const onDidChangeConfiguration = jest . fn ( ) ;
103+ listener . onDidChangeConfiguration ( onDidChangeConfiguration ) ;
104+
123105 await workspace
124106 . getConfiguration ( )
125107 . update ( setting . name , setting . values [ 1 ] ) ;
126108 await wait ( ) ;
127- expect ( listener [ setting . property ] ) . to . eq ( setting . values [ 1 ] ) ;
128- expect ( spy ) . to . have . been . calledOnce ;
109+ const newValue = listener [ setting . property as keyof typeof listener ] ;
110+ expect ( newValue ) . toEqual ( setting . values [ 1 ] ) ;
111+ expect ( onDidChangeConfiguration ) . toHaveBeenCalledTimes ( 1 ) ;
129112 } ) ;
130113 } ) ;
131114 } ) ;
0 commit comments