如何使用proxyquire和sinon存储以下模块:
var email = require("emailjs").server.connect.send();
Run Code Online (Sandbox Code Playgroud)
我做了以下,但它不起作用,因为当我尝试在其中触发错误send()
时仍然发送电子邮件.
sendMailStub = sinon.stub(email, "send");
testedModule = proxyquire('../index.js', {
'email': {
'server': {
'send': sendMailStub
}
}
});
Run Code Online (Sandbox Code Playgroud)
并尝试过:
testedModule = proxyquire('../index.js', {
email: {send: sendMailStub}
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是完整的测试,但失败了:
var chai = require('chai');
var sinonChai = require("sinon-chai");
var sinon = require('sinon');
chai.use(sinonChai);
var proxyquire = require('proxyquire');
var testedModule;
var expect = chai.expect;
describe('invoicer', function () {
var nock = require('nock');
var ResponseOptions = {
username: "Peter Pan",
user_address_line_1: "Never Never Land",
user_address_line_2: "Tree-house 99", …
Run Code Online (Sandbox Code Playgroud) 我有以下使用按钮组材料的反应组件。
当页面首次呈现时,选择默认值 5 并且单选框显示为checked
。
但是,当我选择任何其他单选框时,所有单选框都会变黑,并且不会显示任何选定内容。我已经检查过并且setValue
正在被调用并更改值,所以我不明白为什么值更改没有反映在单选框中?
import React, {useState} from 'react';
import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles((theme) => ({
root: {
marginTop: theme.spacing(3)
},
amountSelectGroupLabel: {
'&.MuiFormLabel-root': {
color: theme.palette.borders.primary
}
}
}));
const RadioButtons = (props) => {
const { radioButton, ...labelProps } = props;
return (
<FormControlLabel …
Run Code Online (Sandbox Code Playgroud) 安装zmq节点模块时,出现以下错误.我安装了最新的稳定版节点.
我在OS X 10.9.3上运行Mac
npm http GET https://registry.npmjs.org/zmq
npm http 304 https://registry.npmjs.org/zmq
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/bindings
> zmq@2.7.0 install /Users/mario/node_modules/zmq
> node-gyp rebuild
/bin/sh: pkg-config: command not found
gyp: Call to 'pkg-config libzmq --libs' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:340:16)
gyp ERR! stack …
Run Code Online (Sandbox Code Playgroud) 根据我的理解Bucket
,Couchbase中的a Database
与CouchDb中的 a node
相同,a 与a 相同document
.这些扣除是否正确?
那么,new Bucket
使用NodeJs SDK创建代码的代码是什么?我找不到相关的文档.
可以在async.waterfall
里面使用async.series
吗?
因此,例如,说我有一个模块api
有两种方法,api.get
并api.post
接着又模块,下载从S3存储图像,调整其大小,然后把它放回S3桶,resizer
.
我想发出一个获取请求api.get
并获取一个oauth
令牌,然后触发,然后resizer
才触发api.post
.我不需要在api
和之间传递任何结果resizer
.
到目前为止,我有这样的事情:
async.series([
function get (callback) {
api.get(callback)
},
async.waterfall([
function download (callback) {
S3.get({...}, callback);
},
function transform (response, callback) {
gm(..)
.resize(....)
.toBuffer(...) {
S3.put({...})
}, callback;
]),
function post (callback) {
api.post(callback)
}
], function (err) {
......
});
Run Code Online (Sandbox Code Playgroud)
但它永远不会触发api.post
并死亡S3.put
.为什么?
有没有人知道如何console.log's
运行aws lambda
功能?
当我在其测试环境中运行该函数时它很好,但我想在生产环境中运行它时看到日志.
我有下表dynamoDB
,我想value1
在第一个实例上写入并value2
留空。然后我运行额外的代码,然后才想用value2
. 我是新手dynamodb
所以在这方面遇到了一些麻烦。
我将如何设置我的表,以便第一次写入只能包含value1
第二次写入更新项目value2
?
就目前而言,尝试更新时出现以下错误:
ValidationException: The provided key element does not match the schema
我运行以下脚本来创建我的Id-map-table
:
var params3 = {
TableName : "my-Id-map",
KeySchema: [
{ AttributeName: "value1", KeyType: "HASH" },
{ AttributeName: "value2", KeyType: "RANGE"}
],
AttributeDefinitions: [
{ AttributeName: "value1", AttributeType: "S" },
{ AttributeName: "value2", AttributeType: "S" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};
dynamodb.describeTable({TableName:"my-Id-map"}, function(err,result) {
if (err) …
Run Code Online (Sandbox Code Playgroud) 我正在为一个函数编写测试代码,该函数将检查twitter中是否存在用户名.我正在使用Hapi框架和实验室进行测试.
当我运行时,npm test
我收到以下错误:
> NameGen@0.0.0 test /Users/mario/projects/NameGen
> ./node_modules/lab/bin/lab -c
/Users/mario/projects/NameGen/test/test.js:5
Lab.experiment( "Test Username Existence", function() {
^
TypeError: Object #<Object> has no method 'experiment'
at Object.<anonymous> (/Users/mario/projects/NameGen/test/test.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js [as origLoader] (module.js:474:10)
at Object.require.extensions..js (/Users/mario/projects/NameGen/node_modules/lab/lib/coverage.js:32:26)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:85:23
at Array.forEach (native)
at Object.internals.traverse (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:81:19)
at Object.exports.run (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:30:29)
at Object.<anonymous> (/Users/mario/projects/NameGen/node_modules/lab/bin/lab:3:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at …
Run Code Online (Sandbox Code Playgroud) 对于下面的代码片段nodejs
,我将如何send
使用proxyquire
和存根该方法sinon
,因为它属于文件index.js
?我尝试了很多方法,但经常出错.
var emailjs = require("emailjs");
emailjs.server.connect({
user: obj.user,
password: obj.password,
host: obj.host,
port: obj.port,
tls: obj.tls,
ssl: obj.ssl
})
.send(mailOptions, function(error, message){
if (error) {
console.log("ERROR");
context.done(new Error("There was an error sending the email: %s", error));
return;
} else {
console.log("SENT");
context.done();
return;
}
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,在我的测试中,我有以下设置,但得到Uncaught TypeError: Property 'connect' of object #<Object> is not a function
.
readFileStub = sinon.stub();
sendStub = sinon.stub();
connectStub = sinon.stub().returns(sendStub);
testedModule = proxyquire('../index', …
Run Code Online (Sandbox Code Playgroud) 使用md5
npm 模块,我试图理解为什么使用两个不同的输入值运行以下命令会产生相同的散列值。
const value1 = ["test1"];
const value2 = ["test2"];
const result1 = md5(value1);
const result2 = md5(value2);
// but
const result3 = md5(JSON.stringify(value1));
const result4 = md5(JSON.stringify(value2));
// result1 === result2
// result3 !== result4
Run Code Online (Sandbox Code Playgroud) 我试图简单地使用jQuery向一个按钮添加一个类.但没有任何反应.为什么?
http://jsbin.com/makoxibogeje/2/edit
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p>Press me!</p>
<button>Test</button>
<button>Fiddle</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
CSS:
.spinner { color:red;}
Run Code Online (Sandbox Code Playgroud)
使用Javascript
var B = {
btn: $("button"),
addSpinner: function() {
B.btn.click(function() {
this.addClass('spinner');
});
},
}
Run Code Online (Sandbox Code Playgroud) node.js ×7
proxyquire ×2
asynchronous ×1
aws-lambda ×1
couchbase ×1
hapijs ×1
javascript ×1
jquery ×1
lab ×1
material-ui ×1
md5 ×1
radio-group ×1
reactjs ×1
sinon ×1
unit-testing ×1
zeromq ×1