11/* eslint-env jest */
2+ import { getFakeNvimClient } from '../testUtil' ;
23import { callable , NvimPlugin } from './NvimPlugin' ;
34
45describe ( 'NvimPlugin' , ( ) => {
56 it ( 'should initialise variables' , ( ) => {
6- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
7+ const fakeNvimClient = getFakeNvimClient ( ) ;
8+ const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , fakeNvimClient ) ;
79
810 expect ( plugin . filename ) . toEqual ( '/tmp/filename' ) ;
9- expect ( plugin . nvim ) . toEqual ( { } ) ;
11+ expect ( plugin . nvim ) . toEqual ( fakeNvimClient ) ;
1012 expect ( plugin . dev ) . toBe ( false ) ;
1113 expect ( Object . keys ( plugin . autocmds ) ) . toHaveLength ( 0 ) ;
1214 expect ( Object . keys ( plugin . commands ) ) . toHaveLength ( 0 ) ;
1315 expect ( Object . keys ( plugin . functions ) ) . toHaveLength ( 0 ) ;
1416 } ) ;
1517
1618 it ( 'should set dev options when you call setOptions' , ( ) => {
17- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
19+ const plugin = new NvimPlugin (
20+ '/tmp/filename' ,
21+ ( ) => { } ,
22+ getFakeNvimClient ( )
23+ ) ;
1824 plugin . setOptions ( { dev : true } ) ;
1925 expect ( plugin . dev ) . toBe ( true ) ;
2026 expect ( plugin . shouldCacheModule ) . toBe ( false ) ;
2127 } ) ;
2228
2329 it ( 'should store registered autocmds' , ( ) => {
24- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
30+ const plugin = new NvimPlugin (
31+ '/tmp/filename' ,
32+ ( ) => { } ,
33+ getFakeNvimClient ( )
34+ ) ;
2535 const fn = ( ) => { } ;
2636 const opts = { pattern : '*' } ;
2737 const spec = {
@@ -36,7 +46,11 @@ describe('NvimPlugin', () => {
3646 } ) ;
3747
3848 it ( 'should store registered commands' , ( ) => {
39- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
49+ const plugin = new NvimPlugin (
50+ '/tmp/filename' ,
51+ ( ) => { } ,
52+ getFakeNvimClient ( )
53+ ) ;
4054 const fn = ( ) => { } ;
4155 const opts = { sync : true } ;
4256 const spec = {
@@ -51,7 +65,11 @@ describe('NvimPlugin', () => {
5165 } ) ;
5266
5367 it ( 'should store registered functions' , ( ) => {
54- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
68+ const plugin = new NvimPlugin (
69+ '/tmp/filename' ,
70+ ( ) => { } ,
71+ getFakeNvimClient ( )
72+ ) ;
5573 const fn = ( ) => { } ;
5674 const opts = { sync : true } ;
5775 const spec = {
@@ -66,7 +84,11 @@ describe('NvimPlugin', () => {
6684 } ) ;
6785
6886 it ( 'should not add autocmds with no pattern option' , ( ) => {
69- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
87+ const plugin = new NvimPlugin (
88+ '/tmp/filename' ,
89+ ( ) => { } ,
90+ getFakeNvimClient ( )
91+ ) ;
7092 plugin . registerAutocmd ( 'BufWritePre' , ( ) => { } , { pattern : '' } ) ;
7193 expect ( Object . keys ( plugin . autocmds ) ) . toHaveLength ( 0 ) ;
7294 } ) ;
@@ -82,7 +104,11 @@ describe('NvimPlugin', () => {
82104 const thisObj = { } ;
83105 expect ( callable ( [ thisObj , fn ] ) ( ) ) . toBe ( thisObj ) ;
84106
85- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
107+ const plugin = new NvimPlugin (
108+ '/tmp/filename' ,
109+ ( ) => { } ,
110+ getFakeNvimClient ( )
111+ ) ;
86112 const obj = {
87113 func : jest . fn ( function ( ) {
88114 return this ;
@@ -97,13 +123,21 @@ describe('NvimPlugin', () => {
97123 } ) ;
98124
99125 it ( 'should not register commands with incorrect callable arguments' , ( ) => {
100- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
126+ const plugin = new NvimPlugin (
127+ '/tmp/filename' ,
128+ ( ) => { } ,
129+ getFakeNvimClient ( )
130+ ) ;
101131 plugin . registerCommand ( 'MyCommand' , [ ] , { } ) ;
102132 expect ( Object . keys ( plugin . commands ) ) . toHaveLength ( 0 ) ;
103133 } ) ;
104134
105135 it ( 'should return specs for registered commands' , ( ) => {
106- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
136+ const plugin = new NvimPlugin (
137+ '/tmp/filename' ,
138+ ( ) => { } ,
139+ getFakeNvimClient ( )
140+ ) ;
107141 const fn = ( ) => { } ;
108142 const aOpts = { pattern : '*' } ;
109143 const aSpec = {
@@ -136,7 +170,11 @@ describe('NvimPlugin', () => {
136170 } ) ;
137171
138172 it ( 'should handle requests for registered commands' , async ( ) => {
139- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
173+ const plugin = new NvimPlugin (
174+ '/tmp/filename' ,
175+ ( ) => { } ,
176+ getFakeNvimClient ( )
177+ ) ;
140178 const fn = arg => arg ;
141179
142180 plugin . registerAutocmd ( 'BufWritePre' , fn , { pattern : '*' , sync : true } ) ;
@@ -155,7 +193,11 @@ describe('NvimPlugin', () => {
155193 } ) ;
156194
157195 it ( 'should throw on unknown request' , ( ) => {
158- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
196+ const plugin = new NvimPlugin (
197+ '/tmp/filename' ,
198+ ( ) => { } ,
199+ getFakeNvimClient ( )
200+ ) ;
159201 expect . assertions ( 1 ) ;
160202 plugin . handleRequest ( 'BufWritePre *' , 'autocmd' , [ true ] ) . catch ( err => {
161203 expect ( err ) . toEqual (
0 commit comments