You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i am trying to make an es7 template project with moleculer-cli generated project .now it can run with npm run dev without error,
but it can't pass npm test , with errors:
●Test'products'service›Testhooks›encounteredadeclarationexceptionServiceSchemaError: Servicenamecan't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema? 4 | const DbMixin = require("../mixins/db.mixin"); 5 | > 6 | @Service({ | ^ 7 | name: 'products',
8 | // constructOverride: false,
9 | // skipHandler: true,
at Object.parseServiceSchema (../node_modules/moleculer/src/service.js:92:10)
at new Service (../node_modules/moleculer/src/service.js:63:9)
at new ProductsService (products.service.js:6:1)
at new <anonymous> (../node_modules/moleculer-decorators/dist/index.js:128:9)
at ServiceBroker.createService (../node_modules/moleculer/src/service-broker.js:801:14)
at Suite.<anonymous> (../test/unit/services/products.spec.js:149:10)
at Suite.<anonymous> (../test/unit/services/products.spec.js:146:2)
at Object.<anonymous> (../test/unit/services/products.spec.js:9:1)
the error was begin from :
products.spec.js
...
describe("Test hooks",()=>{constbroker=newServiceBroker({logger: false});constcreateActionFn=jest.fn();broker.createService(TestService,{// <- error start from here, while it try to merge mock action to TestService Schemaactions: {create: {handler: createActionFn}}});
...
}
and createService run into :
...
createService(schema,schemaMods){letservice;schema=this.normalizeSchemaConstructor(schema);if(Object.prototype.isPrototypeOf.call(this.ServiceFactory,schema)){service=newschema(this,schemaMods);// <- run into here to new Decoratored Schema, but it with schemaMods, this is why it throws error , beacause `new service(broker, schemaMods)` will call parseServiceSchema, it will check name of schemaMods , but shemaMods don't have name properties. see bellow code . }else{lets=schema;if(schemaMods)s=this.ServiceFactory.mergeSchemas(schema,schemaMods);console.log('s',s);service=newthis.ServiceFactory(this,s);}}
...
i notice that , moleculer-decorators return Service as :
returnclassextendsparentService.constructor{constructor(broker,schema){// <- new schema(this, schemaMods) super(broker,schema);// <- here, it will call `Moleculer.Service`, with params broker and schemaMods this.parseServiceSchema(base);}};};
classService{
...
constructor(broker,schema){if(!isObject(broker))thrownewServiceSchemaError("Must set a ServiceBroker instance!");this.broker=broker;if(broker)this.Promise=broker.Promise;if(schema)this.parseServiceSchema(schema);// <- ran into here }/** * Parse Service schema & register as local service * * @param {Object} schema of Service */parseServiceSchema(schema){if(!isObject(schema))thrownewServiceSchemaError("The service schema can't be null. Maybe is it not a service schema?");this.originalSchema=_.cloneDeep(schema);if(schema.mixins){schema=Service.applyMixins(schema);}if(isFunction(schema.merged)){schema.merged.call(this,schema);}elseif(Array.isArray(schema.merged)){schema.merged.forEach(fn=>fn.call(this,schema));}this.broker.callMiddlewareHookSync("serviceCreating",[this,schema]);if(!schema.name){// <- error throws hereconsole.error("Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema?",{ schema });thrownewServiceSchemaError("Service name can't be empty! Maybe it is not a valid Service schema. Maybe is it not a service schema?",{ schema });}
...
The text was updated successfully, but these errors were encountered:
i am trying to make an es7 template project with moleculer-cli generated project .now it can run with
npm run dev
without error,but it can't pass npm test , with errors:
the error was begin from :
products.spec.js
and createService run into :
i notice that , moleculer-decorators return Service as :
ref
The text was updated successfully, but these errors were encountered: