Skip to content

Instantly share code, notes, and snippets.

@felixjb
Created June 2, 2023 10:26
Show Gist options
  • Save felixjb/7d54800229064d2723c0534cf83a8fc8 to your computer and use it in GitHub Desktop.
Save felixjb/7d54800229064d2723c0534cf83a8fc8 to your computer and use it in GitHub Desktop.
A snippet collection for VSCode containing common hooks and functions of JavaScript testing frameworks
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
//
// general testing
"Expect With Log": {
"scope": "javascript,typescript",
"prefix": "expect log",
"description": "Console log response body on error",
"body": [".expect(res => res.status !== ${1:200} && console.log(res.body))"]
},
// Mocha snippets using BDD interface and TDD interfaces only
"Before Hook": {
"scope": "javascript,typescript",
"prefix": "before",
"body": [
"before(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Before Hook"
},
"Before Each Hook": {
"scope": "javascript,typescript",
"prefix": "beforeEach",
"body": [
"beforeEach(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Before Each Hook"
},
"After Hook": {
"scope": "javascript,typescript",
"prefix": "after",
"body": [
"after(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "After Hook"
},
"After Each Hook": {
"scope": "javascript,typescript",
"prefix": "afterEach",
"body": [
"afterEach(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "After Each Hook"
},
"Describe": {
"scope": "javascript,typescript",
"prefix": "describe",
"body": ["describe('${1:description}', () => {", "\t$0", "});"],
"description": "Describe"
},
"Context": {
"scope": "javascript,typescript",
"prefix": "context",
"body": ["context('${1:description}', () => {", "\t$0", "});"],
"description": "Context"
},
"It": {
"scope": "javascript,typescript",
"prefix": "it",
"body": ["it('${1:description}', ${2:async} () => {", "\t$0", "});"],
"description": "It"
},
"Specify": {
"scope": "javascript,typescript",
"prefix": "specify",
"body": ["specify('${1:description}', ${2:async} () => {", "\t$0", "});"],
"description": "Specify"
},
// Mocha snippets using TDD interface
"Suite Setup Hook": {
"scope": "javascript,typescript",
"prefix": "suiteSetup",
"body": [
"suiteSetup(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Suite Setup Hook"
},
"Suite Teardown Hook": {
"scope": "javascript,typescript",
"prefix": "suiteTeardown",
"body": [
"suiteTeardown(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Suite Teardown Hook"
},
"Setup Hook": {
"scope": "javascript,typescript",
"prefix": "setup",
"body": [
"setup(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Setup Hook"
},
"Teardown Hook": {
"scope": "javascript,typescript",
"prefix": "teardown",
"body": [
"teardown(${1:'${2:description}',} ${3:async} () => {",
"\t$0",
"});"
],
"description": "Teardown Hook"
},
"Suite": {
"scope": "javascript,typescript",
"prefix": "suite",
"body": ["suite('${1:description}', () => {", "\t$0", "});"],
"description": "Suite"
},
"Test": {
"scope": "javascript,typescript",
"prefix": "test",
"body": ["test('${1:description}', ${2:async} () => {", "\t$0", "});"],
"description": "Test"
},
// Mocha snippets compound snippets
"Skip or Only": {
"scope": "javascript,typescript",
"prefix": ["skip", "only"],
"body": [
"${2|describe,suite,it,specify,test|}.${1|skip,only|}('${3:description}', ${5:async} () => {",
"\t$0",
"});"
],
"description": "Skip or Only"
},
"Describe With It": {
"scope": "javascript,typescript",
"prefix": "describe-it",
"body": [
"describe('${1:description}', () => {",
"\tit('${3:description}', ${4:async} () => {",
"\t\t$0",
"\t});",
"});"
],
"description": "Describe With It"
},
"Context With It": {
"scope": "javascript,typescript",
"prefix": "context-it",
"body": [
"context('${1:description}', () => {",
"\tit('${3:description}', ${4:async} => () {",
"\t\t$0",
"\t});",
"});"
],
"description": "Context With It"
},
"Suite With Test": {
"scope": "javascript,typescript",
"prefix": "suite-test",
"body": [
"suite('${1:description}', () => {",
"\ttest('${3:description}', ${4:async} () => {",
"\t\t$0",
"\t});",
"});"
],
"description": "Suite With Test"
},
"BDD Suite": {
"scope": "javascript,typescript",
"prefix": "mocha-bdd",
"body": [
"${1|describe,context|}('${2:description}', () => {",
"\tbefore(${4:'${5:description}',} ${6:async} () => {",
"\t\t$8",
"\t});",
"\n",
"\tafter(${9:'${10:description}',} ${11:async} () => {",
"\t\t$13",
"\t});",
"\n",
"\t${14|it,specify|}('${15:description}', ${16:async} () => {",
"\t\t$0",
"\t});",
"});"
],
"description": "BDD Suite"
},
"TDD Suite": {
"scope": "javascript,typescript",
"prefix": "mocha-tdd",
"body": [
"suite('${1:description}', () => {",
"\tsetup(${3:'${4:description}',} ${5:async} () => {",
"\t\t$7",
"\t});",
"\n",
"\tteardown(${8:'${9:description}',} ${10:async} () => {",
"\t\t$12",
"\t});",
"\n",
"\ttest('${13:description}', ${14:async} () => {",
"\t\t$0",
"\t});",
"});"
],
"description": "TDD Suite"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment