How do I go about unit testing a method that calls the DialogController? I want to test that this.controller.ok()
was called.
ReprocessLotDialog.js
@inject(DialogController)
export class ReprocessLotDialog {
constructor(dialogController) {
this.controller = dialogController;
}
commitReprocessingLot() {
this.controller.ok({
reprocessLot: this.model
});
}
commitIncompleteBags(){
... do stuff ....
this.commitReprocessingLot();
}
}
myDialog.spec.js
I've tried this but can't get it to work
describe("The ReprocessLotDialog module", ()=> {
let sut;
beforeEach(()=> {
var container = new Container().makeGlobal();
container.registerInstance(DialogController,controller => new DialogController());
sut = container.get(ReprocessLotDialog);
});
it("commitReprocessingLot() should call controller.ok", (done)=> {
spyOn(sut, "controller.ok");
sut.commitIncompleteBags();
expect(sut.controller.ok).toHaveBeenCalled();
done();
});
});
The test fails with TypeError: 'undefined' is not a function (evaluating 'this.controller.ok({ reprocessLot: this.model })')
As far as I understand it I'm passing the DialogController
through DI into the container
and container.get(ReprocessLotDialog)
injects the DialogController into the ctor.
I've also tried
container.registerInstance(DialogController,{"dialogController":DialogController});
but that doesn't work either.
Many thanks