Unit testing helper function that converts hex colors to rgb colors
hex-to-rgb-jquery is a wrapper for onecolor that adjusts its response, so it matches the rgb format jQuery returns.
$ npm install hex-to-rgb-jquery --save-dev
Add the following script tag to your unit test runner.
<script src="../node_modules/hex-to-rgb-jquery/dist/hex-to-rgb.js"></script>
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Runner</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<!-- lib scripts -->
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<!-- hex-to-rgb script -->
<script src="../node_modules/hex-to-rgb-jquery/dist/hex-to-rgb.js"></script>
<!-- Mocha setup -->
<script type="text/javascript">
chai.should();
mocha.setup('bdd');
// Start the suite.
window.onload = function() {
mocha.run();
};
</script>
</head>
<body>
<div id="mocha"></div>
<div id="fixture"></div>
<!-- source code scripts -->
<!-- test scripts -->
</body>
</html>
Call the function in the test
window.hexToRgbJquery.hexToRgb('#fff');
Ex in context of a test:
var hexToRgb = window.hexToRgbJquery.hexToRgb;
describe('hex-to-rgb tests', function() {
context('when a hex value is passed', function() {
it('with all six characters a valid corresponding rgb value should be returned', function() {
hexToRgb('#f1f1f1').should.equal('rgb(241, 241, 241)');
});
});
});
Please see CONTRIBUTING.md.
Please see CHANGELOG.md.
Copyright (c) 2017-2020 Thomas Lindner. Licensed under the MIT license.