Mocking an empty object using setup and returns
brooksfolk opened this issue · 0 comments
brooksfolk commented
Typemoq tests fail when I try and use '{}' within a setup and return. However, I can create a method that returns a blank object and tests pass.
TestUtil.testAsync(async () => {
const mockedUpload = getMockedUpload();
const blankBody = getBlankBody();
const req: typemoq.IMock<ExpressRequest> = typemoq.Mock.ofType<ExpressRequest>();
req.setup(u => u.body).returns(() => blankBody);
const res: typemoq.IMock<ExpressResponse> = typemoq.Mock.ofType<ExpressResponse>();
const promise = new Promise<Definitions.Upload>((resolve, reject) => {
resolve(mockedUpload);
});
uploadService.setup(files => files.createUpload(blankBody)).returns(() => promise);
And blank body:
function getBlankBody() {
return {};
}
The above example works, but if I try to set empty object inline tests fail:
TestUtil.testAsync(async () => {
const mockedUpload = getMockedUpload();
const req: typemoq.IMock<ExpressRequest> = typemoq.Mock.ofType<ExpressRequest>();
req.setup(u => u.body).returns(() => {});
const res: typemoq.IMock<ExpressResponse> = typemoq.Mock.ofType<ExpressResponse>();
const promise = new Promise<Definitions.Upload>((resolve, reject) => {
resolve(mockedUpload);
});
uploadService.setup(files => files.createUpload({})).returns(() => promise);
Please advise.