Created
June 28, 2020 17:58
-
-
Save KyleMit/81ebd52dde8437c92fcf3759351f1e2d to your computer and use it in GitHub Desktop.
parse-rgb w/ unit tests
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 = parseRGB | |
function parseRGB(string) { | |
return { | |
r: 255, | |
g: 255, | |
b: 255 | |
} | |
} |
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 IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "node", | |
"request": "launch", | |
"name": "Mocha Tests", | |
"program": "${workspaceRoot}/node_modules/mocha/bin/mocha", | |
"args": [ | |
"--inspect-brk", | |
"${workspaceFolder}/test/**/*.js" | |
], | |
"internalConsoleOptions": "openOnSessionStart", | |
"port": 9229, | |
"skipFiles": [ | |
"<node_internals>/**" | |
] | |
} | |
] | |
} |
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
{ | |
"name": "@ads-vdh/parse-rgb", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "mocha" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"mocha": "^8.0.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
var assert = require('assert'); | |
// what we're unit testing in this block is the RGB function | |
describe('parseRGB', function() { | |
it('should return {r,g,b}', function() { | |
// arrange | |
let fn = require("../index") | |
let input = "" // won't matter | |
// act | |
let actual = fn(input) | |
let rDefined = typeof actual.r !== "undefined" | |
let gDefined = typeof actual.g !== "undefined" | |
let bDefined = typeof actual.b !== "undefined" | |
let allDefined = rDefined && gDefined && bDefined | |
// assert | |
assert.equal(allDefined, true) | |
}) | |
it('should return {255,255,255} when passed #ffffff', function() { | |
// arrange | |
let fn = require("../index") | |
let input = "#ffffff" | |
let expected = { r: 255, g: 255, b: 255 } | |
// act | |
let actual = fn(input) | |
// assert | |
assert.deepEqual(actual, expected) | |
}) | |
it('should return {0,0,0} when passed #000000', function() { | |
// arrange | |
let fn = require("../index") | |
let input = "#000000" | |
let expected = { r: 0, g: 0, b: 0 } | |
// act | |
let actual = fn(input) | |
// assert | |
assert.deepEqual(actual, expected) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment