草庐IT

Test_stub

全部标签

node.js - 在 mocha 中使用 sinon 创建请求 stub

我正在使用mocha来测试一些类,我需要创建一个request库的stub。我正在使用sinon,我能够创建request.get方法的stub,但我无法创建request方法(http调用尝试连接到服务器)。正如我所读到的,request.get是request的别名,但是当我stubrequest.get它对request没有影响调用。此代码有效(使用request.get):在测试中:request=require'request'describe"Usertest",->user={}before(done)->user=newtest.user('Ander',18)sino

node.js - 在 mocha 中使用 sinon 创建请求 stub

我正在使用mocha来测试一些类,我需要创建一个request库的stub。我正在使用sinon,我能够创建request.get方法的stub,但我无法创建request方法(http调用尝试连接到服务器)。正如我所读到的,request.get是request的别名,但是当我stubrequest.get它对request没有影响调用。此代码有效(使用request.get):在测试中:request=require'request'describe"Usertest",->user={}before(done)->user=newtest.user('Ander',18)sino

node.js - "npm"如何运行 "npm test"?

我一直认为npmtest命令只是启动我将在scripts:{test:...}中的package.json中编写的内容>部分。但是当它不起作用时,我会遇到这个奇怪的错误。所以,我在package.json中有这段配置"scripts":{"start":"nodeindex.js","test":"mochatests/spec.js"}当我尝试运行测试时,我在终端中输入npmtest并出现以下错误:module.js:340throwerr;^Error:Cannotfindmodule'commander'但是当我只输入mochatests/spec.js时一切正常。任何想法为什么

node.js - "npm"如何运行 "npm test"?

我一直认为npmtest命令只是启动我将在scripts:{test:...}中的package.json中编写的内容>部分。但是当它不起作用时,我会遇到这个奇怪的错误。所以,我在package.json中有这段配置"scripts":{"start":"nodeindex.js","test":"mochatests/spec.js"}当我尝试运行测试时,我在终端中输入npmtest并出现以下错误:module.js:340throwerr;^Error:Cannotfindmodule'commander'但是当我只输入mochatests/spec.js时一切正常。任何想法为什么

javascript - 如何在测试期间 stub node.js 内置 fs?

我想对fs之类的node.js内置插件stub,这样我实际上就不会进行任何系统级文件调用。我唯一能想到的就是将fs和所有其他内置函数作为参数传递给我的所有函数,以避免使用真正的fs。这似乎有点傻,并创建了一个冗长的函数签名,其中包含作为参数的内置函数。varfs=require('fs');functionfindFile(path,callback){_findFile(fs,path,callback);}function_findFile(fs,path,callback){fs.readdir(path,function(err,files){//Dosomething.});

javascript - 如何在测试期间 stub node.js 内置 fs?

我想对fs之类的node.js内置插件stub,这样我实际上就不会进行任何系统级文件调用。我唯一能想到的就是将fs和所有其他内置函数作为参数传递给我的所有函数,以避免使用真正的fs。这似乎有点傻,并创建了一个冗长的函数签名,其中包含作为参数的内置函数。varfs=require('fs');functionfindFile(path,callback){_findFile(fs,path,callback);}function_findFile(fs,path,callback){fs.readdir(path,function(err,files){//Dosomething.});

javascript - 何时使用 Meteor.methods 和使用 stub

使用Meteor,我试图了解何时使用服务器端Meteor.methods(),同时仍保留即时UI更新。来自AndrewScala的introductorytutorial,他声称Meteor.methods()应该在您想要更新和修改数据库文档时使用:Theideaisthatyoudefineallthefunctionsontheserverthatdodangerousstufflikemodifyandupdatedata,andthenlettheclientcallthosefunctionsandgetreturnvalueslikeregularfunctions.The

javascript - 何时使用 Meteor.methods 和使用 stub

使用Meteor,我试图了解何时使用服务器端Meteor.methods(),同时仍保留即时UI更新。来自AndrewScala的introductorytutorial,他声称Meteor.methods()应该在您想要更新和修改数据库文档时使用:Theideaisthatyoudefineallthefunctionsontheserverthatdodangerousstufflikemodifyandupdatedata,andthenlettheclientcallthosefunctionsandgetreturnvalueslikeregularfunctions.The

javascript - Angular 2 Karma Test 'component-name' 不是已知元素

在AppComponent中,我在HTML代码中使用了导航组件。用户界面看起来不错。执行ngserve时没有错误。当我查看应用程序时,控制台中没有错误。但是当我为我的项目运行Karma时,出现了错误:Failed:Templateparseerrors:'app-nav'isnotaknownelement:1.If'app-nav'isanAngularcomponent,thenverifythatitispartofthismodule.2.If'app-nav'isaWebComponentthenadd'CUSTOM_ELEMENTS_SCHEMA'tothe'@NgModu

javascript - Angular 2 Karma Test 'component-name' 不是已知元素

在AppComponent中,我在HTML代码中使用了导航组件。用户界面看起来不错。执行ngserve时没有错误。当我查看应用程序时,控制台中没有错误。但是当我为我的项目运行Karma时,出现了错误:Failed:Templateparseerrors:'app-nav'isnotaknownelement:1.If'app-nav'isanAngularcomponent,thenverifythatitispartofthismodule.2.If'app-nav'isaWebComponentthenadd'CUSTOM_ELEMENTS_SCHEMA'tothe'@NgModu