bdd mocha test method
This commit is contained in:
parent
1662f15f21
commit
b8e26c7703
46
3.5mocha/index.html
Normal file
46
3.5mocha/index.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- add mocha css, to show results -->
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
|
||||||
|
<!-- add mocha framework code -->
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
|
||||||
|
<script>
|
||||||
|
mocha.setup('bdd'); // minimal setup
|
||||||
|
</script>
|
||||||
|
<!-- add chai -->
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
|
||||||
|
<script>
|
||||||
|
// chai has a lot of stuff, let's make assert global
|
||||||
|
let assert = chai.assert;
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function pow(x, n) {
|
||||||
|
/* function code is to be written, empty now */
|
||||||
|
let result = 1;
|
||||||
|
|
||||||
|
for(let i = 0; i < n; i++){
|
||||||
|
result = result * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- the script with tests (describe, it...) -->
|
||||||
|
<script src="test.js"></script>
|
||||||
|
|
||||||
|
<!-- the element with id="mocha" will contain test results -->
|
||||||
|
<div id="mocha"></div>
|
||||||
|
|
||||||
|
<!-- run tests! -->
|
||||||
|
<script>
|
||||||
|
mocha.run();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
16
3.5mocha/test.js
Normal file
16
3.5mocha/test.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
describe("pow", function(){
|
||||||
|
it("calculate the pow of the number", function(){
|
||||||
|
assert.equal(pow(2, 3), 8);
|
||||||
|
})
|
||||||
|
|
||||||
|
function maketest(x){
|
||||||
|
let expected = x * x * x;
|
||||||
|
it(`calculate ${x}^3`, function(){
|
||||||
|
assert.equal(pow(x, 3), expected);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 1; i < 5; i++){
|
||||||
|
maketest(i);
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user