An unexpected error has occurred in the browser console: The character '@' is not valid

I recently made the decision to dive into learning about Unit Testing with JavaScript. To aid in this process, I started using both Mocha.js and Chai.js frameworks. I downloaded the latest versions of these frameworks onto my index.html from cdnjs.com. However, upon checking the Safari console, I noticed a syntax error as shown below:

Invalid character: '@'

https://i.stack.imgur.com/dSlU3.png

After some investigation, I suspect that the issue may lie either within the browser or in the remote file mocha.min.css. Any insights or suggestions would be greatly appreciated.

P.S. In case it helps, I have attached the files index.html, style.css, and test.js for reference below:

/*
* Description: This is a short BDD-test which checks pow() for working
* Mission: Just for study and fun!
*/

describe("Is working function pow()?", function() {

it("2 * 2 * 2 = 8", function() {
assert.equal(pow(2, 3), 8);
});

});
/*
* Description: No any important things..
* Mission: Created for index.html
*/

body {
background-color: #000;
color: #FFF;
font-family: "Open Sans", sans-serif;
}

.title {
text-align: center;
font-size: 72px;
/*margin-top: 300px;*/
}
<!DOCTYPE html>
<html>

<head>

<meta charset="UTF-8>
<title>JS TDD</title>
<link rel="stylesheet" type="text/css" href="style.css">

<!-- import mocha.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.min.css"></script>
<!-- customization mocha.js -->
<script>mocha.setup('bdd');</script>
<!-- import chai.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
<!-- customization chai.js (optional) -->
<script>
var assert = chai.assert;
</script>

</head>

<body>

<h1 class="title">Learn unit test!</h1>
<!-- script for test -->
<script>

function pow() {
return 8; // I am lier!
}

</script>

<!-- upload custom test -->
<script src="test.js"></script>
<!-- result of custom test -->
<div id="mocha"></div>
<!-- run mocha! -->
        <script>mocha.run();</script>

</body>
</html>

Answer №1

You have used the <script> tag to load a .css file like this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.min.css">
</script>

To properly load a .css file into the document, replace the <script> tag with a <link> tag that has the rel attribute set to stylesheet and the type attribute set to "text/css":

<link href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.min.css" 
  rel="stylesheet"/>

<!DOCTYPE html>
<html>

<head>

  <meta charset="UTF-8">
  <title>JS TDD</title>

  <!-- import mocha.js -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.js"></script>
  <link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.min.css" rel="stylesheet" />
  <!-- customization mocha.js -->
  <script>
    mocha.setup('bdd');
  </script>
  <!-- import chai.js -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
  <!-- customization chai.js (optional) -->
  <script>
    var assert = chai.assert;
  </script>
  <style>
    /*
* Description: No any important things..
* Mission: Created for index.html
*/
    body {
      background-color: #000;
      color: #FFF;
      font-family: "Open Sans", sans-serif;
    }
    .title {
      text-align: center;
      font-size: 72px;
      /*margin-top: 300px;*/
    }
  </style>

</head>

<body>

  <h1 class="title">Learn unit test!</h1>
  <!-- script for test -->
  <script>
    function pow() {
      return 8; // I am lier!
    }
  </script>

  <!--  upload custom test -->
  <script>
    /*
     * Description: This is a short BDD-test which checks pow() for working
     * Mission: Just for study and fun!
     */

    describe("Is working function pow()?", function() {

      it("2 * 2 * 2 = 8", function() {
        assert.equal(pow(2, 3), 8);
      });

    });
  </script>
  <!-- result of custom test -->
  <div id="mocha"></div>
  <!-- run mocha! -->
  <script>
    mocha.run();
  </script>

</body>

</html>

plnkr http://plnkr.co/edit/45vSloJPChBvgSc96DRB?p=preview

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determine the name of the time zone using JavaScript

Currently, I am developing a React application and facing an issue where the timezone is detected as 'Etc/GMT-1' instead of the desired format 'Africa/Bangui'. This problem seems to be specific to my machine as it persists even when usi ...

The Vue user object appears to be null in spite of being defined and clearly visible in the log output

There seems to be an issue with my function that utilizes a person's user name to retrieve the current User from the database. Initially, when I log the current user within the function, everything works perfectly. However, once I attempt to access it ...

Retry an Ajax request immediately after a timeout without having to wait for the full

I am attempting to resend an AJAX request every 5 seconds if there is an issue, but when I simulate an offline connection with Chrome, the AJAX request doesn't wait 5 seconds between each attempt and keeps getting called continuously. What could be c ...

The paintbrush is whimsically altering its style on the canvas

My checkerboard has a unique feature where hovering over a tile will highlight it in yellow. Surprisingly, this action also turns the game border and the last white checker's border yellow as well. What's puzzling is that I never specified for t ...

Adjusting the height of flex items to 100%

I'm currently diving into the world of flexbox by exploring various tutorials. Here's an example I created without utilizing Flex. Instead, I relied on float:left. Check out the example: https://jsfiddle.net/arhj8wxg/4/ I attempted to convert t ...

What is causing the jQuery functions to not be executed in sequence?

Whenever I click the Start button, my function is supposed to run a cycle for 10 iterations. Each iteration generates a number between 1 and 7, which then triggers a series of functions on different objects. The problem is that these functions are not runn ...

Angular.js filter issue: "Error: textProvider is not recognized provider"

I implemented a custom filter for my AngularJS project that is similar to the one in this fiddle http://jsfiddle.net/tUyyx/. myapp.filter('truncate',function(text,length){ var end = "..." text = text.replace(/\w\S*/g, function( ...

Issues encountered while optimizing JSON file in a ReactJS program

I'm struggling with utilizing Array.prototype.map() in Javascript Specifically, I'm reformatting a JSON file within my react app, which looks like: { "id": 1, "title": "Manage data in Docker", "description": "How to use v ...

Sending a Django form using AJAX and jQuery: A step-by-step guide

After researching various tutorials on django AJAX forms, I've found that each one offers a different method, but none of them seem simple. Being new to AJAX, I'm feeling a bit confused by the complexity involved. In my specific case, I have a m ...

JavaScript or jQuery for filtering table rows

I have limited experience with JavaScript and jQuery, but I am working with a table containing various entries. My goal is to implement a filtering system using a list on the left side of the table. Here is an example I put together: http://jsfiddle.net/B ...

Unable to save data in local storage

I'm enhancing an existing chrome extension while ensuring a consistent style. I am looking to implement a new feature, and I have written a script that saves the user's selection from the popup and sets a new popup based on that choice going forw ...

Retrieve the identifiers of various HTML elements and store them in an array

Within a div, there are multiple objects. I am trying to retrieve the IDs of all elements based on their class, knowing that the number of elements may vary. So far, my attempt has been: arr = $(".listitem #checkBox").hasClass('checkedItem').att ...

Tips for eliminating the border surrounding the entire table in Material-ui

Is there a way to edit a table in Material-ui without displaying it as a card? I'm looking to remove the border around the entire table, but I couldn't find any information on how to do that. Can someone help me out? Here is a link about the com ...

What is the correct way to invoke a static TypeScript class function in JavaScript?

Recently, I encountered a scenario where I have a TypeScript script called test.ts structured like this: class Foo { public static bar() { console.log("test"); } } The requirement was to call this TypeScript function from plain JavaScript ...

Curved divs display outlines on more compact dimensions

Check out this relevant Codesandbox There seems to be a recurring issue in my application where rounded divs display edges when they are of smaller sizes. Refer to the image below for a visual representation. What could be causing this problem and how can ...

HTML is being incorrectly rendered by the Express framework

Looking to Use HTML as View Engine in Express? After going through the link, I attempted to start my server with an index.html file on port 8001. However, it failed to render correctly and showed an error in the console: Server Started Error: SyntaxError ...

Passing JSON data from an ASP.NET controller to a view

My issue arises when a web page is loaded and triggers a controller action to retrieve data based on user selection. I am trying to return this data as a JSON object, but it appears as a single string within the HTML page. The basic structure of the contro ...

The Transformicons by Navicon featuring a stylish blue outline

While experimenting with the navicon from sara soueidan, I noticed a blue selector around the icons that I can't seem to get rid of. Is this something specific to the method used, or just a misunderstanding of jQuery? Here is the code snippet: http:/ ...

Using specific delimiters in Vue.js components when integrating with Django and Vue-loader

While working on my Django + Vue.js v3 app, I came across a helpful tool called vue3-sfc-loader. This allows me to easily render .vue files using Django, giving me the best of both worlds. The current setup allows Django to successfully render the .vue fil ...

Troubleshoot: Border problem within nested columns in Bootstrap

https://i.sstatic.net/RDWfp.png My layout is based on the bootstrap 4 grid system, as shown in the image above. The problem I'm facing is that the border at the bottom row is misaligned. I have four nested columns in the first and second rows, but on ...