首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Internet中运行Karma时使用WaitForElement进行aurelia测试

在Internet中运行Karma时使用WaitForElement进行aurelia测试
EN

Stack Overflow用户
提问于 2017-04-21 14:05:31
回答 1查看 253关注 0票数 3

我们目前正在开发一个需要在Internet 11上运行的Aurelia应用程序。在我们尝试使用业力启动器在IE11上运行我们的karma/磁带测试之前,一切都很棒。

业力启动正常,一些测试正在执行,直到遇到使用waitForDocumentElement的测试。由于waitForDocumentElement使用承诺,我告诉自己,太好了,我只需要在Karma中加载一些Promise多填充,一切就会像使用Chrome时一样开始工作。但显然没有。

所以,最后一个问题。是否有一种方法可以让我的测试在Karma上运行,以IE11为目标,使用karma-ie-launcher,并能够在测试中使用waitForDocumentElement。这似乎是罪魁祸首,因为它使用承诺。

我可以建立一个样本回购我的项目,如果需要的话。

谢谢!

编辑:,这是“堆栈外空间”错误的堆栈跟踪。对于记录而言,rawValue是我试图在waitForDocumentelement中断言的一个可绑定属性,所以绑定和所有这些都有时间来完成它们的工作。

代码语言:javascript
复制
 WARN: 'Unhandled rejection TypeError: Unable to get property 'rawValue' of undefined or null reference
   at Anonymous function (http://localhost:9876/base/dist/_test/components/aurelia-numeric-input/aurelia-numeric-input.spec.js?ea0d4f3a76b6b818e30e08a7cbbc07dc5c11e02a:31:17)
   at r (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:31:9351)
   at i.prototype._settlePromiseFromHandler (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:14559)
   at i.prototype._settlePromise (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:15364)
   at i.prototype._settlePromise0 (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:16065)
   at i.prototype._settlePromises (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:17395)
   at r.prototype._drainQueue (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3054)
   at r.prototype._drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3112)
   at drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:1236)
   at Anonymous function (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:31140)'
WARN: 'Unhandled rejection TypeError: Unable to get property 'rawValue' of undefined or null reference
   at Anonymous function (http://localhost:9876/base/dist/_test/components/aurelia-numeric-input/aurelia-numeric-input.spec.js?ea0d4f3a76b6b818e30e08a7cbbc07dc5c11e02a:36:17)
   at r (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:31:9351)
   at i.prototype._settlePromiseFromHandler (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:14559)
   at i.prototype._settlePromise (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:15364)
   at i.prototype._settlePromise0 (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:16065)
   at i.prototype._settlePromises (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:17395)
   at r.prototype._drainQueue (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3054)
   at r.prototype._drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:3112)
   at drainQueues (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:29:1236)
   at Anonymous function (http://localhost:9876/base/node_modules/bluebird/js/browser/bluebird.min.js?3d186ac6d244691754303d3153839bf42b57f7d1:30:31140)'
WARN: 'Unhandled rejection Error: Out of stack space
   at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2691:7)
   at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11)
   at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7)
   at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9)
   at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11)
   at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7)
   at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9)
   at _compileNode (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2547:11)
   at compile (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2516:7)
   at _compileElement (http://localhost:9876/base/node_modules/aurelia-templating/dist/amd/aurelia-templating.js?1766dc2dd0fa5489caa6a2c286fad9ab686c2f09:2721:9)'
EN

回答 1

Stack Overflow用户

发布于 2017-04-21 16:00:31

Karma在名为__karma__的窗口上创建一个属性,该属性列出与karma.conf.js中的模式匹配的文件。通常,您的测试入口点模块中有一些代码会在这个文件名列表中加注并删除扩展名等,这样它们就会成为一个适合于加载程序的模块名称列表.(在您的情况下需要;)

然后,将这个模块名称数组分配给所需配置的deps属性,这将导致在调用分配给所需配置的callback属性的函数之前,需要加载所有这些组件。

我一直在手动添加蓝知更鸟作为第一个依赖项。然后,在回调中,我进行一些特征检测,如果浏览器不支持承诺,则将其分配给window.Promise。

下面是一个应该非常清晰地映射到您的设置的示例。相关行均附有注释。

代码语言:javascript
复制
const testModules = Object.keys(window.__karma__.files)
    .filter(filename => /\.spec\.js$/.test(filename))
    .map(filename => filename.replace(/^\/base\/dist\/|\.js$/g, ''));

testModules.unshift('bluebird');  // make bluebird the first dependency in the array... this means it will be the first argument to the callback function (see below)

let karmaStarted = false;

require.config({
    baseUrl: '/base/global/output',
    paths: {
        'bluebird': '../some/path/to/bluebird.min' // ensure the loader can find bluebird
    },
    deps: testModules,  // bluebird is the first item in this array of modules
    callback: (bluebird: any) => {  // bluebird is the first arg... there are many other args but we don't care about the rest
        if (karmaStarted) {
            return;
        }

        // polyfill Promise on an as-needed basis.
        if (!('Promise' in window && 'resolve' in window.Promise && 'reject' in window.Promise && 'all' in window.Promise && 'race' in window.Promise)) {
            window.Promise = bluebird.Promise;
        }

        karmaStarted = true;
        window.__karma__.start();
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43544792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档