Hi,
I’d like to test a component. This component dispatches an action in its activation method. Sadly, when I call the activate
method, I get this error:
TypeError: Cannot read property 'mark' of undefined
at Store.<anonymous> (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:375:57)
at step (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:94:23)
at Object.next (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:75:53)
at node_modules/aurelia-store/dist/commonjs/aurelia-store.js:68:71
at __awaiter (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:64:12)
at Store.Object.<anonymous>.Store.internalDispatch (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:365:16)
at Store.<anonymous> (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:346:51)
at step (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:94:23)
at Object.next (node_modules/aurelia-store/dist/commonjs/aurelia-store.js:75:53)
From what I see, it comes from aureliaPal.PLATFORM.performance.mark("dispatch-start");
in the code of the plugin. I am using Jest as a test runner and Webpack as a bundler. Any idea how to solve this? I’d really like to fully test this.
My test file:
import {bootstrap} from 'aurelia-bootstrapper';
import {Container, PLATFORM} from 'aurelia-framework';
import {Store} from 'aurelia-store';
import {StageComponent} from 'aurelia-testing';
import {registerRssBackendsActions} from '../../../src/store/rss-backends-actions';
import {createInitialState} from '../../__fixtures__/state-fixtures';
describe('Route: DisplayArticlesFromCategory', () => {
describe('Render tests', () => {
let container;
let component;
let store;
let state;
beforeEach(async() => {
container = new Container();
container.makeGlobal();
state = createInitialState();
state.rss.isFetching = true;
store = new Store(state);
// FIXME: This is required to make the test pass.
store.dispatch = jest.fn().mockImplementation(() => {});
registerRssBackendsActions(store);
container.registerInstance(Store, store);
component = StageComponent.withResources(PLATFORM.moduleName('../../src/routes/display-articles-from-category'))
.inView('<display-articles-from-category></display-articles-from-category>');
await component.create(bootstrap);
component.viewModel.store = store;
component.viewModel.activate();
return component;
});
it('should render and match snapshot fetching', async() => {
await component.waitForElement('.fa-spinner');
expect(document.body.outerHTML).toMatchSnapshot();
component.dispose();
});
});
});