I cannot import method from another JavaScript file.
I try both exporting single method or class from the file but still does not work. Basically i'm trying to learn Mocha so i try to create library so i can test the methods in Mocha but my exporting and importing dont seem to work. I run the script in Chrome browser.
file: myTest.js
function myTestClass(){
this.myTestText = "Welcome to myTestClass!";
this.mySum = function(a, b) {
return a + b;
}
this.mySubtraction = function(a,b) {
return a - b;
}
this.myMultiply = function(a, b) {
return a * b;
}
};
export default {myTestClass};
file: test.js
import myTestClass from 'myTest.js';
console.log("enter test.js file");
console.log("test.js finished importing myTest.js file");
file: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8">
<title>Mocha Tests</title>
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></id>
<div id="messages"></div>
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.js"></script>
<script type="module" class="mocha-init">
mocha.setup('bdd');
</script>
<script src="test.js"></script>
<script type="module">
mocha.run();
</script>
</body>
</html>
when I open index.html in Chorme, none of my window.alert() functions get called so from that, the error must have occurred. Please note that all of my files are in the same directory.