我已經使用skelton-plugin創建了aurelia插件https://github.com/aurelia/skeleton-plugin我現在正在爲它編寫單元測試。 我在爲項目中添加的自定義元素添加單元測試。我開始與來自http://aurelia.io/hub.html#/doc/article/aurelia/testing/latest/testing-components/3aurelia/skeleton-plugin無法在custum元素上運行測試
模板 '測試自定義元素' 例如:
<template>
<div class="firstName">${firstName}</div>
</template>
VM
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路上,引導程序和奧裏利亞測試,以讓它運行。 IM現在得到的錯誤
Error{stack: '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/my-component.js
所以看起來人緣不能找到我的組件。我檢查了karma.config文件和jspm loadFiles:['test/setup.js','test/unit/**/*。js'],看起來正確。 有沒有遇到過類似的問題?
更新.withResources( '我的組分')以.withResources('的src/(SystemJS)XHR錯誤(404 Not Found)加載http:// localhost:9876/base/src/my-component.html' – user4912152