This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Ava Test Snippet": { | |
"prefix": "ava", | |
"body": [ | |
"import test from 'ava'", | |
"", | |
"import ${1} from '${2}'", | |
"", | |
"test('It exports a function', function (t) {", | |
" t.is(typeof ${3}, 'function')", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* source code file "myFunction.js" */ | |
export default myFunction(callback) { | |
return callback(10) | |
} | |
/* test file */ | |
import assert from 'assert' | |
import test from 'my-favorite-test-library' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assert from 'assert' | |
import test from 'my-favorite-test-library' | |
import functionality from './myFunctionality' | |
test('It exports a function', function () { | |
assert.strictEqual(typeof functionality, 'function') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { cork, uncork, wrap } = promiseFunnel() | |
const wrapped = wrap(function () { | |
return 'done!' | |
}) | |
cork() | |
// An unresolved promise is returned | |
const promise = wrapped().then(function (res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Promise from 'bluebird' | |
import createFunnel from 'promise-funnel' | |
const funnel = createFunnel({ | |
Promise, // promise-funnel will use Bluebird promises now | |
}) | |
// The usage is exactly the same as before after this! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import createFunnel from 'promise-funnel' | |
const funnel = createFunnel() | |
function fetchData(...options) { | |
// This will fail if the user is unauthenticated | |
return fetch(...options) | |
} | |
function login() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql from 'mysql' | |
import createFunnel from 'promise-funnel' | |
const funnel = createFunnel() | |
funnel.cork() | |
const connection = mysql.createConnection({ | |
/* options here */ | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test from 'ava'; | |
function doubleSay (str) { | |
return str + ", " + str; | |
} | |
function capitalize (str) { | |
return str[0].toUpperCase() + str.substring(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test from 'ava'; | |
test('Nullish coalescing defaults null', (t) => { | |
t.is(null ?? 'default', 'default'); | |
}); | |
test('Nullish coalescing defaults undefined', (t) => { | |
t.is(undefined ?? 'default', 'default'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let neighborCount = 0; | |
function getNextNeighbor(neighbors) { | |
return neighbors?.[++neighborCount]; | |
} | |
test('It short circuits expressions', (t) => { | |
const neighbors = getNeighbors(data); | |
t.is(getNextNeighbor(neighbors), 'jane doe'); | |
t.is(getNextNeighbor(undefined), undefined); |