So I'm using Typescript/RequireJs/Jasmine, and can't get my spy to work for modules loaded in another module.
Here is my Spec:
import { CrmWebApiLib } from "../../../webresources/allgnt_/scripts/Allgnt.RestLib";
import { TextFormatter } from "../../../webresources/new_/scripts/script/TextFormatter";
describe("Test", () => {
it("A Test", () => {
spyOn(CrmWebApiLib, "create").and.callFake((a, b) => { });
TextFormatter.test();
expect(CrmWebApiLib.create).toHaveBeenCalled();
});
it("B Test", () => {
var stub = {
CrmWebApiLib: {
create(a, b) { }
}
};
define("../../../webresources/allgnt_/scripts/Allgnt.RestLib", [], stub as any);
spyOn(stub.CrmWebApiLib, "create").and.callFake((a, b) => { });
TextFormatter.test();
expect(CrmWebApiLib.create).toHaveBeenCalled();
});
});
Here is the TextFormatter:
import { RestLib, CrmWebApiLib } from "../../../allgnt_/scripts/allgnt.restlib";
export module TextFormatter {
export function test() {
CrmWebApiLib.create("A", "Test");
}
}
In either "A Test" or "B Test" I can't get the spy to function. It always calls the actual implementation and errors. I can change the TextFormatter
to allow for it's definition of TextFormatter to be injected in, but that just feels wrong.
How do I get the spyOn call to work in situations like this?