最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Testing with Mocha and requirejs - Stack Overflow

programmeradmin1浏览0评论

Im trying to get a testing environment for JavaScript set up but I am having some trouble with Mocha and requirejs. So far I have installed Mocha and that works as it should because I have tested it with the sample test from the documentation. The problem arises when I try and require some of the modules I want to test. At the top of my test.js file I have this:

var assert = require("assert"),
door = require( '../../assets/scripts/modules/door' );

But i get this error message in the console.

ReferenceError: define is not defined

Its referring to the first line of the door.js file that is.

define(['../utils/templating/hogan', '../models/ApiCaller', 'Backbone'], function (hogan, ApiCaller) {

I have also tried requiring requirejs like so...

var assert = require("assert"),
requirejs = require( '../../assets/scripts/require' ),
door = require( '../../assets/scripts/modules/door' );

As you have probably guessed im new to testing JavaScript and any explanation or solution would be great.

Thanks.

Im trying to get a testing environment for JavaScript set up but I am having some trouble with Mocha and requirejs. So far I have installed Mocha and that works as it should because I have tested it with the sample test from the documentation. The problem arises when I try and require some of the modules I want to test. At the top of my test.js file I have this:

var assert = require("assert"),
door = require( '../../assets/scripts/modules/door' );

But i get this error message in the console.

ReferenceError: define is not defined

Its referring to the first line of the door.js file that is.

define(['../utils/templating/hogan', '../models/ApiCaller', 'Backbone'], function (hogan, ApiCaller) {

I have also tried requiring requirejs like so...

var assert = require("assert"),
requirejs = require( '../../assets/scripts/require' ),
door = require( '../../assets/scripts/modules/door' );

As you have probably guessed im new to testing JavaScript and any explanation or solution would be great.

Thanks.

Share Improve this question asked Jun 28, 2013 at 14:08 David JonesDavid Jones 4,3057 gold badges30 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

See if this gist https://gist.github./michaelcox/3800736 is helpful for you.

发布评论

评论列表(0)

  1. 暂无评论