Hey people,
I’m joyfully ding in the new Aurelia (lots of fun!!!). I have thought problems with the tests:
From pasted, I have the following issues":
I’m not really sure where exactly the error is.
The other thing I’m not sure is, how to configure the dependencies. Eg. I have an error from the code where I have
httpClient = resolve(newInstanceOf(IHttpClient));
How can I test this?
And how can test my-app component where I have:
import {Cases} from './cases';
import {Addresses} from './addresses';
import {Home} from './home';
export class MyApp {
static routes = [
{
path: '',
component: Home,
title: 'Home',
},
{
path: 'addresses',
component: Addresses,
title: 'Addresses',
},
{
path: 'addresses/:addressId',
component: Addresses,
title: 'Address details',
},
{
path: 'cases',
component: Cases,
title: 'Cases',
},
{
path: 'cases/:caseId',
component: Cases,
title: 'Case Details',
},
];
}
and the test is:
import {render} from './helper';
import {MyApp} from '../src/components/my-app';
describe('my-app', () => {
it('should render message', async () => {
const node = (await render('<my-app></my-app>', MyApp)).firstElementChild;
const text = node.textContent;
expect(text.trim()).toBe('Hello World!');
});
});
and the render is:
import Aurelia, {CustomElement} from 'aurelia';
import {DialogDefaultConfiguration} from '@aurelia/dialog';
import {RouterConfiguration} from '@aurelia/router';
import {StateDefaultConfiguration} from '@aurelia/state';
import {ValidationHtmlConfiguration} from '@aurelia/validation-html';
import {itemTreeHandler} from '../src/actions/action-handlers';
import {persistentStatePlugin} from '../src/lib/persistent-state';
import {initialState} from '../src/constants/initialstate';
export async function render(template, ...deps) {
const wrapper = CustomElement.define({name: 'wrapper', template});
const div = document.createElement('div');
const au = Aurelia
.register(deps)
.register(
RouterConfiguration.customize({
useUrlFragmentHash: false,
}))
.register(DialogDefaultConfiguration)
.register(ValidationHtmlConfiguration)
.register(StateDefaultConfiguration.init(
JSON.parse(localStorage.getItem('eosState')) || initialState,
itemTreeHandler,
),
persistentStatePlugin('eosState'),
)
.app({
host: div,
component: wrapper,
});
await au.start();
return div;
}
this is pretty much the same I’ve got from a fresh bootstrapped project.