【问题标题】:aurelia/skeleton-plugin cant run test on custum elementaurelia/skeleton-plugin 无法在自定义元素上运行测试
【发布时间】: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'],看起来是正确的。 有没有人遇到过类似的问题?

【问题讨论】:

标签: karma-runner aurelia


【解决方案1】:

解决了这个问题。

在需要更改的 karma.config.js 文件中 serveFiles: ['src//.'] 至 serveFiles: ['src//*.js', 'src/**/*.html']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    相关资源
    最近更新 更多