如何使用自己的JavaScript库"在Qunit中思考 "?
我熟悉在javascript中开发,但现在我想开始使用Qunit (我的应用程序在HTML/JavaScript中).
我创建自己的库.我使用公共函数和私有函数.我也使用类似于jQuery的异步函数(事件监听器和回调):
var mylib;
(function() {
//...
})();
Run Code Online (Sandbox Code Playgroud)
我不知道如何组织.以下是一些问题,以澄清我正在寻求的答案类型:
是否有建议用于单元测试的QUnit插件?
使用GitHub,我可以在提交时自动使用QUnit吗?你是如何设置的?也许用travis-ci?
如何对异步函数进行单元测试?具体来说,如果函数与LocalStorage(HTML5存储)有链接并且可以与其他页面(如此)交互,该怎么办?我怎么测试呢?我应该使用对象变量而不是LocalStorage吗?
我访问了官方网站http://qunitjs.com/,但我不认为文档是一个很好的起点.
我试图在NodeJS和python中对base64编码二进制字符串,我得到2个不同的值.
注意,值是i在python中使用生成的16个随机字节os.urandom(16)
的NodeJS
> var i = '>e\x93\x10\xabK\xbe\xfeX\x97\x9a$\r\xef\x8f3';
> var s = new Buffer(i).toString('base64');
> console.log(s);
PmXCkxDCq0vCvsO+WMKXwpokDcOvwo8z
Run Code Online (Sandbox Code Playgroud)
蟒蛇
>>> import base64
>>> i = '>e\x93\x10\xabK\xbe\xfeX\x97\x9a$\r\xef\x8f3'
>>> s = base64.b64encode(i)
>>> print s
PmWTEKtLvv5Yl5okDe+PMw==
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?它适用于常规字符串,例如我的名字.
的NodeJS
> var s = new Buffer('travis').toString('base64');
undefined
> console.log(s);
dHJhdmlz
Run Code Online (Sandbox Code Playgroud)
蟒蛇
>>> s = base64.b64encode('travis')
>>> print s
dHJhdmlz
Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的类:
function myClass(q) {
this.someFunction = function(e) {
console.log("Click event");
};
jQuery(q).click(this.someFunction);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法向JSDoc表明someFunction不仅仅是一个应该直接调用的函数,而是一个事件处理程序?
我看到了@event标签,但是如果我理解正确的话,这更多的是记录我的类中的一个函数,我认为它是一个事件(客户端代码也将注册,我的类将在需要时触发)而不是事件处理程序功能?
我有一个很好的任务,就是使用带有Rails的大量SOAP api.SOAP服务有三种不同的绑定; wsHttpBinding,wsHttpBinding与x509,以及自定义绑定.我只能使用wsHttpBinding来击中两个端点,但是第三个端点需要用户名和密码,这与之无关.我因为证书而避免使用x509,并且自定义绑定在SoapUI中运行良好,但是使用Savon我得到以下错误.
由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).
我已经使用了Savon生成的确切XML并将其放入SoapUI并且它可以工作.
这是一个具有约束力的问题吗?有没有办法告诉它使用这个自定义绑定?
这是我在App.config中找到的自定义绑定
<bindings>
<customBinding>
<binding name="cust">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
<binding name="cust1">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
<binding name="cust2">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<endpoint address="http://api.xyz.com/stuff.svc/cust"
binding="customBinding" bindingConfiguration="cust" contract="stuff.Xstuff"
name="cust" />
Run Code Online (Sandbox Code Playgroud)
编辑#1
这是我当前的客户端设置,这有助于它.
@client = Savon.client(
wsdl: 'http://api.xyz.com/stuff.svc?wsdl',
wsse_auth: %w'username password',
wsse_timestamp: true,
raise_errors: false,
log: true,
log_level: :debug,
soap_version: 2,
pretty_print_xml: true,
convert_request_keys_to: :none,
use_wsa_headers: true,
headers: {'Content-Type' => 'application/soap+xml; charset=utf-8'}
Run Code Online (Sandbox Code Playgroud)
编辑#2
我发现了这个问题.Savon没有像SoapUI那样在Content-Type中设置动作.感谢@RicardoPontual建议再次尝试比较Savon和SoapUI请求,这让我更仔细地看一下并注意到这个问题.
headers: {'Content-Type' => 'application/soap+xml;charset=UTF-8;action="tempuri.org/stuf??f/set_table_stuff"'}
Run Code Online (Sandbox Code Playgroud) 我有一个引导面板,将标题移到了左侧。我正在努力使文本垂直(旋转90度)。
大多数情况下我都有这个,但是在使其他东西与CSS对齐时遇到了一些麻烦。
我的最终目标是,图标位于“标题/子标题”之前,所有内容均位于面板标题的中央,子标题位于标题下方。
.panel {
position: relative;
}
.panel-default>.panel-leftheading {
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
}
.panel-primary>.panel-leftheading {
color: #fff;
background-color: #428bca;
border-color: #428bca;
}
.panel-success>.panel-leftheading {
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6;
}
.panel-info>.panel-leftheading {
color: #31708f;
background-color: #d9edf7;
border-color: #bce8f1;
}
.panel-warning>.panel-leftheading {
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
}
.panel-danger>.panel-leftheading {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}
.panel-leftheading {
width: 42px;
padding-top: 10px;
padding-right: 15px;
padding-bottom: 10px;
padding-left: 8px;
border-right: 1px solid transparent;
border-bottom: 1px …Run Code Online (Sandbox Code Playgroud)在我的Javascript代码中,我正在检查变量是否未定义(未定义值但未定义变量)或null.修剪代码我正在使用运算符.我是这样做的:
if (myVariable === (undefined || null)) {
// Do something.
}
Run Code Online (Sandbox Code Playgroud)
我的一个朋友告诉过我,我应该把支票分成:
if (myVariable === undefined || myVariable === null) {
// Do something.
}
Run Code Online (Sandbox Code Playgroud)
这两种方法之间真的有什么区别吗?如果是,我应该使用哪一个?为什么?
当用户登录 API 时会生成一个令牌,以便他可以访问其他端点,但该令牌会在 60 秒后过期,我创建了一个函数来使用旧令牌(存储在数据库中)生成新的有效令牌,但是当我要生成新的有效令牌时,我收到 SecretOrPrivateKey 必须有一个值错误
函数refreshToken使用函数login生成一个新的token
secretOrPrivateKey must have a value
Error: secretOrPrivateKey must have a value
at Object.module.exports [as sign] (C:\Users\talis\nova api\myflakes_api\node_modules\jsonwebtoken\sign.js:107:20)
at JwtService.sign (C:\Users\talis\nova api\myflakes_api\node_modules\@nestjs\jwt\dist\jwt.service.js:28:20)
at AuthService.login (C:\Users\talis\nova api\myflakes_api\src\auth\auth.service.ts:18:39)
at TokenService.refreshToken (C:\Users\talis\nova api\myflakes_api\src\token\token.service.ts:39:37)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at TokenController.refreshToken (C:\Users\talis\nova api\myflakes_api\src\token\token.controller.ts:12:16)
at C:\Users\talis\nova api\myflakes_api\node_modules\@nestjs\core\router\router-execution-context.js:46:28
at C:\Users\talis\nova api\myflakes_api\node_modules\@nestjs\core\router\router-proxy.js:9:17
Run Code Online (Sandbox Code Playgroud)
token.service.ts文件中的函数refreshToken
async refreshToken(oldToken: string) {
let objToken = await this.tokenRepository.findOne({hash: oldToken})
if (objToken) {
let user = await this.userService.findOneOrFail({email:objToken.email})
return this.authService.login(user)
} else {
return new UnauthorizedException(MessagesHelper.TOKEN_INVALID)
} …Run Code Online (Sandbox Code Playgroud) 我的requirejs设置有问题,我试图解决它,但每次我打破应用程序.这是我的index.html
<script type="text/javascript" src="/js/bower_components/requirejs/require.js"></script>
<script>
// obtain requirejs config
require(['require', 'js/require-config'], function (require, config) {
// update global require config
window.require.config(config);
// load app
require(['main']);
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果我从根路径"/"加载应用程序,这很有效,但是一旦我尝试在其他地方刷新应用程序(即./ user/1),我就会收到以下错误:
资源解释为脚本但使用MIME类型text/html传输:" http://domain.local/users/js/require-config.js ".
require.js:1895 Uncaught SyntaxError:意外的令牌<
require-config.js:1资源被解释为脚本但使用MIME类型text/html传输:" http://domain.local/users/main.js ".
require.js:1895 Uncaught SyntaxError:意外的令牌<
正如你可以看到它在相对路径上寻找文件:
http://domain.local/users/js/require-config.js
但它应该加载:
http://domain.local/js/require-config.js
如果我/在模块的前面添加一个,那么它就不再工作了,因为它正在寻找一个文件而不是一个模块:
<script type="text/javascript" src="/js/bower_components/requirejs/require.js"></script>
<script>
// obtain requirejs config
require(['require', '/js/require-config'], function (require, config) {
// update global require config
window.require.config(config);
// load app
require(['/js/main']);
});
</script>
Run Code Online (Sandbox Code Playgroud)
资源解释为脚本但使用MIME类型text/html传输:" http://domain.local/js/require-config ".require.js:1895年
未捕获的SyntaxError:意外的令牌<require-config:1资源被解释为脚本但使用MIME类型text/html传输:
" …
我想知道如果我们可以在我们的网站上传任何字体?我在哪里可以下载字体或谷歌字体并将其直接上传到我的css文件中:
@font-face { font-family: 'Myriad Pro Regular';
font-style: normal;
font-weight: 300;
src: local('Myriad Pro Regular'), url('MYRIADPRO-REGULAR.woff') format('woff'); }
Run Code Online (Sandbox Code Playgroud)
而不是使用这种代码:
@import url(http://fonts.googleapis.com/css?family=Source+Sans Pro:200italic,200,300italic,300,400italic,400,600italic,600,700italic,700,900italic,900);
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试像绿色盒子一样改变我的 div 。
我想要获得 3D 变换,而不是 mask :
我找到了使用此生成器的方法,但 css 代码在我的小提琴上不起作用:
/*transform css3*/
#screen {
transform: scale(1.0) scaleZ(1.0) rotateX(-16deg);
transform-origin: 0% 0%;
perspective: 450;
perspective-origin: 100% 50%;
}
Run Code Online (Sandbox Code Playgroud)
/*transform css3*/
#screen {
transform: scale(1.0) scaleZ(1.0) rotateX(-16deg);
transform-origin: 0% 0%;
perspective: 450;
perspective-origin: 100% 50%;
}
Run Code Online (Sandbox Code Playgroud)
body {
height:100%;
padding:0;
margin:0;
}
#mask {
background:url(https://i.stack.imgur.com/cBK0O.png) no-repeat;
background-size:350px;
height:200px;
position:relative;
}
#screen:hover {
background:url(https://www.actugaming.net/wp-content/uploads/2018/06/Assassins-Creed-Odyssey_Leak_06-10-18_015-1.jpg);
background-size:100%;
}
#screen {
position:absolute;
bottom:38px;
background:red;
opacity:0.6;
}
#screen {
left:70px;
width:240px;
height:calc(240px * 9 / …Run Code Online (Sandbox Code Playgroud)我有一个文本区域,我希望用户编辑已经存在的内容,然后按Enter键以使用Ajax调用提交,但是一旦按Enter键,它就禁止进入新行。谢谢
$(document).keypress(function(e) {
if (!$(".specialClass").is(":focus")) {
e.preventDefault();
if (e.which == 13) {
console.log('You pressed enter!');
}
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
我找到了nodeJS服务器的示例代码.我不明白这行代码的作用是什么,它的真实含义是:
var urlParts = url.parse(req.url, true)
Run Code Online (Sandbox Code Playgroud)
以下几行对我来说也不清楚.为什么写data.txt是必要的?
fs.writeFileSync("data.txt", data);
Run Code Online (Sandbox Code Playgroud)
服务器
server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': 'http://localhost'
});
var urlParts = url.parse(req.url, true),
data = urlParts.query.data;
fs.writeFileSync("data.txt", data);
res.end("OK");
});
Run Code Online (Sandbox Code Playgroud)