Skip to content

Instantly share code, notes, and snippets.

@G100g
Last active August 27, 2017 10:01
Show Gist options
  • Save G100g/f5642567e73b3560802e4736bb163b59 to your computer and use it in GitHub Desktop.
Save G100g/f5642567e73b3560802e4736bb163b59 to your computer and use it in GitHub Desktop.
Testing Private Functions: Basic
function createFunnyName(name) {
return `^^${name}^^`;
}
module.exports = {
createCat(name) {
return {
name: name,
funnyName: createFunnyName(name)
};
}
};
const catCreator = require('./modules/cats');
const zelda = catCreator.createCat('Zelda');
console.log(zelda); // { name: 'Zelda', funnyName: '^^Zelda^^' }
const frida = catCreator.createCat('Frida');
console.log(frida); // { name: 'Frida', funnyName: '^^Frida^^' }
const test = require("tape");
const catCreator = require("./modules/cats");
const name = "Zelda";
test("Should return an object", t => {
t.equal(typeof catCreator.createCat(name), "object");
t.end();
});
test("Cat name should be funny", t => {
const result = catCreator.createCat(name).funnyName;
t.equal(result, `^^${name}^^`, "Should contain ^^ before and after the name");
t.ok(result.indexOf(name) === 2, "Should contain the name");
t.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment