2017-08-25 34 views
0

我已经使用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'],看起来正确。 有没有遇到过类似的问题?

+0

更新.withResources( '我的组分')以.withResources('的src/(SystemJS)XHR错误(404 Not Found)加载http:// localhost:9876/base/src/my-component.html' – user4912152

回答

0

解决了这个问题。

在karma.config.js文件需要更改 serveFiles:['src// '] 到 serveFiles:['。SRC/ /*.js', 'SRC/**/* HTML']

相关问题