我需要为单元测试提供静态泛型方法.但是,我似乎无法让Fakes创建填充对象.有谁知道如何做到这一点?
特别是,我想要填充Newtonsoft的JsonConvert.DeserializeObject <>()
我经常看到人们建议我包含HTML5 shiv JS脚本以使HTML5在Internet Explorer中工作,但我找不到这将涵盖的最常见用例的明确解释.
有人可能会提供为什么需要这个JS脚本的常见场景?
此外,它是否需要在<head>或者我可以将其与我的JS的其余部分放在<body>标记的底部,以便它不会阻止UI线程?
我有两个小的Backbone插件,看起来像这样:
(function($, _, Backbone) {
var ListView = Backbone.View.extend({
// blablabla
});
Backbone.ListView = ListView;
})($, _, Backbone);
Run Code Online (Sandbox Code Playgroud)
和
(function($, _, Backbone) {
var Repository = Backbone.Model.extend({
// blablabla
});
Backbone.Repository = Repository;
})($, _, Backbone);
Run Code Online (Sandbox Code Playgroud)
我现在已经设置了require.config:
require.config({
baseUrl: "javascripts",
shim: {
"jquery": {
exports: "$"
},
"underscore": {
exports: "_"
},
"backbone": {
deps: ['jquery', 'underscore'],
exports: "Backbone"
},
"ListView": {
deps: ['jquery', 'underscore', 'backbone'],
exports: "Backbone.ListView"
},
"Repository": {
deps: ['jquery', 'underscore', 'backbone'],
exports: "Backbone.Repository"
}
},
paths: …Run Code Online (Sandbox Code Playgroud) 如何为C库编写自定义Emscripten填充程序?Emscripten捆绑了某些C库(如SDL和OpenAL)的填充程序,但是对于其他库,您将不得不自己动手.
通过shim我的意思是,一个C库的JavaScript替换要移植的代码取决于.
bikesheddingCSS3属性还有其他选择吗?它似乎还没有得到支持.
我有以下设置为requireJS.
requirejs.config({
paths: {
'resources' : '/Scripts/resources'
},
shim: {
'resources': {
exports: 'LocalizedStrings'
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的资源.JS如下所示:
LocalizedStrings = {
title: "Demo",
save: "Save"
}
Run Code Online (Sandbox Code Playgroud)
现在当我在main.JS文件中加载资源作为依赖项时,我可以访问LocalizedStrings并且它可以工作.
//main.js
define(function(require){
var LocalizedStrings = require('resources');
console.log(LocalizedStrings); //works as expected
});
Run Code Online (Sandbox Code Playgroud)
但是在其他模块上,我并不需要将资源作为依赖项加载到"LocalizedStrings".
//othermodule.js
define(function(require){
console.log(LocalizedStrings); //works as expected even though resources dependency is not loaded
});
Run Code Online (Sandbox Code Playgroud)
我在这里不明白的是,如果我使用shim加载一个JS文件并加载一次,它是否全局可用,我不必再在其他模块中加载相同的依赖项.
我一直在浏览Mozilla开发者网络(MDN)上的polyfill实现,因为我需要其中一些用于库.我知道shim.js存在,但我没有使用它.
似乎polyfill在代码样式方面不一致.几乎看起来它们是由社区以几乎"维基"的方式编写的.
举个例子 String.prototype.contains
if(!('contains' in String.prototype)) {
String.prototype.contains = function(str, startIndex) {
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
}
}
Run Code Online (Sandbox Code Playgroud)
对我来说,实现这一点似乎更合乎逻辑:
if(!String.prototype.contains) {
String.prototype.contains = function(str, startIndex) {
return this.indexOf(str, startIndex) !== -1;
}
}
Run Code Online (Sandbox Code Playgroud)
鉴于JavaScript是一种大小关键的语言(因为网络传输的所有内容应尽可能小),我的示例应该对MDN上的示例有利,因为这样可以节省几个字节.
正如标题所示,我想知道代码在MDN上的可靠性,我是否应该根据需要对其进行修改以尽可能提供真正干净,微小的实现?
我无法编译使用 Microsoft fakes 的单元测试项目。尝试这样做时,我遇到了以下错误。
严重性代码描述项目文件行抑制状态错误 CS0115 'StubX509Certificate2.GetCertHash(HashAlgorithmName)':找不到合适的方法来覆盖 [C:\path\ServerAPI.UnitTest\obj\Debug\Fakes\s\f.csproj] ServerAPI.UnitTest C:\path\ServerAPI.UnitTest\f.cs 137304 活动
我正在使用 Visual Studio 2019(企业版)并针对 .NET 4.6.2。我不确定为什么会发生这种情况,并尝试将以下代码添加到 mscorlib.fakes。
<StubGeneration>
<Remove FullName="System.Security.Cryptography"/>
</StubGeneration>
Run Code Online (Sandbox Code Playgroud)
即使删除了假程序集引用和 .fakes 配置文件,我仍然收到此错误。
我想针对一些错误的网络行为测试存储库.我使用MS Fakes伪造了这个类,它看起来像这样:
ShimInputRepository
.AllInstances
.UpdateEngagementStringNullableOfInt64NullableOfInt32String = (xInst, xEngId, xTrimUri, xTargetVers, xComments) =>
{
if (xEngId != initializer.SeededEngagementsWithoutEmp[3].EngagementId)
{
return xInst.UpdateEngagement(xEngId, xTrimUri, xTargetVers, xComments); //Unfortunately, calls recursively same method (not the original one)
}
else
{
throw new Exception
(
"An error occurred while executing the command definition. See the inner exception for details.",
new Exception
(
"A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"
)
); …Run Code Online (Sandbox Code Playgroud) 我在mscorlib.fakes库中找到伪造的Thread.Sleep时遇到了麻烦.我正在关注http://www.codewrecks.com/blog/index.php/2012/04/27/using-shims-in-visual-studio-11-to-test-untestable-code/
http://msdn.microsoft.com/en-us/library/d00bd51t(v=vs.100).aspx显示Thread.Sleep在mscorlib中,所以我添加了它的假,但System.Threading.Fakes命名空间不包含ShimThread也不是StubThread.线程是一个密封类,但VS假框架应该能够在密封类中伪造静态方法.
我有一个新的 Angular 5 CLI 应用程序,并为应用程序的顶部构建了一个导航菜单组件。当我在 Edge 和 Chrome 中单击我的菜单项时,它可以完美运行并遵循我在 app.module.ts 中定义的路线。但是,当我单击 IE11 或 Firefox 中的链接时,没有任何反应。我去启用了所有可以在 polyfills.ts 中看到的 polyfill,但仍然没有变化,尽管它们确实解决了在 IE11 中渲染材质图标的问题。
<span *ngIf="isLoggedIn() == false">
<button [routerLinkActive]="['link-active']" mat-icon-button >
<a [routerLink]="['/login']">
<mat-icon>account_circle</mat-icon> Login
</a>
</button>
<span> </span>
</span>
Run Code Online (Sandbox Code Playgroud)
如果我把
<a [routerLink]="['/login']">
<mat-icon>account_circle</mat-icon> Login
</a>
Run Code Online (Sandbox Code Playgroud)
按钮节点的一部分我可以单击它并且它在 IE11 和 Firefox 中正确路由,所以我的路由很好。以某种方式激活锚点在 IE11 和 Firefox 中不起作用。有谁知道这可能是什么?Edge 和 Chrome 完美运行。
我刚开始构建android项目时遇到问题:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
Run Code Online (Sandbox Code Playgroud)
com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/crashlytics/android/answers/shim/R.class
试过其他相关的答案,比如从终端清理项目,重建但没有任何效果.
shim ×12
javascript ×3
c# ×2
polyfills ×2
requirejs ×2
android ×1
angular ×1
angular-cli ×1
backbone.js ×1
c ×1
crashlytics ×1
css ×1
css3 ×1
emscripten ×1
firefox ×1
html5 ×1
html5shiv ×1
module ×1
mozilla ×1
mstest ×1
stub ×1
unit-testing ×1
w3c ×1