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 getVat( quantity ) { | |
if ( typeof quantity === 'string' ) { | |
// Remove thousands separator. | |
quantity = quantity.replace( /\./g, '' ) | |
// Remove decimals separator. | |
quantity = quantity.replace( ',', '.' ) | |
// Remove currency. | |
quantity = quantity.replace( /[^0-9.]/g, '' ); | |
}//end if | |
return quantity * 0.21; | |
}//end getVat() |
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
QUnit.module( 'The function "getVat"', {}, function() { | |
QUnit.module( 'when the quantity is an integer', {}, function() { | |
QUnit.test( 'should return 21% of the given value', function( assert ) { | |
var result = getVat( 1000 ); | |
assert.equal( result, 210 ); | |
}); | |
}); | |
QUnit.module( 'when the quantity is a string', {}, function() { | |
QUnit.test( 'should accept values that use dot as the thousands separator and return 21% of the given value', function( assert ) { | |
var result = getVat( '1.000' ); | |
assert.equal( result, 210 ); | |
}); | |
QUnit.test( 'should accept values that use comma as the decimal separator and return 21% of the given value', function( assert ) { | |
var result = getVat( '100,00' ); | |
assert.equal( result, 21 ); | |
}); | |
// ... | |
}); | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>QUnit Example</title> | |
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.1.css"> | |
<script src="functions.js"></script> | |
</head> | |
<body> | |
<div id="qunit"></div> | |
<div id="qunit-fixture"></div> | |
<script src="https://code.jquery.com/qunit/qunit-2.0.1.js"></script> | |
<script src="tests.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment