JS测试NodeJS的模块

JS测试NodeJS的模块

本文介绍了如何要求使用Intern JS测试NodeJS的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我通过以下用于测试NodeJS的intern.js测试(以下myfile.js执行require('xxxxxx'))得到错误Attempt to require unloaded module xxxxxx.

I'm getting the error Attempt to require unloaded module xxxxxx with the following intern.js test (myfile.js below does a require('xxxxxx')) for testing NodeJS.

define(function(require) {
  var bdd = require('intern!bdd');
  var myfile = require('../myfile.js');
  bdd.describe('the thing being tested', function() {
    bdd.it('do the test', function() {
      ...

目录结构为

intern.js
myfile.js
test
|-- test.js

如何正确要求文件?没有使用BDD测试界面执行此操作的示例.在如何从intern.js测试中加载node.js http模块有一些使用其他样式的示例.但不使用BDD.

How do I properly require a file? There's no examples on how to do it with the BDD test interface. There are examples of doing it with the other style like in How do I load the node.js http module from within an intern.js test? but that doesn't use BDD.

与我需要在intern.js文件中设置的属性有什么关系吗?

Does it have anything to do with properties I need to set in intern.js file?

推荐答案

require与任何Intern接口的工作原理相同.棘手的是,AMD的要求(您在上面的代码中使用的)与Node的要求(这是加载Node模块所需要的)不同.

require works the same with any of the Intern interfaces. The tricky part is that the AMD require (which you're using in the code above) is not the same as Node's require (which is what you need to use to load Node modules).

如果myfiles.js是节点模块,则需要使用Dojo的node插件来加载它,例如:

If myfiles.js is a node module, you'll need to use Dojo's node plugin to load it, like:

var myfile = require('intern/dojo/node!../myfile');

这篇关于如何要求使用Intern JS测试NodeJS的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:04