如何连接 Node 和 Jasmine 文件之间的函数声明?
How to connect a function declaration between Node and Jasmine files?
在我的 pigLatin Jasmine 文件中,我试图让以下代码工作:
var pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = translate("apple");
expect(pigLatin.s).toEqual('appleay');
});
});
这是我的节点文件:
function translate(argument) {
return "appleay";
}
module.exports = {
translate
}
我认为这与间谍功能有关,但我对它的具体功能一头雾水。提前感谢您的帮助。
您的 pigLatin.js
文件仅导出函数 translate
,因此当您导入文件时,您将函数存储到变量 pigLatin
.
所以对于你的 describe
你会想要更像...
var translate = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = translate("apple"); // we imported the translate function
expect(s).toEqual('appleay'); // `s` is the result of the translation
});
});
模块导出的内容就是 require
函数返回的内容。
希望对您有所帮助!
多亏了布拉德,我才能够解决这个问题。这是固定的解决方案:
var pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = pigLatin.translate("apple");
expect(s).toEqual('appleay');
});
在我的 pigLatin Jasmine 文件中,我试图让以下代码工作:
var pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = translate("apple");
expect(pigLatin.s).toEqual('appleay');
});
});
这是我的节点文件:
function translate(argument) {
return "appleay";
}
module.exports = {
translate
}
我认为这与间谍功能有关,但我对它的具体功能一头雾水。提前感谢您的帮助。
您的 pigLatin.js
文件仅导出函数 translate
,因此当您导入文件时,您将函数存储到变量 pigLatin
.
所以对于你的 describe
你会想要更像...
var translate = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = translate("apple"); // we imported the translate function
expect(s).toEqual('appleay'); // `s` is the result of the translation
});
});
模块导出的内容就是 require
函数返回的内容。
希望对您有所帮助!
多亏了布拉德,我才能够解决这个问题。这是固定的解决方案:
var pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = pigLatin.translate("apple");
expect(s).toEqual('appleay');
});