testingUtils.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
  5. var link_1 = require("../link");
  6. var sampleQuery = graphql_tag_1.default(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n query SampleQuery {\n stub {\n id\n }\n }\n"], ["\n query SampleQuery {\n stub {\n id\n }\n }\n"])));
  7. function checkCalls(calls, results) {
  8. if (calls === void 0) { calls = []; }
  9. expect(calls.length).toBe(results.length);
  10. calls.map(function (call, i) { return expect(call.data).toEqual(results[i]); });
  11. }
  12. exports.checkCalls = checkCalls;
  13. function testLinkResults(params) {
  14. var link = params.link, context = params.context, variables = params.variables;
  15. var results = params.results || [];
  16. var query = params.query || sampleQuery;
  17. var done = params.done || (function () { return void 0; });
  18. var spy = jest.fn();
  19. link_1.execute(link, { query: query, context: context, variables: variables }).subscribe({
  20. next: spy,
  21. error: function (error) {
  22. expect(error).toEqual(results.pop());
  23. checkCalls(spy.mock.calls[0], results);
  24. if (done) {
  25. done();
  26. }
  27. },
  28. complete: function () {
  29. checkCalls(spy.mock.calls[0], results);
  30. if (done) {
  31. done();
  32. }
  33. },
  34. });
  35. }
  36. exports.testLinkResults = testLinkResults;
  37. var templateObject_1;
  38. //# sourceMappingURL=testingUtils.js.map