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

Creating a dynamic select functionality in Drupal forms

Being more focused on backend development, I am facing a challenge that may be simple for jQuery experts. In Drupal, I have two arrays - one containing names of views and the other having displays for each view. To populate these arrays, here is the code s ...

Is it possible to modify the appearance or behavior of a button in a React application based on its current state?

I'm looking to customize the color of a button based on different states. For example, if the state is active, the button should appear in red; otherwise it should be blue. Can anyone suggest how this can be achieved in React? Furthermore, I would als ...

Every time I try to create a new React app, I consistently run into the same error

I keep encountering this error every time I try to create a React app using create-react-app. ...

I am in need of a JavaScript event that will take precedence over the CSS pointer

There is an image causing issues with scrolling on a mobile device because it's located in the finger-friendly area where people tend to scroll. I attempted to use pointer-events: null; to allow scrolling, but this also prevented the click event from ...

Exploring the JSON data received from PHP script via jQuery AJAX

In my program, I have created a web page with 5 radio buttons for selection. The goal is to change the picture displayed below the buttons each time a different button is chosen. However, I am encountering an issue during the JSON decoding phase after rec ...

What could be causing the problem with my CSS background-image being referenced correctly?

Everything seems to be in order: background-image: url(./dir/img.jpg); However, I encounter a 404 error when attempting to reference an image using this approach: index.html <div style="--url: url(./dir/img.jpg);"></div> css backg ...

Choose all checkboxes across the entire webpage

Given the code below: <input type="checkbox" name="categories[9507]"> Is there a way to write a JavaScript command that can automatically select all checkboxes with similar naming structures on the entire page? The only difference in the names is t ...

Exploring the nuances between Ruby on Rails and the responses from json and JavaScript ajax

I am interested in learning the most effective method for handling an ajax request. Would it be better to send json data and parse it on the client side (for instance using pure), or should I generate javascript at the server side and send back the respo ...

What are the best practices for managing certificates with Selenium?

I am currently utilizing Selenium to initiate a browser. What is the best approach for handling webpages (URLs) that prompt the browser to accept or deny a certificate? In the case of Firefox, I sometimes encounter websites that require me to accept their ...

Adjust the alignment of text within the <select> tag to the right in Safari browser

Is there a way to align text right in a select option tag? <select style="direction:rtl;text-align:right"> <option value="" selected="">همه</option> <option value="1">راهبر سيستم</option> <option v ...

Difficulty arises when Jest tests struggle to interpret basic HTML tags within a React Component

When running test runs, issues arise when using standard HTML tags with Jest. My setup includes Babel, Webpack, Jest, and React Testing Library. To enable jest, I have installed a number of packages: "@babel/plugin-proposal-class-properties": "7.8.3", "@ ...

Creating an HTML Table with Database Data utilizing JSP, Java, and JavaScript

Challenge: I am currently tasked with developing a web application for a university course using JSP, Java, Javascript, and JQuery without relying on any external frameworks or libraries. The main goal is to create a calendar-like table that displays cours ...

Performing JavaScript functions after fetching an XSLT page via AJAX

Is there a way to trigger JavaScript at a particular time without relying on setInterval() or onClick()? The issue I'm facing is that when I click to load an XSLT page using Ajax, the JavaScript within it does not execute even though it's writt ...

Update the image within the svg tag

I am attempting to modify a preexisting SVG element within an HTML document. Here is the current code: <svg class="logo" viewBox="0 0 435 67"> <!-- IMAGE DIMENSIONS --> <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#logo- ...

Does the Karma Tast Runner function on node js version 0.12.0?

I'm experiencing an issue where I have Node.js v0.12.0 installed with Karma on my OS X Yosemite, but when I try to run my test task using Gulp, it just hangs as shown in the picture. It seems like PhantomJS is not starting. Interestingly, the same cod ...

Simple steps to validate an ajax response with a specific string

I'm encountering a problem with a simple ajax call that involves checking the returned text against a string: // in my php file echo 'mystring'; // in my javascript if((request.readyState == 4) && (request.status == 200)){ if(req ...

Display Partial View in MVC 4 using ajax success callback

Issue: Unable to load view on ajax success. Situation: I have two cascaded dropdowns where the second dropdown's options are based on the selection of the first dropdown. Upon selecting an option in the second dropdown, I want to display a list of re ...

Accelerate blinking timer by utilizing CSS3 animations

I'm currently developing a quiz application that includes a timer counting down from 10 seconds to 0 seconds. As the timer reaches closer to 0 seconds, I am looking to implement a feature where my text blinks faster and faster. Additionally, I would l ...

Crafting CSS for styling input type file elements

My attempts to style the input type file with CSS have been unsuccessful. In my current code, the "choose file" button is displaying above my styled button. How can I use CSS to remove this? I am aiming to only display a blue colored button for uploading ...

Creating dynamic stylesheets with the help of PHP and JavaScript

Generating tooltips based on a dynamically changing background image in CSS is my goal. Within my file named my_css.php, I have implemented the following code: <?php header('content-type: text/css'); $i = $_GET['index']; ...