UNPKG

4.53 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("apollo-angular"),require("@apollo/client/core"),require("@angular/core"),require("graphql")):"function"==typeof define&&define.amd?define("apollo-angular/testing",["exports","apollo-angular","@apollo/client/core","@angular/core","graphql"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["apollo-angular"]=e["apollo-angular"]||{},e["apollo-angular"].testing={}),e["apollo-angular"],e.core,e.ng.core,e.graphql)}(this,(function(e,t,o,r,n){"use strict";var i=function(){},a=function(e){return e&&e.hasOwnProperty("graphQLErrors")},p=function(){function e(e,t){this.operation=e,this.observer=t}return e.prototype.flush=function(e){a(e)?this.observer.error(e):(this.observer.next(e),this.observer.complete())},e.prototype.flushData=function(e){this.flush({data:e})},e.prototype.networkError=function(e){var t=new o.ApolloError({networkError:e});this.flush(t)},e.prototype.graphqlErrors=function(e){this.flush({errors:e})},e}(),c=function(){function e(){this.open=[]}return e.prototype.handle=function(e){var t=this;return new o.Observable((function(o){var r=new p(e,o);t.open.push(r)}))},e.prototype._match=function(e){var t=this;return"string"==typeof e?this.open.filter((function(t){return t.operation.operationName===e})):"function"==typeof e?this.open.filter((function(t){return e(t.operation)})):this.isDocumentNode(e)?this.open.filter((function(t){return n.print(t.operation.query)===n.print(e)})):this.open.filter((function(o){return t.matchOp(e,o)}))},e.prototype.matchOp=function(e,t){var o=JSON.stringify(e.variables),r=JSON.stringify(e.extensions),i=this.compare(e.operationName,t.operation.operationName),a=this.compare(o,t.operation.variables),p=n.print(t.operation.query)===n.print(e.query),c=this.compare(r,t.operation.extensions);return i&&a&&p&&c},e.prototype.compare=function(e,t){var o,r="string"==typeof(o=t)?o:JSON.stringify(o);return!e||r===e},e.prototype.match=function(e){var t=this,o=this._match(e);return o.forEach((function(e){var o=t.open.indexOf(e);-1!==o&&t.open.splice(o,1)})),o},e.prototype.expectOne=function(e,t){t=t||this.descriptionFromMatcher(e);var o=this.match(e);if(o.length>1)throw new Error('Expected one matching operation for criteria "'+t+'", found '+o.length+" operations.");if(0===o.length)throw new Error('Expected one matching operation for criteria "'+t+'", found none.');return o[0]},e.prototype.expectNone=function(e,t){t=t||this.descriptionFromMatcher(e);var o=this.match(e);if(o.length>0)throw new Error('Expected zero matching operations for criteria "'+t+'", found '+o.length+".")},e.prototype.verify=function(){var e=this.open;if(e.length>0){var t=e.map((function(e){return e.operation.operationName})).join(", ");throw new Error("Expected no open operations, found "+e.length+": "+t)}},e.prototype.isDocumentNode=function(e){return!e.operationName},e.prototype.descriptionFromMatcher=function(e){return"string"==typeof e?"Match operationName: "+e:"object"==typeof e?this.isDocumentNode(e)?"Match DocumentNode":"Match operation: "+(e.operationName||"(any)")+", variables: "+(JSON.stringify(e.variables)||"(any)"):"Match by function: "+e.name},e}();c.decorators=[{type:r.Injectable}];var u=new r.InjectionToken("apollo-angular/testing cache"),s=new r.InjectionToken("apollo-angular/testing named cache"),l=new r.InjectionToken("apollo-angular/testing named clients");var f=function(e,t,r,n,i){function a(e,r){return{link:new o.ApolloLink((function(o){return t.handle(function(e,t){return t.clientName=e,t}(e,o))})),cache:r||new o.InMemoryCache({addTypename:!1})}}e.create(a("default",n)),r&&r.length&&r.forEach((function(t){var o=i&&"object"==typeof i?i:{};e.createNamed(t,a(t,o[t]))}))};f.decorators=[{type:r.NgModule,args:[{providers:[c,{provide:i,useExisting:c}]}]}],f.ctorParameters=function(){return[{type:t.Apollo},{type:c},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[l]}]},{type:o.ApolloCache,decorators:[{type:r.Optional},{type:r.Inject,args:[u]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[s]}]}]};var h=function(){function e(){}return e.withClients=function(e){return{ngModule:f,providers:[{provide:l,useValue:e}]}},e}();h.decorators=[{type:r.NgModule,args:[{imports:[f]}]}],e.APOLLO_TESTING_CACHE=u,e.APOLLO_TESTING_NAMED_CACHE=s,e.ApolloTestingController=i,e.ApolloTestingModule=h,e.TestOperation=p,e.ɵa=l,e.ɵb=f,e.ɵc=c,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngApolloTesting.umd.min.js.map
\No newline at end of file