I think, mocha does not recognise jQuery in the scope of my tests, because it tests plain JavaScript without a problem. I tried to require jQuery's full code in the beginning of the .js file with my tests, tried to manually define $ with
before(function() {/* some code */}), but I always get this ReferenceError: $ is not defined when I try to run my tests and there is jQuery code tested with some of them.
Any ideas of how do I fix this?
In docs:
Mocha runs in the browser. Every release of Mocha will have new builds
of ./mocha.js and ./mocha.css for use in the browser. To setup Mocha
for browser use all you have to do is include the script, stylesheet,
tell Mocha which interface you wish to use, and then run the tests. A
typical setup might look something like the following, where we call
mocha.setup('bdd') to use the BDD interface before loading the test
scripts, running them onload with mocha.run().
So you can include any scripts, but the first you include libs, like jQuery, then tests
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="jquery.js"></script>
<script src="expect.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test.array.js"></script>
<script src="test.object.js"></script>
<script src="test.xhr.js"></script>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
</script>
</body>
</html>
Related
I am getting this error
TypeError: Cannot read properties of undefined (reading 'UDFCompatibleDatafeed')
Import these two script in index.html /public folder
<script src="%PUBLIC_URL%/datafeeds/udf/dist/polyfills.js"></script>
<script src="%PUBLIC_URL%/datafeeds/udf/dist/bundle.js"></script>
i deleted my project and cloned their project and then i followed those mention steps then its run
i figured out the problem later
so in our on project i we missed two script in index.html then it will give this error on running so clone the project and then follow the mention step for your specific framework or library
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="%PUBLIC_URL%/datafeeds/udf/dist/polyfills.js"></script>
<script src="%PUBLIC_URL%/datafeeds/udf/dist/bundle.js"></script>
<title>Charting Library React Demo</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
Is it possible to run generated js test code in browser?
ScalaJS seems to generate following js files under target directory
(project-name)-test-fastopt.js
(project-name)-test-jsdeps.js
before running tests.
Is it possible to run these tests in browser e.g. using this type of html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>The Scala.js Experimental</title>
</head>
<body>
<!-- Include JavaScript dependencies -->
<script type="text/javascript" src="./sjsexp2/js/target/scala-2.11/sjsexp2js-test-jsdeps.js"></script>
<!-- Include Scala.js compiled code -->
<script type="text/javascript" src="./sjsexp2/js/target/scala-2.11/sjsexp2js-test-fastopt.js"></script>
<script type="text/javascript">
$(function(){
package.ClassName().mainFunction();
})
</script>
</body>
</html>
If yes then what should be in place of "package.ClassName().mainFunction();"?
I'm using uTest framework for testing.
There is a sbt plugin which provides a real browser environment for your tests using Selenium: https://github.com/scala-js/scala-js-env-selenium
I have a type script file and want to include angular.
I have the following throwing errors when compiling the typescript as angular is not included as a referenced file or anything:
app.ts
var app = angular.module('app', []);
index.html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script src="Scripts/angular.min.js"></script>
<link rel="stylesheet" href="app.css" type="text/css" />
</body>
</html>
Obviously it does not matter that my index.html file correctly states dependencies in order as the compiler has no idea where angular comes from.
How do i include the external files?
You have to declare angular variable to tell compiler something like angular will be presented at runtime. You can combine it together with downloading already existing declaration file from DefinitelyTyped github repository.
If you don't want to do that, you an just use this instead:
declare var angular:any;
But I highly recommend using DefinitelyTyped Angular.js declarations, and declarations for all other 3rd party libraries for that matter. You will get code completion support.
At the moment, I'm including all of my JavaScript files in the <head> part of my html.
<!DOCTYPE html>
<html data-ng-csp>
<head>
<!-- ... -->
<script src="js/lib/wiki2html.min.js"></script>
<script src="js/lib/es6-promise.min.js"></script>
<script src="js/lib/l10n.min.js"></script>
<script src="js/lib/angular.min.js"></script>
<script src="js/lib/angular-route.min.js"></script>
<script src="js/lib/angular-sanitize.min.js"></script>
<script src="js/lib/angular-touch.min.js"></script>
<script src="js/wrapper-indexeddb.js"></script>
<script src="js/wrapper-devicestorage.js"></script>
<script src="js/util.js"></script>
<script src="js/app.js"></script>
<script src="js/app-services.js"></script>
<script src="js/app-directives.js"></script>
<script src="js/app-controllers.js"></script>
</head>
<body data-ng-app="FireDict">
<!-- ... -->
</body>
</html>
I thought about using build and packaging tools together with tools like require.js or browserify, but most of my dependencies don't come as npm modules or as requirejs definitions. I have never used any js build tools before, but it seems to be a lot of work if not all of your dependencies come in the right modularized/packaged format.
What is the most elegant way to include AngularJS and the other scripts I'm using?
Some background: I'm authoring a webapp for Firefox OS based on AngularJS. (The problems about ngCsp that I previously described here were due to my ignorance of angular-csp.css. I simply forgot to include it.)
I would take a second look at RequireJS. With RequireJS not all of your packages need to be formatted as AMD modules. In the case where a dependency is not in the RequireJS (AMD) format you would instead use the shim configuration for those dependencies in your RequireJS configuration.
My problem is very much like the Hem on windows problem: Uncaught module jqueryify not found
I can't deploy my spine mobile app to a android mobile devise using phonegap, it works perfectly in a browser (linux) but whenever I run it through eclipse on a android devise (various versions tested) I recieve:
06-17 18:39:36.878: E/Web Console(5976): ReferenceError: Can't find variable: require at file:///android_asset/www/index.html:9
Which is referencing:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>App</title>
<link rel="stylesheet" href="/application.css" type="text/css" charset="utf-8">
<script src="/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var jQuery = require("jqueryify"); //REFERENCED LINE 9
var exports = this;
jQuery(function(){
var App = require("index");
exports.app = new App({el: $("body")});
});
</script>
</head>
<body>
</body>
</html>
I have installed the dependencies through npm and also built it using Hem, I'm kind of lost to what the problem might be.
Any ideas why this might be happening?
** EDIT **
The problem was the .js file was not being found, needed:
<script src="./application.js" type="text/javascript" charset="utf-8"></script>
NOTICE THE '.' in the javascript file src att.
The error specifically means that the require function is undefined when it executes your inline script. Since require isn't a built-in part of browser JavaScript, that means whatever code (presumably a module-loader library) should be providing it either isn't getting executed or is failing. Given your code, that would have to be somewhere in application.js.