reactant
Version:
A framework for building React web applications
69 lines (58 loc) • 1.44 kB
text/typescript
import { injectable, testBed, ViewModule } from '..';
describe('testBed', () => {
test('mock with useValue', () => {
()
class Foo {
getValue() {
return 'foo';
}
}
()
class Bar {
constructor(public foo: Foo) {
//
}
getValue() {
return `${this.foo.getValue()}Bar`;
}
}
const bar = testBed({
main: Bar,
modules: [{ provide: Foo, useValue: { getValue: () => 'test' } }],
});
expect(bar.instance.getValue()).toBe('testBar');
expect(() => {
bar.bootstrap(document.createElement('div'));
}).toThrow(`Main module should be a 'ViewModule'.`);
});
test('mock with custom render', () => {
()
class Foo {
getValue() {
return 'foo';
}
}
()
class Bar extends ViewModule {
constructor(public foo: Foo) {
super();
}
getValue() {
return `${this.foo.getValue()}Bar`;
}
component() {
return null;
}
}
const bar = testBed({
main: Bar,
modules: [{ provide: Foo, useValue: { getValue: () => 'test' } }],
render: null as any,
});
const spy = jest.spyOn(console, 'log').mockImplementation();
bar.bootstrap(document.createElement('div'));
expect(spy.mock.calls.slice(-1)).toEqual([
['No render function is configured.'],
]);
});
});