I'm facing problem while loading view in Aurelia test. Please refer below sample test code..
import {StageComponent} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';
describe('MyComponent', () => {
let component;
beforeEach(() => {
component = StageComponent
.withResources('src/common/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();
});
});
I'm using karma for running tests with proxies as -
proxies: {
'/base/jspm_packages/': '/base/wwwroot/jspm_packages/'
}
after running above test i'm able to load the view-model but it fails to load the view with following error -
LOG: 'Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/src/common/my-component.html Error: XHR error (404 Not Found) loading http://localhost:9876/base/src/common/my-component.html Error loading http://localhost:9876/base/src/common/my-component.html!http://localhost:9876/base/jspm_packages/github/systemjs/plugin-text@0.0.8.js Error loading http://localhost:9876/base/src/common/my-component.html!template-registry-entry'
Thank you for you help in advance!
UPDATE --> Karma.conf.js file
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jspm', 'jasmine'],
jspm: {
// Edit this to your needs
loadFiles: ['test/unit/setup.js', 'test/unit/**/*.js'],
serveFiles: ['src/**/*.js'],
paths: {
'*': 'src/*',
'test/*': 'test/*',
'github:*': 'jspm_packages/github/*',
'npm:*': 'jspm_packages/npm/*'
}
},
// list of files / patterns to load in the browser
files: [],
proxies: {
'/base/jspm_packages/': '/base/wwwroot/jspm_packages/'
},
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.js': ['babel'],
'src/**/*.js': ['babel', 'coverage']
},
'babelPreprocessor': {
options: {
sourceMap: 'inline',
presets: ['es2015-loose', 'stage-1'],
plugins: [
'syntax-flow',
'transform-decorators-legacy',
'transform-flow-strip-types'
]
}
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
It might be that this line:
serveFiles: ['src/**/*.js'],
should actually be this:
serveFiles: ['src/**/*.js', 'src/**/*.html']
Normally your html would be bundled up with your component's js, but in this case you're serving the html directly.