Jasmine doesn't see my js file? ReferenceError: marsRover is not defined

Marsrover.js

var marsRover = function() {
    return 0;
};

MarsRoverSpec.js (this does not work)

describe("MarsRover Kata Tests", function() {
    it("has function named marsRover", function() {
        expect(marsRover()).toBe(0);
    });
});

The above code does not work: ReferenceError: marsRover is not defined

MarsRoverSpec.js (this works)

var marsRover = function() {
    return 0;
};

describe("MarsRover Kata Tests", function() {
    it("has function named marsRover", function() {
        expect(marsRover()).toBe(0);
    });
});

I assume that I need to include or require a JS file. What is the best or easiest way to do this?

HTML

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Jasmine Spec Runner v2.0.0</title>

  <link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0/jasmine_favicon.png">
  <link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0/jasmine.css">

  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>

  <!-- include source files here... -->
  <script type="text/javascript" src="../Mars Rover/src/MarsRover.js"></script>

  <!-- include spec files here... -->
  <script type="text/javascript" src="../Mars Rover/spec/MarsRoverSpec.js"></script>

</head>

<body>
</body>
</html> 
+4
source share
1 answer

I had a duplicate of the MarsRover.js file in the root directory of the application. I don't know why this was a problem, as I clearly indicate in the html js file in the src folder.

0
source

Source: https://habr.com/ru/post/1533033/


All Articles