Created
October 26, 2017 08:43
-
-
Save websoftwares/10e92aaa95b4cf40703adb44afa8fb05 to your computer and use it in GitHub Desktop.
webtask-function-with-context-model
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
module.exports = function (context, cb) { | |
cb(null, { hello_you: context.data.name || 'Anonymous' }) | |
} |
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
'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