Last active
August 27, 2017 10:01
-
-
Save G100g/f5642567e73b3560802e4736bb163b59 to your computer and use it in GitHub Desktop.
Testing Private Functions: Basic
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
function createFunnyName(name) { | |
return `^^${name}^^`; | |
} | |
module.exports = { | |
createCat(name) { | |
return { | |
name: name, | |
funnyName: createFunnyName(name) | |
}; | |
} | |
}; |
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 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^^' } |
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 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