Is there a way to get the MeteorStubs package to work in this context:
Unit under test:
import { Meteor } from 'meteor/meteor';
class Component {
constructor() {
Meteor.startup(() => {
this.$initialize.apply(this,[]);
});
}
$initialize() {
this.$onInit();
}
$onInit() {
}
}
export { Component, Component as default };
test:
import { expect } from "meteor/practicalmeteor:chai";
import { sinon } from "meteor/practicalmeteor:sinon";
import { MeteorStubs } from "meteor/velocity:meteor-stubs";
import { Meteor } from "meteor/meteor";
import Component from './component';
describe('Component', () => {
let myComponent;
class TestComponent extends Component {
constructor() {
super();
}
$onInit() {
}
}
beforeEach(() => {
MeteorStubs.install();
});
afterEach(() => {
MeteorStubs.uninstall();
});
describe('constructor', () => {
it('should register a startup function with meteor.', () => {
myComponent = new TestComponent();
let spy = sinon.spy(myComponent, '$onInit');
Meteor.runStartupMethods();
expect(spy.called).to.be.true;
});
});
});
The problem I have is that since my unit under test explicitly import Meteor from the package, the MeteorStubs don’t seem to get installed onto that context. So I end up getting the error that Meteor.runStartupMethods() is not a function. I’m aware that MeteorStubs.install accepts a context parameter, but I’m not sure there is an appropriate context to pass in there. This test works fine if I remove the Meteor import statements and just refer to global.Meteor.
Any thoughts welcome!