1
1
/* eslint-env jest */
2
+ import { getFakeNvimClient } from '../testUtil' ;
2
3
import { callable , NvimPlugin } from './NvimPlugin' ;
3
4
4
5
describe ( 'NvimPlugin' , ( ) => {
5
6
it ( 'should initialise variables' , ( ) => {
6
- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
7
+ const fakeNvimClient = getFakeNvimClient ( ) ;
8
+ const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , fakeNvimClient ) ;
7
9
8
10
expect ( plugin . filename ) . toEqual ( '/tmp/filename' ) ;
9
- expect ( plugin . nvim ) . toEqual ( { } ) ;
11
+ expect ( plugin . nvim ) . toEqual ( fakeNvimClient ) ;
10
12
expect ( plugin . dev ) . toBe ( false ) ;
11
13
expect ( Object . keys ( plugin . autocmds ) ) . toHaveLength ( 0 ) ;
12
14
expect ( Object . keys ( plugin . commands ) ) . toHaveLength ( 0 ) ;
13
15
expect ( Object . keys ( plugin . functions ) ) . toHaveLength ( 0 ) ;
14
16
} ) ;
15
17
16
18
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
+ ) ;
18
24
plugin . setOptions ( { dev : true } ) ;
19
25
expect ( plugin . dev ) . toBe ( true ) ;
20
26
expect ( plugin . shouldCacheModule ) . toBe ( false ) ;
21
27
} ) ;
22
28
23
29
it ( 'should store registered autocmds' , ( ) => {
24
- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
30
+ const plugin = new NvimPlugin (
31
+ '/tmp/filename' ,
32
+ ( ) => { } ,
33
+ getFakeNvimClient ( )
34
+ ) ;
25
35
const fn = ( ) => { } ;
26
36
const opts = { pattern : '*' } ;
27
37
const spec = {
@@ -36,7 +46,11 @@ describe('NvimPlugin', () => {
36
46
} ) ;
37
47
38
48
it ( 'should store registered commands' , ( ) => {
39
- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
49
+ const plugin = new NvimPlugin (
50
+ '/tmp/filename' ,
51
+ ( ) => { } ,
52
+ getFakeNvimClient ( )
53
+ ) ;
40
54
const fn = ( ) => { } ;
41
55
const opts = { sync : true } ;
42
56
const spec = {
@@ -51,7 +65,11 @@ describe('NvimPlugin', () => {
51
65
} ) ;
52
66
53
67
it ( 'should store registered functions' , ( ) => {
54
- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
68
+ const plugin = new NvimPlugin (
69
+ '/tmp/filename' ,
70
+ ( ) => { } ,
71
+ getFakeNvimClient ( )
72
+ ) ;
55
73
const fn = ( ) => { } ;
56
74
const opts = { sync : true } ;
57
75
const spec = {
@@ -66,7 +84,11 @@ describe('NvimPlugin', () => {
66
84
} ) ;
67
85
68
86
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
+ ) ;
70
92
plugin . registerAutocmd ( 'BufWritePre' , ( ) => { } , { pattern : '' } ) ;
71
93
expect ( Object . keys ( plugin . autocmds ) ) . toHaveLength ( 0 ) ;
72
94
} ) ;
@@ -82,7 +104,11 @@ describe('NvimPlugin', () => {
82
104
const thisObj = { } ;
83
105
expect ( callable ( [ thisObj , fn ] ) ( ) ) . toBe ( thisObj ) ;
84
106
85
- const plugin = new NvimPlugin ( '/tmp/filename' , ( ) => { } , { } ) ;
107
+ const plugin = new NvimPlugin (
108
+ '/tmp/filename' ,
109
+ ( ) => { } ,
110
+ getFakeNvimClient ( )
111
+ ) ;
86
112
const obj = {
87
113
func : jest . fn ( function ( ) {
88
114
return this ;
@@ -97,13 +123,21 @@ describe('NvimPlugin', () => {
97
123
} ) ;
98
124
99
125
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
+ ) ;
101
131
plugin . registerCommand ( 'MyCommand' , [ ] , { } ) ;
102
132
expect ( Object . keys ( plugin . commands ) ) . toHaveLength ( 0 ) ;
103
133
} ) ;
104
134
105
135
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
+ ) ;
107
141
const fn = ( ) => { } ;
108
142
const aOpts = { pattern : '*' } ;
109
143
const aSpec = {
@@ -136,7 +170,11 @@ describe('NvimPlugin', () => {
136
170
} ) ;
137
171
138
172
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
+ ) ;
140
178
const fn = arg => arg ;
141
179
142
180
plugin . registerAutocmd ( 'BufWritePre' , fn , { pattern : '*' , sync : true } ) ;
@@ -155,7 +193,11 @@ describe('NvimPlugin', () => {
155
193
} ) ;
156
194
157
195
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
+ ) ;
159
201
expect . assertions ( 1 ) ;
160
202
plugin . handleRequest ( 'BufWritePre *' , 'autocmd' , [ true ] ) . catch ( err => {
161
203
expect ( err ) . toEqual (
0 commit comments