本文介绍了Chutzpah或Jasmine不允许我运行使用原型的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JavaScript测试中,Chutzpah和Jasmine在Visual Studio的解决方案中运行良好.

Chutzpah and Jasmine runs fine in my solution in Visual Studio, for my javascript tests.

我有一个问题,我认为是chutzpah,但我不确定100%(可能是茉莉花).

I have an issue, and I think it's chutzpah but I'm not 100% certain (it could be Jasmine).

我现在需要测试我的扩展方法,其中包含类似于

I now need to test my extension methods, which contains code similar to

if (!Array.prototype.where) {
    Array.prototype.where = function(callback) {
        const arr = [];
        this.forEach(function(item) {
            if (callback(item)) {
                arr.push(item);
            }
        });
        return arr;
    };
}

我的茉莉花测试是

    //arrange
    const array = [];
    const fixedInput = "a";
    array.push(fixedInput);
    array.push("b");

    //act
    const result = array.where(a => a === fixedInput);
    //console.log(result);

    //assert
    const expected = [fixedInput];
    expect(result).toBe(expected);
    expect(result.length).toBe(1);

我无法通过命令行或Visual Studio中的Chutzpah插件运行此测试(并且在VS中显示为不可行的测试)

I am unable to run this test, over command line or the Chutzpah plug in within Visual Studio (and it does not show as a viable test in VS)

如果我注释掉 const result = array.where(a => a === fixedInput); ,则会发现测试.

If I comment out the const result = array.where(a => a === fixedInput); then the test is discovered.

如果执行测试,并注释掉该行,则会显示测试结果的Jasmine网页-打开该窗口,我可以编辑测试,取消注释该行,就可以得到期望的结果(但仅适用于几秒钟,直到结果页面变成找不到文件".

If I execute the test, with that line commented out, the Jasmine web page of test results is shown - with it open, I can edit the test, uncomment the line and I get the result I would expect (but only for a few seconds until that result page turns into a "file not found").

显示输出窗口

我不知道该如何解决.有什么建议吗?

I don't know how to solve this. Any advice?

推荐答案

您可能遇到一个问题,默认情况下Chutzpah使用旧的JS引擎.您应该将chutzpah.json配置为使用更新的 https://github.com/mmanela/chutzpah/wiki/浏览器引擎

You are probably hitting an issue that Chutzpah by default uses an old JS engine. You should configure your chutzpah.json to use a newer one https://github.com/mmanela/chutzpah/wiki/Browser-Engines

这篇关于Chutzpah或Jasmine不允许我运行使用原型的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 16:48