├── LICENSE ├── README.md ├── UltiSnips └── javascript_jest.snippets ├── addon-info.json └── autoload └── vim_jest_snippets.vim /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kersul 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim Jest Snippets 2 | ## Snippets for UltiSnips 3 | 4 | An Vim snippet library for [Jest](https://facebook.github.io/jest/). This library uses ES6 syntax. 5 | 6 | Based on [Atom Jest Snippets](https://github.com/bryceosterhaus/atom-jest-snippets). 7 | 8 | ## Installation 9 | 10 | #### Using Vundle 11 | Add this line to your .vimrc file 12 | 13 | ``` 14 | Plugin 'joaohkfaria/vim-jest-snippets' 15 | ``` 16 | 17 | ## Snippet Available 18 | 19 | #### [exp] 20 | expect(value) 21 | ```js 22 | expect($1)$2; 23 | ``` 24 | 25 | #### [ebe] 26 | expect(value).toBe(value) 27 | ```js 28 | expect($1).toBe($2); 29 | ``` 30 | 31 | #### [ecall] 32 | expect(mockFn).toHaveBeenCalled() 33 | ```js 34 | expect($1).toHaveBeenCalled(); 35 | ``` 36 | 37 | #### [ecallt] 38 | expect(mockFn).toHaveBeenCalledTimes(number) 39 | ```js 40 | expect($1).toHaveBeenCalledTimes($2); 41 | ``` 42 | 43 | #### [ecallw] 44 | expect(mockFn).toHaveBeenCalledWith(arg1, arg2, ...) 45 | ```js 46 | expect($1).toHaveBeenCalledWith($2); 47 | ``` 48 | 49 | #### [ecloseto] 50 | expect(number).toBeCloseTo(number, numDigits) 51 | ```js 52 | expect($1).toBeCloseTo($2, $3); 53 | ``` 54 | 55 | #### [edef] 56 | expect(value).toBeDefined() 57 | ```js 58 | expect($1).toBeDefined(); 59 | ``` 60 | 61 | #### [efalsy] 62 | expect(value).toBeFalsy() 63 | ```js 64 | expect($1).toBeFalsy(); 65 | ``` 66 | 67 | #### [egreater] 68 | expect(number).toBeGreaterThan(number) 69 | ```js 70 | expect($1).toBeGreaterThan($2); 71 | ``` 72 | 73 | #### [egreateror] 74 | expect(number).toBeGreaterThanOrEqual(number) 75 | ```js 76 | expect($1).toBeGreaterThanOrEqual($2); 77 | ``` 78 | 79 | #### [eless] 80 | expect(number).toBeLessThan(number) 81 | ```js 82 | expect($1).toBeLessThan($2); 83 | ``` 84 | 85 | #### [elessor] 86 | expect(number).toBeLessThanOrEqual(number) 87 | ```js 88 | expect($1).toBeLessThanOrEqual($2); 89 | ``` 90 | 91 | #### [einst] 92 | expect(obj).toBeInstanceOf(Class) 93 | ```js 94 | expect($1).toBeInstanceOf($2); 95 | ``` 96 | 97 | #### [enull] 98 | expect(value).toBeNull() 99 | ```js 100 | expect($1).toBeNull(); 101 | ``` 102 | 103 | #### [etruthy] 104 | expect(value).toBeTruthy() 105 | ```js 106 | expect($1).toBeTruthy(); 107 | ``` 108 | 109 | #### [eundef] 110 | expect(value).toBeUndefined() 111 | ```js 112 | expect($1).toBeUndefined(); 113 | ``` 114 | 115 | #### [econ] 116 | expect(list).toContain(value) 117 | ```js 118 | expect($1).toContain($2); 119 | ``` 120 | 121 | #### [econeq] 122 | expect(list).toContainEqual(value) 123 | ```js 124 | expect($1).toContainEqual($2); 125 | ``` 126 | 127 | #### [eeq] 128 | expect(value).toEqual(value) 129 | ```js 130 | expect($1).toEqual($2); 131 | ``` 132 | 133 | #### [eleng] 134 | expect(list).toHaveLength(number) 135 | ```js 136 | expect($1).toHaveLength($2); 137 | ``` 138 | 139 | #### [emat] 140 | expect(string).toMatch(regexpOrString) 141 | ```js 142 | expect($1).toMatch($2); 143 | ``` 144 | 145 | #### [ematob] 146 | expect(obj).toMatchObject(obj) 147 | ```js 148 | expect($1).toMatchObject($2); 149 | ``` 150 | 151 | #### [ematsnap] 152 | expect(value).toMatchSnapshot(optionalString) 153 | ```js 154 | expect($1).toMatchSnapshot($2); 155 | ``` 156 | 157 | #### [ethrow] 158 | expect(func).toThrow(error) 159 | ```js 160 | expect($1).toThrow($2); 161 | ``` 162 | 163 | #### [desc] 164 | describe(name, fn) 165 | ```js 166 | describe('$1', () => { 167 | $2 168 | }); 169 | ``` 170 | 171 | #### [test] 172 | test(name, fn) 173 | ```js 174 | test('$1', () => { 175 | $2 176 | }); 177 | ``` 178 | 179 | #### [it] 180 | alias for test() 181 | ```js 182 | it('$1', () => { 183 | $2 184 | }); 185 | ``` 186 | 187 | #### [aftera] 188 | afterAll(fn) 189 | ```js 190 | afterAll(() => { 191 | $1 192 | }) 193 | ``` 194 | 195 | #### [aftere] 196 | afterEach(fn) 197 | ```js 198 | afterEach(() => { 199 | $1 200 | }) 201 | ``` 202 | 203 | #### [beforea] 204 | beforeAll(fn) 205 | ```js 206 | beforeAll(() => { 207 | $1 208 | }) 209 | ``` 210 | 211 | #### [beforee] 212 | beforeEach(fn) 213 | ```js 214 | beforeEach(() => { 215 | $1 216 | }) 217 | ``` 218 | 219 | #### [jcleartimers] 220 | ```js 221 | jest.clearAllTimers(); 222 | ``` 223 | 224 | #### [jdisableautomock] 225 | ```js 226 | jest.disableAutomock(); 227 | ``` 228 | 229 | #### [jenableautomock] 230 | ```js 231 | jest.enableAutomock(); 232 | ``` 233 | 234 | #### [jfn] 235 | ```js 236 | jest.fn($1); 237 | ``` 238 | 239 | #### [jismock] 240 | ```js 241 | jest.isMockFunction($1); 242 | ``` 243 | 244 | #### [jgenmock] 245 | ```js 246 | jest.genMockFromModule($1); 247 | ``` 248 | 249 | #### [jmock] 250 | ```js 251 | jest.mock($1); 252 | ``` 253 | 254 | #### [jresetallmocks] 255 | ```js 256 | jest.resetAllMocks(); 257 | ``` 258 | 259 | #### [jresetmodules] 260 | ```js 261 | jest.resetModules(); 262 | ``` 263 | 264 | #### [jrunticks] 265 | ```js 266 | jest.runAllTicks(); 267 | ``` 268 | 269 | #### [jruntimers] 270 | ```js 271 | jest.runAllTimers(); 272 | ``` 273 | 274 | #### [jrunpendtimers] 275 | ```js 276 | jest.runOnlyPendingTimers(); 277 | ``` 278 | 279 | #### [jsetmock] 280 | ```js 281 | jest.setMock($1); 282 | ``` 283 | 284 | #### [junmock] 285 | ```js 286 | jest.unmock($1); 287 | ``` 288 | 289 | #### [jfaketimers] 290 | ```js 291 | jest.useFakeTimers($1); 292 | ``` 293 | 294 | #### [jrealtimers] 295 | ```js 296 | jest.useRealTimers($1); 297 | ``` 298 | 299 | #### [mclear] 300 | ```js 301 | .mockClear(); 302 | ``` 303 | 304 | #### [mreset] 305 | ```js 306 | .mockReset(); 307 | ``` 308 | 309 | #### [mimpl] 310 | ```js 311 | .mockImplementation($1); 312 | ``` 313 | 314 | #### [mimplonce] 315 | ```js 316 | .mockImplementationOnce($1); 317 | ``` 318 | 319 | #### [mrett] 320 | ```js 321 | .mockReturnThis(); 322 | ``` 323 | 324 | #### [mretval] 325 | ```js 326 | .mockReturnValue($1); 327 | ``` 328 | 329 | #### [mretvalo] 330 | ```js 331 | .mockReturnValueOnce($1); 332 | ``` 333 | 334 | -------------------------------------------------------------------------------- /UltiSnips/javascript_jest.snippets: -------------------------------------------------------------------------------- 1 | priority -50 2 | 3 | ## EXPECT 4 | snippet exp "Jest - expect(value)" 5 | expect($1)$2; 6 | endsnippet 7 | 8 | snippet ebe "Jest - expect(value).toBe(value)" 9 | expect($1).toBe($2); 10 | endsnippet 11 | 12 | snippet ecall "Jest - expect(mockFn).toHaveBeenCalled()" 13 | expect($1).toHaveBeenCalled(); 14 | endsnippet 15 | 16 | snippet ecallt "Jest - expect(mockFn).toHaveBeenCalledTimes(number)" 17 | expect($1).toHaveBeenCalledTimes($2); 18 | endsnippet 19 | 20 | snippet ecallw "Jest - expect(mockFn).toHaveBeenCalledWith(arg1, arg2, ...)" 21 | expect($1).toHaveBeenCalledWith($2); 22 | endsnippet 23 | 24 | snippet ecloseto "Jest - expect(number).toBeCloseTo(number, numDigits)" 25 | expect($1).toBeCloseTo($2, $3); 26 | endsnippet 27 | 28 | snippet edef "Jest - expect(value).toBeDefined()" 29 | expect($1).toBeDefined(); 30 | endsnippet 31 | 32 | snippet efalsy "Jest - expect(value).toBeFalsy()" 33 | expect($1).toBeFalsy(); 34 | endsnippet 35 | 36 | snippet egreater "Jest - expect(number).toBeGreaterThan(number)" 37 | expect($1).toBeGreaterThan($2); 38 | endsnippet 39 | 40 | snippet egreateror "Jest - expect(number).toBeGreaterThanOrEqual(number)" 41 | expect($1).toBeGreaterThanOrEqual($2); 42 | endsnippet 43 | 44 | snippet eless "Jest - expect(number).toBeLessThan(number)" 45 | expect($1).toBeLessThan($2); 46 | endsnippet 47 | 48 | snippet elessor "Jest - expect(number).toBeLessThanOrEqual(number)" 49 | expect($1).toBeLessThanOrEqual($2); 50 | endsnippet 51 | 52 | snippet einst "Jest - expect(obj).toBeInstanceOf(Class)" 53 | expect($1).toBeInstanceOf($2); 54 | endsnippet 55 | 56 | snippet enull "Jest - expect(value).toBeNull()" 57 | expect($1).toBeNull(); 58 | endsnippet 59 | 60 | snippet etruthy "Jest - expect(value).toBeTruthy()" 61 | expect($1).toBeTruthy(); 62 | endsnippet 63 | 64 | snippet eundef "Jest - expect(value).toBeUndefined()" 65 | expect($1).toBeUndefined(); 66 | endsnippet 67 | 68 | snippet econ "Jest - expect(list).toContain(value)" 69 | expect($1).toContain($2); 70 | endsnippet 71 | 72 | snippet econeq "Jest - expect(list).toContainEqual(value)" 73 | expect($1).toContainEqual($2); 74 | endsnippet 75 | 76 | snippet eeq "Jest - expect(value).toEqual(value)" 77 | expect($1).toEqual($2); 78 | endsnippet 79 | 80 | snippet eleng "Jest - expect(list).toHaveLength(number)" 81 | expect($1).toHaveLength($2); 82 | endsnippet 83 | 84 | snippet emat "Jest - expect(string).toMatch(regexpOrString)" 85 | expect($1).toMatch($2); 86 | endsnippet 87 | 88 | snippet ematob "Jest - expect(obj).toMatchObject(obj)" 89 | expect($1).toMatchObject($2); 90 | endsnippet 91 | 92 | snippet ematsnap "Jest - expect(value).toMatchSnapshot(optionalString)" 93 | expect($1).toMatchSnapshot($2); 94 | endsnippet 95 | 96 | snippet ethrow "Jest - expect(func).toThrow(error)" 97 | expect($1).toThrow($2); 98 | endsnippet 99 | 100 | ## GLOBALS 101 | 102 | snippet jsetup "Jest - Sets up jest test file" 103 | import $1 from './$1'; 104 | describe('$1', () => { 105 | test('$2', () => { 106 | $3 107 | }); 108 | }); 109 | endsnippet 110 | 111 | snippet desc "Jest - describe(name, fn)" 112 | describe('$1', () => { 113 | ${VISUAL}$0 114 | }); 115 | endsnippet 116 | 117 | snippet test "Jest - test(name, fn)" 118 | test('$1', () => { 119 | $2 120 | }); 121 | endsnippet 122 | 123 | snippet it "Jest - alias for test()" 124 | it('$1', () => { 125 | $2 126 | }); 127 | endsnippet 128 | 129 | snippet aftera "Jest - afterAll(fn)" 130 | afterAll(() => { 131 | $1 132 | }); 133 | endsnippet 134 | 135 | snippet aftere "Jest - afterEach(fn)" 136 | afterEach(() => { 137 | $1 138 | }); 139 | endsnippet 140 | 141 | snippet beforea "Jest - beforeAll(fn)" 142 | beforeAll(() => { 143 | $1 144 | }); 145 | endsnippet 146 | 147 | snippet beforee "Jest - beforeEach(fn)" 148 | beforeEach(() => { 149 | $1 150 | }); 151 | endsnippet 152 | 153 | ## MOCK 154 | 155 | snippet mclear "Jest - .mockClear()" 156 | .mockClear(); 157 | endsnippet 158 | 159 | snippet mreset "Jest - .mockReset()" 160 | .mockReset(); 161 | endsnippet 162 | 163 | snippet mimpl "Jest - .mockImplementation(fn)" 164 | .mockImplementation($1); 165 | endsnippet 166 | 167 | snippet mimplonce "Jest - .mockImplementationOnce(fn)" 168 | .mockImplementationOnce($1); 169 | endsnippet 170 | 171 | snippet mrett "Jest - .mockReturnThis()" 172 | .mockReturnThis(); 173 | endsnippet 174 | 175 | snippet mretval "Jest - .mockReturnValue(value)" 176 | .mockReturnValue($1); 177 | endsnippet 178 | 179 | snippet mretvalo "Jest - .mockReturnValueOnce(value)" 180 | .mockReturnValueOnce($1); 181 | endsnippet 182 | 183 | ## JEST 184 | 185 | snippet jcleartimers "Jest - jest.clearAllTimers()" 186 | jest.clearAllTimers(); 187 | endsnippet 188 | 189 | snippet jdisableautomock "Jest - jest.disableAutomock()" 190 | jest.disableAutomock(); 191 | endsnippet 192 | 193 | snippet jenableautomock "Jest - jest.enableAutomock()" 194 | jest.enableAutomock(); 195 | endsnippet 196 | 197 | snippet jfn "Jest - jest.fn()" 198 | jest.fn($1); 199 | endsnippet 200 | 201 | snippet jismock "Jest - jest.isMockFunction(fn)" 202 | jest.isMockFunction($1); 203 | endsnippet 204 | 205 | snippet jgenmock "Jest - jest.genMockFromModule(moduleName)" 206 | jest.genMockFromModule($1); 207 | endsnippet 208 | 209 | snippet jmock "Jest - jest.mock(moduleName, factory, options)" 210 | jest.mock($1); 211 | endsnippet 212 | 213 | snippet jresetallmocks "Jest - jest.resetAllMocks()" 214 | jest.resetAllMocks(); 215 | endsnippet 216 | 217 | snippet jresetmodules "Jest - jest.resetModules()" 218 | jest.resetModules(); 219 | endsnippet 220 | 221 | snippet jrunticks "Jest - jest.runAllTicks()" 222 | jest.runAllTicks(); 223 | endsnippet 224 | 225 | snippet jruntimers "Jest - jest.runAllTimers()" 226 | jest.runAllTimers(); 227 | endsnippet 228 | 229 | snippet jrunpendtimers "Jest - jest.runOnlyPendingTimers()" 230 | jest.runOnlyPendingTimers(); 231 | endsnippet 232 | 233 | snippet jsetmock "Jest - jest.setMock(moduleName, moduleExports)" 234 | jest.setMock($1); 235 | endsnippet 236 | 237 | snippet junmock "Jest - jest.unmock(moduleName)" 238 | jest.unmock($1); 239 | endsnippet 240 | 241 | snippet jfaketimers "Jest - jest.useFakeTimers()" 242 | jest.useFakeTimers($1); 243 | endsnippet 244 | 245 | snippet jrealtimers "Jest - jest.useRealTimers()" 246 | jest.useRealTimers($1); 247 | endsnippet 248 | -------------------------------------------------------------------------------- /addon-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "vim-jest-snippets", 3 | "author" : "joaohkfaria", 4 | "maintainer" : "joaohkfaria", 5 | "repository" : {"type": "git", "url": "git@github.com:joaohkfaria/vim-jest-snippets.git"}, 6 | "dependencies" : { 7 | }, 8 | "description" : "Vim editor snippets for Jest." 9 | } 10 | -------------------------------------------------------------------------------- /autoload/vim_jest_snippets.vim: -------------------------------------------------------------------------------- 1 | " this is well known Filename found in snipmate (and the other engines), but 2 | " rewritten and documented :) 3 | " 4 | " optional arg1: string in which to replace '$1' by filename with extension 5 | " and path dropped. Defaults to $1 6 | " optional arg2: return this value if buffer has no filename 7 | " But why not use the template in this case, too? 8 | " Doesn't make sense to me 9 | fun! vim_snippets#Filename(...) 10 | let template = get(a:000, 0, "$1") 11 | let arg2 = get(a:000, 1, "") 12 | 13 | let basename = expand('%:t:r') 14 | 15 | if basename == '' 16 | return arg2 17 | else 18 | return substitute(template, '$1', basename, 'g') 19 | endif 20 | endf 21 | 22 | " original code: 23 | " fun! Filename(...) 24 | " let filename = expand('%:t:r') 25 | " if filename == '' | return a:0 == 2 ? a:2 : '' | endif 26 | " return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g') 27 | " endf 28 | 29 | --------------------------------------------------------------------------------