小编fre*_*sko的帖子

在Jasmine中,array.includes不起作用(必须由其他函数替换).为什么?

我的问题似乎很奇怪.我有一个带有一个新的,非常简单的函数的构造函数,它应该检查变量是否包含在数组中.它完美地工作(我在表单中使用此功能).

但是......我不能在这个函数上写任何单元测试,因为Karma/Jasmine看不到数组的"包含"功能.

有人可以建议我做什么吗?这里的情况,有点简化:

//要测试的构造函数

    vm.isNameAlreadyUsed = function () {
    //debut logging:
        console.log ("vm.allNames ",vm.allNames);  // output: vm.allNames ['A', 'B', 'C']
        console.log ("and vm.nameToBeChecked is ",vm.nameToBeChecked);    //output: and vm.nameToBeChecked is 'A'

        return vm.allNames.includes(vm.nameToBeChecked);
        // The previous works as expected at runtime, but it causes the following exception in karma/jasmine:
        // TypeError: undefined is not a constructor (evaluating 'vm.allNames.includes(vm.nameToBeChecked)
    };
Run Code Online (Sandbox Code Playgroud)

//测试(业力/茉莉花)

        theConstructor.allNames = ["A", "B", "C"];
        theConstructor.nameToBeChecked = "A";
        var result theConstructor.isNameAlreadyUsed();           //error!
        expect(result).toBeTruthy();
Run Code Online (Sandbox Code Playgroud)

茉莉花有可能看不到"包含"吗?数组被填充,变量也... ...为什么应该是那里的任何构造函数?

TypeError: undefined is not a constructor …
Run Code Online (Sandbox Code Playgroud)

javascript arrays unit-testing karma-jasmine

9
推荐指数
1
解决办法
1572
查看次数

Inno Setup语法 - OR,AND

我必须更改Inno安装脚本.但是我无法编译它(每次编译时,我都要等待将近1个小时才能完成构建).我需要知道如何编写C++伪代码中的以下表达式:

if ((A==B) || (A==C))
{
  // do something
}
Run Code Online (Sandbox Code Playgroud)

问题是我应该如何在Inno Setup脚本中编写它,如果可能的话,你知道这个脚本语言是否特定于Inno Setup,或者我可以在某个地方找到指南吗?在官方网站上,很难以简单的方式得到你想要的东西,它相当混乱,我找不到简单的例子OR(例子非常基本).

inno-setup pascalscript

7
推荐指数
1
解决办法
3523
查看次数

Jasmine toBeClose到底是什么第二个参数?

Jasmine的文档很短; 经常就够了.不总是.

我想知道toBeCloseTo的第二个参数究竟是什么.官方参考仅显示:

it("The 'toBeCloseTo' matcher is for precision math comparison", function() {
    var pi = 3.1415926, e = 2.78;
    expect(pi).not.toBeCloseTo(e, 2);
    expect(pi).toBeCloseTo(e, 0);
});
Run Code Online (Sandbox Code Playgroud)

好吧它是精确的,但在这种情况下实际上意味着"精确"?是"."之后的位数.应该是一样的吗?

我的情况:我想比较两个时间戳,以毫秒为单位; 如果他们之间的差异小于100,那对我来说没问题.

例如,在下列情况下X的值是多少?

var timestamp1 = 1501254807000;
var timestamp2 = 1501254807099;
var timestamp3 = 1501254807100;
var precision = X;
expect(timestamp1).toBeCloseTo(timestamp2, precision); //this should pass
expect(timestamp1).toBeCloseTo(timestamp3, precision); //this should NOT pass
Run Code Online (Sandbox Code Playgroud)

如果精度仅用于十进制数,我可以将我的整数除以1000得到十进制数,但无论如何,我不知道什么是X.现在,我这样做:

 expect(Math.abs(timestamp2-timestamp1)).toBeLessThan(100);
Run Code Online (Sandbox Code Playgroud)

但它不是很易读,我想使用toBeCloseTo(因为它会出现......).

谢谢


编辑.以下结果可能会有所帮助:

expect(1000000.005).toBeCloseTo(1000000.000,3); //fails
expect(1000000.005).toBeCloseTo(1000000.000,2); //fails
expect(1000000.005).toBeCloseTo(1000000.000,1); //pass
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jasmine angularjs

6
推荐指数
1
解决办法
4760
查看次数

列出 Azure 中(子)目录中的所有文件

我正在使用 Java 开发一个 azure 函数。我需要迭代以下文件夹中的所有文件

aDirectory/aSubdirectoryWithManyFiles/
Run Code Online (Sandbox Code Playgroud)

该路径中有很多文件:

aDirectory/aSubdirectoryWithManyFiles/file1
aDirectory/aSubdirectoryWithManyFiles/file2
aDirectory/aSubdirectoryWithManyFiles/file3
aDirectory/aSubdirectoryWithManyFiles/file4
aDirectory/aSubdirectoryWithManyFiles/file5
Run Code Online (Sandbox Code Playgroud)

所以我写了下面的代码来获取它们:

// myCloudBlobContainer is a CloudBlobContainer
// I expected to get all files thanks to the next row
Iterable<ListBlobItem> blobs = myCloudBlobContainer.listBlobs();
// The only blob found in the container is the directory itself
for (ListBlobItem blob : blobs) {
    //log the current blob URI
    if (blob instanceof CloudBlob) {  // this never happens
        CloudBlob cloudBlob = (CloudBlob) blob;
        //make nice things with every found file
    }
} …
Run Code Online (Sandbox Code Playgroud)

java azure azure-blob-storage

5
推荐指数
1
解决办法
1万
查看次数

GIT undo branch -D

After merged my changes on the main remote branch, I wanted to remove the name of my branch and leave the branch where it is. Only delete its name (in my team they don't like branches with names, unless they are releases).

So I did the following:

git branch -d branch_2b_deleted
error: The branch 'branch_2b_deleted' is not fully merged.
If you are sure you want to delete it, run 'git branch -D branch_2b_deleted'
git branch -D branch_deleted
git push origin …
Run Code Online (Sandbox Code Playgroud)

git

2
推荐指数
1
解决办法
467
查看次数

TSLint - 如何避免我的所有代码都用红色下划线?

我在 ItelliJ 中加载了一个 angular 项目,所有文件都有一些用红色下划线标出的代码。右边的滚动条上也有同样的红色。代码似乎充满了错误,但它们只是缺少空格或类似的东西;该项目已正确构建。甚至在 // 之后没有空格的注释也会用红色下划线表示。

负责人是 TSLint。

这让我分心;我想为“真正的”问题加下划线的代码,并且可能在左侧(而不是滚动条中)为注释或导入中缺少空格的黄色建议。

我发现了这个(这里https://github.com/Microsoft/vscode-tslint/issues/199

tslint.alwaysShowRuleFailuresAsWarnings

但它在visualStudio中,我不知道在intelliJ中的哪里添加这个选项。

你知道如何禁用这个红色下划线吗?

还有一个问题,如果我要禁用 TSLint,除了格式之外,我会丢​​失任何东西吗?我喜欢有一个格式良好的代码,但是在 IntelliJ 环境中,我希望主要是语法错误而不是格式错误,至少不是实时的(也许我可以在需要时运行以检查代码格式,因为我直到现在)。

这是第一个答案要求的屏幕截图。设置被忽略了,可能是我电脑有问题...(顺便说一下TLSint是5.0.0)

设置 - 我选择不突出显示 前两行是红色的,因为尾随空格。 我不喜欢这样的空格,但红色太多了

intellij-idea tslint

1
推荐指数
1
解决办法
1470
查看次数