aurelia/skeleton-plugin 无法 运行 测试自定义元素

aurelia/skeleton-plugin cant run test on custum element

我已经使用 skelton-plugin 创建了一个 aurelia 插件 https://github.com/aurelia/skeleton-plugin 我现在正在考虑为它编写单元测试。 我正在努力为我添加到项目中的自定义元素进行单元测试 运行ning。我从 http://aurelia.io/hub.html#/doc/article/aurelia/testing/latest/testing-components/3

中的 'testing a custom element' 示例开始

模板:

<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 来获取它 运行ning。 我现在收到错误

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'],看起来是正确的。 有人 运行 遇到过类似问题吗?

解决了问题。

in karma.config.js 文件需要更改 服务文件:['src//.'] 到 服务文件:['src//*.js', 'src/**/*.html']