Skip to content

Instantly share code, notes, and snippets.

@websoftwares
Created October 26, 2017 08:43
Show Gist options
  • Save websoftwares/10e92aaa95b4cf40703adb44afa8fb05 to your computer and use it in GitHub Desktop.
Save websoftwares/10e92aaa95b4cf40703adb44afa8fb05 to your computer and use it in GitHub Desktop.
webtask-function-with-context-model
module.exports = function (context, cb) {
cb(null, { hello_you: context.data.name || 'Anonymous' })
}
'use strict'
const tape = require('tape')
const functionWithContext = require('./function-with-context')
let contextMock = { data: { name: null } }
const cbSpy = (t, expected) => (error, actual) => {
t.equal(null, error, `Assert expected: null matches actual: ${error}`)
t.deepEqual(
expected,
actual,
`Assert expected: ${JSON.stringify(expected)} matches actual: ${JSON.stringify(actual)}`
)
}
tape('Function with context test cases', (t) => {
const names = ['Boris', 'Anonymous']
for (let i = 0; i < names.length; i++) {
let name = names[i] === 'Anonymous' ? null : names[i]
contextMock.data.name = name
functionWithContext(contextMock, cbSpy(t, { hello_you: names[i] }))
}
t.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment