I’m currently taking the plunge into upgrading to the latest webpack and karma versions, basing my changes on the generated skeleton from aurelia-cli. So far, things have gone well, except for when I’m checking the “innerText” of an element that uses string interpolation from an injected class (evaluates to empty).
Has anyone else run into this? I’m able to reproduce it in the aurelia-cli skeleton. This did not used to be an issue.
app.js:
import {inject} from 'aurelia-framework';
import {AppLocalization} from './localizations/app-localization';
@inject(AppLocalization)
export class App {
constructor(appLocalization) {
this.appLocalization = appLocalization;
}
activate() {
console.log(this.appLocalization.HELLO_WORLD); // This properly prints the value to the console
}
}
app.html:
<template>
<h1 id="msg-id">${appLocalization.HELLO_WORLD}</h1>
</template>
localizations/app-localization.js:
/**
* Screen specific strings
*/
export class AppLocalization {
constructor() {
this.HELLO_WORLD = 'Hello World!';
}
}
app.spec.js:
import {App} from '../../src/app';
import {PLATFORM, DOM} from 'aurelia-pal';
import {StageComponent} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';
describe('the app', () => {
let component;
describe('and testing screen components', () => {
beforeEach(() => {
// Configure Component (Screen)
component = StageComponent
.withResources(PLATFORM.moduleName('app'))
.inView('<app></app>');
component.bootstrap(aurelia => {
aurelia.use.standardConfiguration();
});
});
afterEach(() => {
component.dispose();
});
it('should display the correct header for the screen', done => {
component.create(bootstrap)
.then(() => component.viewModel.activate())
.then(() => {
const element = document.querySelector('#msg-id');
expect(element).toBeDefined();
expect(element.innerText).toBe('Hello World!');
done();
return null;
}).catch(done.fail);
});
});
});
Test fails with message:
Error: expect(received).toBe(expected)
Expected value to be (using ===):
"Hello World!"
Received:
undefined