【发布时间】:2017-08-25 23:23:11
【问题描述】:
我已经使用 skelton-plugin https://github.com/aurelia/skeleton-plugin 创建了一个 aurelia 插件,我现在正在考虑为它编写单元测试。 我正在努力为我添加到项目中的自定义元素运行单元测试。我从http://aurelia.io/hub.html#/doc/article/aurelia/testing/latest/testing-components/3 的“测试自定义元素”示例开始
模板:
<template>
<div class="firstName">${firstName}</div>
</template>
虚拟机
import {bindable} from 'aurelia-framework';
export class MyComponent {
@bindable firstName;
}
我将此添加到 src 文件夹中。
我的测试代码是
import {StageComponent} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';
describe('MyComponent', () => {
let component;
beforeEach(() => {
component = StageComponent
.withResources('my-component')
.inView('<my-component first-name.bind="firstName"></my-component>')
.boundTo({ firstName: 'Bob' });
});
it('should render first name', done => {
component.create(bootstrap).then(() => {
const nameElement = document.querySelector('.firstName');
expect(nameElement.innerHTML).toBe('Bob');
done();
}).catch(e => { console.log(e.toString()) });
});
afterEach(() => {
component.dispose();
});
});
我 jspm 安装了 aurelia-bootstrapper 和 aurelia-testing 以使其运行。 我现在收到错误
Error{stack: '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/my-component.js
所以看起来 karma 找不到我的组件。我检查了 karma.config 文件和 jspm loadFiles: ['test/setup.js', 'test/unit/**/*.js'],看起来是正确的。 有没有人遇到过类似的问题?
【问题讨论】:
-
将 .withResources('my-component') 更新为 .withResources('src/my-component') 现在错误是 error{stack: '(SystemJS) XHR error (404 Not Found)正在加载localhost:9876/base/src/my-component.html'
标签: karma-runner aurelia