├── .github └── workflows │ └── test.yaml ├── .gitignore ├── .prettierrc ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── RELEASE.md ├── images └── jest_snippets_icon.png ├── package-lock.json ├── package.json └── snippets ├── snippets.json └── snippets.test.js /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - uses: actions/setup-node@v3 11 | with: 12 | node-version: 16 13 | - run: npm ci 14 | - run: npm test 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100 3 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .gitignore 3 | node_modules/** -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | [Releases](https://github.com/andys8/vscode-jest-snippets/releases) 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 andys8 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 | # vscode-jest-snippets 2 | 3 | [![Version](https://img.shields.io/visual-studio-marketplace/v/andys8.jest-snippets?label=VS%20Marketplace&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=andys8.jest-snippets) 4 | [![Node CI](https://github.com/andys8/vscode-jest-snippets/actions/workflows/test.yaml/badge.svg)](https://github.com/andys8/vscode-jest-snippets/actions/workflows/test.yaml) 5 | 6 | [Jest](https://facebook.github.io/jest) snippets extension for [Visual Studio Code](https://code.visualstudio.com/). 7 | 8 | ## Snippets 9 | 10 | Below is a list of all available snippets and the triggers of each one. The **→** means the `TAB` key. 11 | 12 | ### Globals 13 | 14 | | Trigger | Content | 15 | | -------: | --------------------- | 16 | | `desc→` | describe | 17 | | `desco→` | describe.only | 18 | | `descs→` | describe.skip | 19 | | `desce→` | describe.each | 20 | | `ae→` | afterEach | 21 | | `aa→` | afterAll | 22 | | `be→` | beforeEach | 23 | | `bea→` | beforeEach(async ...) | 24 | | `ba→` | beforeAll | 25 | | `baa→` | beforeAll(async ...) | 26 | 27 | ### Tests 28 | 29 | | Trigger | Content | 30 | | --------: | -------------------- | 31 | | `it→` | it | 32 | | `ito→` | it.only | 33 | | `its→` | it.skip | 34 | | `itt→` | it.todo | 35 | | `ite→` | it.each | 36 | | `ita→` | it(..., async ...) | 37 | | `test→` | test | 38 | | `testo→` | test.only | 39 | | `tests→` | test.skip | 40 | | `testt→` | test.todo | 41 | | `teste→` | test.each | 42 | | `testet→` | test.each (table) | 43 | | `testa→` | test(..., async ...) | 44 | 45 | ### Expect 46 | 47 | | Trigger | Content | 48 | | --------: | ---------------------------------- | 49 | | `exp→` | expect | 50 | | `expr→` | expect.resolves | 51 | | `exprj→` | expect.rejects | 52 | | `expas→` | expect.assertions(count) | 53 | | `expha→` | expect.hasAssertions() | 54 | | `tb→` | toBe | 55 | | `tbct→` | toBeCloseTo | 56 | | `tbd→` | toBeDefined | 57 | | `tbf→` | toBeFalsy | 58 | | `tbgt→` | toBeGreaterThan | 59 | | `tbgte→` | toBeGreaterThanOrEqual | 60 | | `tbi→` | toBeInstanceOf | 61 | | `tblt→` | toBeLessThan | 62 | | `tblte→` | toBeLessThanOrEqual | 63 | | `tbn→` | toBeNull | 64 | | `tbt→` | toBeTruthy | 65 | | `tbu→` | toBeUndefined | 66 | | `tc→` | toContain | 67 | | `tce→` | toContainEqual | 68 | | `te→` | toEqual | 69 | | `tse→` | toStrictEqual | 70 | | `thbc→` | toHaveBeenCalled | 71 | | `thbct→` | toHaveBeenCalledTimes | 72 | | `thbcw→` | toHaveBeenCalledWith | 73 | | `thblcw→` | toHaveBeenLastCalledWith | 74 | | `thl→` | toHaveLength | 75 | | `thp→` | toHaveProperty | 76 | | `tm→` | toMatch | 77 | | `tmo→` | toMatchObject | 78 | | `tms→` | toMatchSnapshot | 79 | | `tmis→` | toMatchInlineSnapshot | 80 | | `tt→` | toThrow | 81 | | `tte→` | toThrowError | 82 | | `ttems→` | toThrowErrorMatchingSnapshot | 83 | | `ttemis→` | toThrowErrorMatchingInlineSnapshot | 84 | 85 | ### Templates 86 | 87 | | Trigger | Content | 88 | | ------: | ----------------------- | 89 | | `cut→` | test a class under test | 90 | | `jfn→` | jest.fn | 91 | 92 | ## Settings 93 | 94 | The `editor.snippetSuggestions` setting in vscode `settings.json` will show snippets on top of the suggestion list. 95 | 96 | ```json 97 | "editor.snippetSuggestions": "top" 98 | ``` 99 | 100 | ## Credits 101 | 102 | - Thanks to [xabikos](https://github.com/xabikos) for [vscode-jasmine](https://github.com/xabikos/vscode-jasmine) 103 | - Thanks to [martinlechner1](https://github.com/martinlechner1) for initial contributions 104 | - Thanks to all [contributors](https://github.com/andys8/vscode-jest-snippets/graphs/contributors) 105 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release 2 | 3 | ## Install `vsce` 4 | 5 | ```shell 6 | npm i -g vsce 7 | ``` 8 | 9 | ## Publish 10 | 11 | - Bump version in `package.json` via `npm version ` 12 | - Push changes including `--tags` 13 | - [Create release on github](https://github.com/andys8/vscode-jest-snippets/releases/new) 14 | - Run `npm run publish` or `vsce publish` 15 | 16 | ## Create a token 17 | 18 | 19 | with custom defined scope "Marketplace" 20 | 21 | ### Login 22 | 23 | - 24 | - Token needs organization: All accessible organizations 25 | 26 | ```shell 27 | vsce login andys8 28 | ``` 29 | -------------------------------------------------------------------------------- /images/jest_snippets_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andys8/vscode-jest-snippets/7acab5211eaa49d29189e223982991fa6d06c634/images/jest_snippets_icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest-snippets", 3 | "displayName": "Jest Snippets", 4 | "description": "Code snippets for testing framework Jest", 5 | "version": "1.9.1", 6 | "publisher": "andys8", 7 | "icon": "images/jest_snippets_icon.png", 8 | "license": "MIT", 9 | "scripts": { 10 | "format:sort-json": "sort-json snippets/snippets.json", 11 | "format:prettier": "prettier --write package.json *.md snippets/*", 12 | "format": "npm run format:sort-json && npm run format:prettier", 13 | "publish": "vsce publish", 14 | "test": "jest --ci", 15 | "test:watch": "jest --watch" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/andys8/vscode-jest-snippets" 20 | }, 21 | "engines": { 22 | "vscode": "^1.11.0" 23 | }, 24 | "categories": [ 25 | "Snippets" 26 | ], 27 | "galleryBanner": { 28 | "color": "#99424f", 29 | "theme": "light" 30 | }, 31 | "contributes": { 32 | "snippets": [ 33 | { 34 | "language": "javascript", 35 | "path": "./snippets/snippets.json" 36 | }, 37 | { 38 | "language": "javascriptreact", 39 | "path": "./snippets/snippets.json" 40 | }, 41 | { 42 | "language": "typescript", 43 | "path": "./snippets/snippets.json" 44 | }, 45 | { 46 | "language": "typescriptreact", 47 | "path": "./snippets/snippets.json" 48 | } 49 | ] 50 | }, 51 | "devDependencies": { 52 | "jest": "28.1.3", 53 | "prettier": "2.7.1", 54 | "sort-json": "^2.0.1", 55 | "vsce": "^2.10.0" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /snippets/snippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "afterAll": { 3 | "body": "afterAll(() => {\n\t$0\n});", 4 | "description": "afterAll function is called once after all specs", 5 | "prefix": "aa", 6 | "scope": "source.js" 7 | }, 8 | "afterEach": { 9 | "body": "afterEach(() => {\n\t$0\n});", 10 | "description": "afterEach function is called once after each spec", 11 | "prefix": "ae", 12 | "scope": "source.js" 13 | }, 14 | "beforeAll": { 15 | "body": "beforeAll(() => {\n\t$0\n});", 16 | "description": "beforeAll function is called once before all specs", 17 | "prefix": "ba", 18 | "scope": "source.js" 19 | }, 20 | "beforeAll:async": { 21 | "body": "beforeAll(async () => {\n\t$0\n});", 22 | "description": "beforeAll with async function is called once before all specs", 23 | "prefix": "baa", 24 | "scope": "source.js" 25 | }, 26 | "beforeEach": { 27 | "body": "beforeEach(() => {\n\t$0\n});", 28 | "description": "beforeEach function is called once before each spec", 29 | "prefix": "be", 30 | "scope": "source.js" 31 | }, 32 | "beforeEach:async": { 33 | "body": "beforeEach(async () => {\n\t$0\n});", 34 | "description": "beforeEach with async callback function is called once before each spec", 35 | "prefix": "bea", 36 | "scope": "source.js" 37 | }, 38 | "describe": { 39 | "body": "describe('${1:Name of the group}', () => {\n\t$0\n});", 40 | "description": "creates a describe block", 41 | "prefix": "desc", 42 | "scope": "source.js" 43 | }, 44 | "describe.each": { 45 | "body": [ 46 | "describe.each([${1:[1, 2], [2, 4]}])(", 47 | "\t'${2:double(%d)}',", 48 | "\t(${3:input, expected}) => {", 49 | "\t\ttest(`returns \\${expected}`, () => {", 50 | "\t\t\t${4:expect(double(input)).toBe(expected);}", 51 | "\t\t});", 52 | "\t}", 53 | ");" 54 | ], 55 | "description": "creates a describe block with different test data sets", 56 | "prefix": "desce", 57 | "scope": "source.js" 58 | }, 59 | "describe.only": { 60 | "body": "describe.only('${1:Name of the group}', () => {\n\t$0\n});", 61 | "description": "creates a describe block that runs only", 62 | "prefix": "desco", 63 | "scope": "source.js" 64 | }, 65 | "describe.skip": { 66 | "body": "describe.skip('${1:Name of the group}', () => {\n\t$0\n});", 67 | "description": "creates a describe block that will be skipped", 68 | "prefix": "descs", 69 | "scope": "source.js" 70 | }, 71 | "expect": { 72 | "body": "expect($0)", 73 | "description": "expect actual value", 74 | "prefix": "exp", 75 | "scope": "source.js" 76 | }, 77 | "expect.assertions": { 78 | "body": "expect.assertions($0);", 79 | "description": "expects the test to make the indicated number of assertions (useful for async)", 80 | "prefix": "expas", 81 | "scope": "source.js" 82 | }, 83 | "expect.hasAssertions": { 84 | "body": "expect.hasAssertions();$0", 85 | "description": "expects the test to make at least one assertion (useful for async)", 86 | "prefix": "expha", 87 | "scope": "source.js" 88 | }, 89 | "expect.rejects": { 90 | "body": "expect($1).rejects$0", 91 | "description": "expect promise rejects to", 92 | "prefix": "exprj", 93 | "scope": "source.js" 94 | }, 95 | "expect.resolves": { 96 | "body": "expect($1).resolves$0", 97 | "description": "expect promise resolves to", 98 | "prefix": "expr", 99 | "scope": "source.js" 100 | }, 101 | "it": { 102 | "body": "it('${1:should }', () => {\n\t$0\n});", 103 | "description": "creates an it block", 104 | "prefix": "it", 105 | "scope": "source.js" 106 | }, 107 | "it.each": { 108 | "body": [ 109 | "it.each([${1:[1, 2], [2, 4]}])(", 110 | "\t'${2:double(%d)}',", 111 | "\t(${3:input, expected}) => {", 112 | "\t\t${0:expect(double(input)).toBe(expected);}", 113 | "\t}", 114 | ");" 115 | ], 116 | "description": "creates an it block with different test data sets", 117 | "prefix": "ite", 118 | "scope": "source.js" 119 | }, 120 | "it.only": { 121 | "body": "it.only('${1:should }', () => {\n\t$0\n});", 122 | "description": "creates an it block that runs only", 123 | "prefix": "ito", 124 | "scope": "source.js" 125 | }, 126 | "it.skip": { 127 | "body": "it.skip('${1:should }', () => {\n\t$0\n});", 128 | "description": "creates an it block that will be skipped", 129 | "prefix": "its", 130 | "scope": "source.js" 131 | }, 132 | "it.todo": { 133 | "body": "it.todo('${1:should }');", 134 | "description": "creates a test placeholder", 135 | "prefix": "itt", 136 | "scope": "source.js" 137 | }, 138 | "it:async": { 139 | "body": "it('${1:should }', async () => {\n\t$0\n});", 140 | "description": "creates an it block with async callback function", 141 | "prefix": "ita", 142 | "scope": "source.js" 143 | }, 144 | "jest.fn": { 145 | "body": "jest.fn($0)", 146 | "description": "creates jest.fn()", 147 | "prefix": "jfn", 148 | "scope": "source.js" 149 | }, 150 | "template:cut": { 151 | "body": [ 152 | "describe('${1:Name of the group}', () => {\n", 153 | "\tlet ${2:cut};\n", 154 | "\tbeforeEach(() => {\n\t\t$2 = $3;\n\t});\n", 155 | "\ttest('${1:should }', () => {", 156 | "\t\texpect($2).toBe($0);", 157 | "\t});\n", 158 | "});" 159 | ], 160 | "description": "creates a template to test a class under test", 161 | "prefix": "cut", 162 | "scope": "source.js" 163 | }, 164 | "test": { 165 | "body": "test('${1:should }', () => {\n\t$0\n});", 166 | "description": "creates a test block", 167 | "prefix": "test", 168 | "scope": "source.js" 169 | }, 170 | "test.each": { 171 | "body": [ 172 | "test.each([${1:[1, 2], [2, 4]}])(", 173 | "\t'${2:double(%d)}',", 174 | "\t(${3:input, expected}) => {", 175 | "\t\t${0:expect(double(input)).toBe(expected);}", 176 | "\t}", 177 | ");" 178 | ], 179 | "description": "creates an test block with different test data sets", 180 | "prefix": "teste", 181 | "scope": "source.js" 182 | }, 183 | "test.each (table)": { 184 | "body": [ 185 | "test.each`", 186 | "\t${1:input}\t| ${2:expected}", 187 | "\t\\${1}\t| \\${2}", 188 | "\t\\${2}\t| \\${4}", 189 | "`('${3:double($${1:input})}', ({ ${1:input}, ${2:expected} }) => {", 190 | "\t${0:expect(double(${1:input})).toBe(${2:expected});}", 191 | "});" 192 | ], 193 | "description": "creates a test block using a permutation table", 194 | "prefix": "testet", 195 | "scope": "source.js" 196 | }, 197 | "test.only": { 198 | "body": "test.only('${1:should }', () => {\n\t$0\n});", 199 | "description": "creates a test block that runs only", 200 | "prefix": "testo", 201 | "scope": "source.js" 202 | }, 203 | "test.skip": { 204 | "body": "test.skip('${1:should }', () => {\n\t$0\n});", 205 | "description": "creates a test block that will be skipped", 206 | "prefix": "tests", 207 | "scope": "source.js" 208 | }, 209 | "test.todo": { 210 | "body": "test.todo('${1:should }');", 211 | "description": "creates a test placeholder", 212 | "prefix": "testt", 213 | "scope": "source.js" 214 | }, 215 | "test:async": { 216 | "body": "test('${1:should }', async () => {\n\t$0\n});", 217 | "description": "creates an test block with async callback function", 218 | "prefix": "testa", 219 | "scope": "source.js" 220 | }, 221 | "toBe": { 222 | "body": "expect($1).toBe($2);$0", 223 | "description": "expects the first argument to be equal with the second one", 224 | "prefix": "tb", 225 | "scope": "source.js" 226 | }, 227 | "toBeCloseTo": { 228 | "body": "expect($1).toBeCloseTo(${2:number}, ${3:delta});$0", 229 | "description": "expects the first argument to be close to the second one base on the delta", 230 | "prefix": "tbct", 231 | "scope": "source.js" 232 | }, 233 | "toBeDefined": { 234 | "body": "expect($1).toBeDefined();$0", 235 | "description": "expects the argument is defined", 236 | "prefix": "tbd", 237 | "scope": "source.js" 238 | }, 239 | "toBeFalsy": { 240 | "body": "expect($1).toBeFalsy();$0", 241 | "description": "expects the argument is falsy", 242 | "prefix": "tbf", 243 | "scope": "source.js" 244 | }, 245 | "toBeGreaterThan": { 246 | "body": "expect($1).toBeGreaterThan($2);$0", 247 | "description": "expects the argument is greater than or equal", 248 | "prefix": "tbgt", 249 | "scope": "source.js" 250 | }, 251 | "toBeGreaterThanOrEqual": { 252 | "body": "expect($1).toBeGreaterThanOrEqual($2);$0", 253 | "description": "expects the argument is greater than", 254 | "prefix": "tbgte", 255 | "scope": "source.js" 256 | }, 257 | "toBeInstanceOf": { 258 | "body": "expect($1).toBeInstanceOf($2);$0", 259 | "description": "expects the argument is less than", 260 | "prefix": "tbi", 261 | "scope": "source.js" 262 | }, 263 | "toBeLessThan": { 264 | "body": "expect($1).toBeLessThan($2);$0", 265 | "description": "expects the argument is less than", 266 | "prefix": "tblt", 267 | "scope": "source.js" 268 | }, 269 | "toBeLessThanOrEqual": { 270 | "body": "expect($1).toBeLessThanOrEqual($2);$0", 271 | "description": "expects the argument is less than or equal", 272 | "prefix": "tblte", 273 | "scope": "source.js" 274 | }, 275 | "toBeNull": { 276 | "body": "expect($1).toBeNull();$0", 277 | "description": "expects the argument is null", 278 | "prefix": "tbn", 279 | "scope": "source.js" 280 | }, 281 | "toBeTruthy": { 282 | "body": "expect($1).toBeTruthy();$0", 283 | "description": "expects the argument is truthy", 284 | "prefix": "tbt", 285 | "scope": "source.js" 286 | }, 287 | "toBeUndefined": { 288 | "body": "expect($1).toBeUndefined();$0", 289 | "description": "expects the argument is undefined", 290 | "prefix": "tbu", 291 | "scope": "source.js" 292 | }, 293 | "toContain": { 294 | "body": "expect(${1:list}).toContain($2);$0", 295 | "description": "expects the list contains the item (===)", 296 | "prefix": "tc", 297 | "scope": "source.js" 298 | }, 299 | "toContainEqual": { 300 | "body": "expect(${1:list}).toContainEqual($2);$0", 301 | "description": "expects the list contains the item (equals)", 302 | "prefix": "tce", 303 | "scope": "source.js" 304 | }, 305 | "toEqual": { 306 | "body": "expect($1).toEqual($2);$0", 307 | "description": "expects the first argument to be equal with the second one", 308 | "prefix": "te", 309 | "scope": "source.js" 310 | }, 311 | "toHaveBeenCalled": { 312 | "body": "expect($1).toHaveBeenCalled();$0", 313 | "description": "returns true if the spy was called", 314 | "prefix": "thbc", 315 | "scope": "source.js" 316 | }, 317 | "toHaveBeenCalledTimes": { 318 | "body": "expect($1).toHaveBeenCalledTimes($2);$0", 319 | "description": "returns true if the spy has been called given times", 320 | "prefix": "thbct", 321 | "scope": "source.js" 322 | }, 323 | "toHaveBeenCalledWith": { 324 | "body": "expect($1).toHaveBeenCalledWith($2);$0", 325 | "description": "returns true if the spy has been called with", 326 | "prefix": "thbcw", 327 | "scope": "source.js" 328 | }, 329 | "toHaveBeenLastCalledWith": { 330 | "body": "expect($1).toHaveBeenLastCalledWith($2);$0", 331 | "description": "returns true if the spy has been last called with", 332 | "prefix": "thblcw", 333 | "scope": "source.js" 334 | }, 335 | "toHaveLength": { 336 | "body": "expect($1).toHaveLength($2);$0", 337 | "description": "expects the object to have length", 338 | "prefix": "thl", 339 | "scope": "source.js" 340 | }, 341 | "toHaveProperty": { 342 | "body": "expect($1).toHaveProperty(${2:keyPath}, ${3:value});$0", 343 | "description": "returns true if the argument matches the second object", 344 | "prefix": "thp", 345 | "scope": "source.js" 346 | }, 347 | "toMatch": { 348 | "body": "expect($1).toMatch($2);$0", 349 | "description": "returns true if the argument matches the second value", 350 | "prefix": "tm", 351 | "scope": "source.js" 352 | }, 353 | "toMatchInlineSnapshot": { 354 | "body": "expect($1).toMatchInlineSnapshot($2);$0", 355 | "description": "returns true if the argument matches the most recent inline snapshot", 356 | "prefix": "tmis", 357 | "scope": "source.js" 358 | }, 359 | "toMatchObject": { 360 | "body": "expect($1).toMatchObject($2);$0", 361 | "description": "returns true if the argument matches the second object", 362 | "prefix": "tmo", 363 | "scope": "source.js" 364 | }, 365 | "toMatchSnapshot": { 366 | "body": "expect($1).toMatchSnapshot($2);$0", 367 | "description": "returns true if the argument matches the most recent snapshot", 368 | "prefix": "tms", 369 | "scope": "source.js" 370 | }, 371 | "toStrictEqual": { 372 | "body": "expect($1).toStrictEqual($2);$0", 373 | "description": "expects the first argument to be strictly equal with the second one", 374 | "prefix": "tse", 375 | "scope": "source.js" 376 | }, 377 | "toThrow": { 378 | "body": "expect(() => {\n\t$0\n}).toThrow($1);", 379 | "description": "expects that the method will throw an error", 380 | "prefix": "tt", 381 | "scope": "source.js" 382 | }, 383 | "toThrowError": { 384 | "body": "expect(() => {\n\t$0\n}).toThrowError($1);", 385 | "description": "expects that the method will throw an error", 386 | "prefix": "tte", 387 | "scope": "source.js" 388 | }, 389 | "toThrowErrorMatchingInlineSnapshot": { 390 | "body": "expect(() => {\n\t$0\n}).toThrowErrorMatchingInlineSnapshot();", 391 | "description": "expects that the method will throw an error matching the inline snapshot", 392 | "prefix": "ttemis", 393 | "scope": "source.js" 394 | }, 395 | "toThrowErrorMatchingSnapshot": { 396 | "body": "expect(() => {\n\t$0\n}).toThrowErrorMatchingSnapshot();", 397 | "description": "expects that the method will throw an error mathing the snapshpot", 398 | "prefix": "ttems", 399 | "scope": "source.js" 400 | } 401 | } 402 | -------------------------------------------------------------------------------- /snippets/snippets.test.js: -------------------------------------------------------------------------------- 1 | const snippets = require("./snippets.json"); 2 | 3 | const unique = (xs) => [...new Set(xs)]; 4 | 5 | describe("snippets.json", () => { 6 | it("has entries", () => { 7 | expect(Object.keys(snippets).length).toBeGreaterThan(0); 8 | }); 9 | 10 | it("is sorted by key", () => { 11 | const keys = Object.keys(snippets); 12 | const sortedKeys = [...keys].sort(); 13 | expect(keys).toEqual(sortedKeys); 14 | }); 15 | 16 | it("has unique prefixes", () => { 17 | const prefixes = Object.values(snippets).map((x) => x.prefix); 18 | expect(prefixes).toEqual(unique(prefixes)); 19 | }); 20 | 21 | describe.each(Object.keys(snippets))("%s", (k) => { 22 | it("has prefix", () => { 23 | const { prefix } = snippets[k]; 24 | expect(prefix).toBeDefined(); 25 | expect(prefix).not.toEqual(""); 26 | }); 27 | 28 | it("has body", () => { 29 | const { body } = snippets[k]; 30 | expect(body).toBeDefined(); 31 | expect(body).not.toEqual(""); 32 | }); 33 | 34 | it("has description", () => { 35 | const { description } = snippets[k]; 36 | expect(description).toBeDefined(); 37 | expect(description).not.toEqual(""); 38 | }); 39 | }); 40 | }); 41 | --------------------------------------------------------------------------------