I have converted my fetch calls to use breeze.EntityQuery but how can I write my unit tests to mock the breeze client? Here is my code for the unit test fetch call that I'm trying to write for breeze.
class HttpStub {
fetch(url) {
var response = this.itemStub;
this.url = url;
return new Promise((resolve) => {
resolve({ json: () => response });
});
}
configure(func) {}
}
describe('Order', () => {
var sut, http, itemStubs, itemFake;
beforeEach(() => {
http = new HttpStub();
sut = new Order(http);
itemStubs = [1];
itemFake = [2];
http.itemStub = itemStubs;
});
describe('getOrders', () => {
it('should return orders', (done) => {
var info = new Info("1", "C", null, null);
sut.getOrders(info).then(result => {
expect(result).toBe(itemStubs);
expect(result).not.toBe(itemFake);
done();
});
});
});
});
Try using the jasmine
spyOnfunction withcallFake. Jasmine's spies are an easier way to mock a function call.An example (with TypeScript)