How to use getFactory method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

type-mapper-definition.js

Source:type-mapper-definition.js Github

copy

Full Screen

...47 */48 TypeMapperDefinition.prototype.getVariableDeclarations = function () {49 var variableDeclarations = [];50 var self = this;51 var ballerinaASTFactory = this.getFactory();52 _.forEach(this.getChildren(), function (child) {53 if (ballerinaASTFactory.isVariableDeclaration(child)) {54 variableDeclarations.push(child);55 }56 });57 return variableDeclarations;58 };59 /**60 * Add variable declaration61 * @param newVariableDeclaration62 */63 TypeMapperDefinition.prototype.addVariableDeclaration = function (newVariableDeclaration) {64 // Get the index of the last variable declaration.65 var self = this;66 var ballerinaASTFactory = this.getFactory();67 var index = _.findLastIndex(this.getChildren(), function (child) {68 return ballerinaASTFactory.isVariableDeclaration(child);69 });70 this.addChild(newVariableDeclaration, index + 1);71 };72 /**73 * Remove variable declaration74 * @param variableDeclarationIdentifier75 */76 TypeMapperDefinition.prototype.removeVariableDeclaration = function (variableDeclarationIdentifier) {77 var self = this;78 var ballerinaASTFactory = this.getFactory();79 // Removing the variable from the children.80 var variableDeclarationChild = _.find(this.getChildren(), function (child) {81 return ballerinaASTFactory.isVariableDeclaration(child)82 && child.getIdentifier() === variableDeclarationIdentifier;83 });84 this.removeChild(variableDeclarationChild);85 };86 /**87 * Gets the return type88 * @return {string} - Return type.89 */90 TypeMapperDefinition.prototype.getReturnType = function () {91 var returnType = 'ReturnType';92 var ballerinaASTFactory = this.getFactory();93 _.forEach(this.getChildren(), function (child) {94 if (ballerinaASTFactory.isReturnType(child)) {95 returnType = child.getType();96 }97 });98 return returnType;99 };100 /**101 * returns the input parameter and its identifier102 * @returns {String} argument103 */104 TypeMapperDefinition.prototype.getInputParamAndIdentifier = function () {105 var inputParamAndIdentifier = 'InputType inputIdentifier';106 var ballerinaASTFactory = this.getFactory();107 _.forEach(this.getChildren(), function (child) {108 if (ballerinaASTFactory.isResourceParameter(child)) {109 inputParamAndIdentifier = child.getArgumentAsString();110 }111 });112 return inputParamAndIdentifier;113 };114 /**115 * removes the already selected child before adding a new child116 */117 TypeMapperDefinition.prototype.removeResourceParameter = function () {118 var self = this;119 var ballerinaASTFactory = this.getFactory();120 var previousInputType = _.find(this.getChildren(), function (child) {121 return ballerinaASTFactory.isResourceParameter(child)122 });123 var blockStatement = self.getBlockStatement();124 _.find(blockStatement.getChildren(), function (child) {125 if (ballerinaASTFactory.isAssignmentStatement(child)) {126 child.remove();127 }128 });129 if (!_.isUndefined(previousInputType)) {130 this.removeChild(previousInputType);131 }132 };133 /**134 * removes the already selected child before adding a new child135 */136 TypeMapperDefinition.prototype.removeReturnType = function () {137 var self = this;138 var ballerinaASTFactory = this.getFactory();139 var previousOutputType = _.find(this.getChildren(), function (child) {140 return ballerinaASTFactory.isReturnType(child)141 });142 var blockStatement = self.getBlockStatement();143 _.find(blockStatement.getChildren(), function (child) {144 if (ballerinaASTFactory.isAssignmentStatement(child)) {145 child.remove();146 }147 });148 if (!_.isUndefined(previousOutputType)) {149 this.removeChild(previousOutputType);150 }151 };152 /**153 * Adds new resource parameter.154 * @param {string} typeStructName155 * @param {string} identifier156 */157 TypeMapperDefinition.prototype.addResourceParameterChild = function (typeStructName, identifier) {158 // Creating a new ResourceParameter.159 var newResourceParameter = this.getFactory().createResourceParameter();160 newResourceParameter.setIdentifier(identifier);161 newResourceParameter.setType(typeStructName);162 var lastIndex = _.findLastIndex(this.getChildren());163 this.addChild(newResourceParameter, lastIndex - 1);164 };165 /**166 * Adds new return type.167 * @param {string} typeStructName168 * @param {string} identifier169 */170 TypeMapperDefinition.prototype.addReturnTypeChild = function (typeStructName, identifier) {171 // Creating a new ResourceParameter.172 var newReturnType = this.getFactory().createReturnType();173 newReturnType.setType(typeStructName);174 var lastIndex = _.findLastIndex(this.getChildren());175 this.addChild(newReturnType, lastIndex - 1);176 };177 /**178 * fill return statement.179 * @param {string} identifier180 */181 TypeMapperDefinition.prototype.fillReturnStatement = function (identifier) {182 var self = this;183 var ballerinaASTFactory = this.getFactory();184 var blockStatement = _.find(self.getChildren(), function (child) {185 return ballerinaASTFactory.isBlockStatement(child);186 });187 var returnStatement = _.find(blockStatement.getChildren(), function (child) {188 return ballerinaASTFactory.isReturnStatement(child);189 });190 var variableReferenceExpression = _.find(returnStatement.getChildren(), function (child) {191 return ballerinaASTFactory.isVariableReferenceExpression(child);192 });193 variableReferenceExpression.setVariableReferenceName(identifier);194 };195 /**196 * fill return statement.197 * @param {string} identifier198 */199 TypeMapperDefinition.prototype.fillVariableDefStatement = function (structName, identifier) {200 var self = this;201 var ballerinaASTFactory = this.getFactory();202 var blockStatement = _.find(self.getChildren(), function (child) {203 return ballerinaASTFactory.isBlockStatement(child);204 });205 var variableDefStatement = _.find(blockStatement.getChildren(), function (child) {206 return ballerinaASTFactory.isVariableDefinitionStatement(child);207 });208 variableDefStatement.setLeftExpression(structName + " " + identifier);209 };210 /**211 * Adds new variable definition statement.212 * @param {string} typeStructName213 * @param {string} identifier214 */215 TypeMapperDefinition.prototype.addVariableDefinitionStatement = function (typeStructName, identifier) {216 // Creating a new ResourceParameter.217 var newReturnType = this.getFactory().createReturnType();218 var newStructType = this.getFactory().createStructType();219 newStructType.setTypeName(typeStructName);220 var newSymbolName = this.getFactory().createSymbolName();221 newSymbolName.setName(identifier);222 newReturnType.addChild(newStructType);223 newReturnType.addChild(newSymbolName);224 this.addChild(newReturnType);225 };226 /**227 * Constructs new assignment statement.228 * @param sourceIdentifier229 * @param targetIdentifier230 * @param sourceValue231 * @param targetValue232 * @param isComplexMapping233 * @param targetCastValue234 * @returns {AssignmentStatement}235 */236 TypeMapperDefinition.prototype.returnConstructedAssignmentStatement = function (sourceIdentifier, targetIdentifier, sourceValue, targetValue,237 isComplexMapping, targetCastValue) {238 // Creating a new Assignment Statement.239 var self = this;240 var newAssignmentStatement = this.getFactory().createAssignmentStatement();241 var leftOperandExpression = this.getFactory().createLeftOperandExpression();242 var rightOperandExpression = this.getFactory().createRightOperandExpression();243 var typeCastExpression = undefined;244 var sourceStructFieldAccessExpression = this.getFactory().createStructFieldAccessExpression();245 var sourceVariableReferenceExpressionForIdentifier = this.getFactory().createVariableReferenceExpression();246 sourceVariableReferenceExpressionForIdentifier.setVariableReferenceName(sourceIdentifier);247 var sourceFieldExpression = this.getFactory().createStructFieldAccessExpression();248 var tempRefOfFieldExpression;249 _.forEach(sourceValue, function (sourceVal) {250 var tempFieldExpression;251 var tempVariableReferenceExpression = self.getFactory().createVariableReferenceExpression();252 tempVariableReferenceExpression.setVariableReferenceName(sourceVal);253 if (_.head(sourceValue) == sourceVal) {254 sourceFieldExpression.addChild(tempVariableReferenceExpression);255 tempRefOfFieldExpression = sourceFieldExpression256 } else {257 tempFieldExpression = self.getFactory().createStructFieldAccessExpression();258 tempFieldExpression.addChild(tempVariableReferenceExpression);259 tempRefOfFieldExpression.addChild(tempFieldExpression);260 tempRefOfFieldExpression = tempFieldExpression;261 }262 });263 sourceStructFieldAccessExpression.addChild(sourceVariableReferenceExpressionForIdentifier);264 sourceStructFieldAccessExpression.addChild(sourceFieldExpression);265 var targetStructFieldAccessExpression = this.getFactory().createStructFieldAccessExpression();266 var targetVariableReferenceExpressionForIdentifier = this.getFactory().createVariableReferenceExpression();267 targetVariableReferenceExpressionForIdentifier.setVariableReferenceName(targetIdentifier);268 var targetFieldExpression = this.getFactory().createStructFieldAccessExpression();269 var tempRefOfFieldExpression;270 _.forEach(targetValue, function (targetVal) {271 var tempFieldExpression;272 var tempVariableReferenceExpression = self.getFactory().createVariableReferenceExpression();273 tempVariableReferenceExpression.setVariableReferenceName(targetVal);274 if (_.head(targetValue) == targetVal) {275 targetFieldExpression.addChild(tempVariableReferenceExpression);276 tempRefOfFieldExpression = targetFieldExpression277 } else {278 tempFieldExpression = self.getFactory().createStructFieldAccessExpression();279 tempFieldExpression.addChild(tempVariableReferenceExpression);280 tempRefOfFieldExpression.addChild(tempFieldExpression);281 tempRefOfFieldExpression = tempFieldExpression;282 }283 });284 targetStructFieldAccessExpression.addChild(targetVariableReferenceExpressionForIdentifier);285 targetStructFieldAccessExpression.addChild(targetFieldExpression);286 leftOperandExpression.addChild(targetStructFieldAccessExpression);287 newAssignmentStatement.addChild(leftOperandExpression);288 if (isComplexMapping) {289 typeCastExpression = this.getFactory().createTypeCastExpression();290 typeCastExpression.setName(targetCastValue);291 rightOperandExpression.addChild(typeCastExpression);292 typeCastExpression.addChild(sourceStructFieldAccessExpression);293 } else {294 rightOperandExpression.addChild(sourceStructFieldAccessExpression);295 }296 newAssignmentStatement.addChild(rightOperandExpression);297 return newAssignmentStatement;298 };299 /**300 * 301 * @param identifier302 * @param properties303 * @returns {*}304 */305 TypeMapperDefinition.prototype.getStructFieldAccessExpression = function (identifier, properties) {306 var self = this;307 var structFieldAccessExpression = this.getFactory().createStructFieldAccessExpression();308 var variableReferenceExpression = this.getFactory().createVariableReferenceExpression();309 variableReferenceExpression.setVariableReferenceName(identifier);310 var targetFieldExpression = this.getFactory().createStructFieldAccessExpression();311 var tempRefOfFieldExpression;312 _.forEach(properties, function (property) {313 var tempFieldExpression;314 var tempVariableReferenceExpression = self.getFactory().createVariableReferenceExpression();315 tempVariableReferenceExpression.setVariableReferenceName(property);316 if (_.head(properties) == property) {317 targetFieldExpression.addChild(tempVariableReferenceExpression);318 tempRefOfFieldExpression = targetFieldExpression319 } else {320 tempFieldExpression = self.getFactory().createStructFieldAccessExpression();321 tempFieldExpression.addChild(tempVariableReferenceExpression);322 tempRefOfFieldExpression.addChild(tempFieldExpression);323 tempRefOfFieldExpression = tempFieldExpression;324 }325 });326 structFieldAccessExpression.addChild(variableReferenceExpression);327 structFieldAccessExpression.addChild(targetFieldExpression);328 return structFieldAccessExpression;329 };330 /**331 * Gets the reference of block statement child332 * @return {string} - String blockStatement.333 */334 TypeMapperDefinition.prototype.getBlockStatement = function () {335 var blockStatement = undefined;336 var ballerinaASTFactory = this.getFactory();337 _.forEach(this.getChildren(), function (child) {338 if (ballerinaASTFactory.isBlockStatement(child)) {339 blockStatement = child;340 return false;341 }342 });343 return blockStatement;344 };345 /**346 * @inheritDoc347 * @override348 */349 TypeMapperDefinition.prototype.generateUniqueIdentifiers = function () {350 CommonUtils.generateUniqueIdentifier({351 node: this,352 attributes: [{353 defaultValue: "newTypeMapper",354 setter: this.setTypeMapperName,355 getter: this.getTypeMapperName,356 parents: [{357 node: this.parent,358 getChildrenFunc: this.parent.getTypeMapperDefinitions,359 getter: this.getTypeMapperName360 }]361 }]362 });363 };364 /**365 * Initialize TypeMapperDefinition from json object366 * @param {Object} jsonNode - JSON object for initialization.367 * @param {string} jsonNode.type_mapper_name - Name of the type mapper definition.368 */369 TypeMapperDefinition.prototype.initFromJson = function (jsonNode) {370 var ballerinaASTFactory = this.getFactory();371 var self = this;372 this.setTypeMapperName(jsonNode.type_mapper_name, {doSilently: true});373 var returnNode = undefined;374 _.each(jsonNode.children, function (childNode) {375 if(childNode.type === 'return_type'){376 returnNode = childNode;377 }else{378 var child = ballerinaASTFactory.createFromJson(childNode);379 self.addChild(child);380 child.initFromJson(childNode);381 }382 });383 var blockStatementNode = ballerinaASTFactory.createBlockStatement();384 var childrenArray = self.getChildren();...

Full Screen

Full Screen

logic.js

Source:logic.js Github

copy

Full Screen

...25 // Get the asset registry for the asset.26 const assetRegistry = await getAssetRegistry('org.example.mynetwork.Package');27 // Update the asset in the asset registry.28 await assetRegistry.update(tx.batch); 29 const contract = getFactory().newResource('org.example.mynetwork', 'makeContract', 'CON_001');30 contract.manufacturer = getFactory().newRelationship('org.example.mynetwork', 'Manufacturer', '');31 contract.shipper = getFactory().newRelationship('org.example.mynetwork', 'Shipper', '');32 contract.wholesaleperson = getFactory().newRelationship('org.example.mynetwork', 'Wholesaleperson', '');33 contract.retailer = getFactory().newRelationship('org.example.mynetwork', 'Retailer', '');34 contract.box = getFactory().newRelationship('org.example.mynetwork', 'Package', '');35 const today = shipping.timestamp;36 contract.startDateTime = today; // the contract created at this time37 contract.status = 'SHIPPED' //giving status of shipment38 const contractRegistry = await getAssetRegistry('org.example.mynetwork.makeContract');39 await contractRegistry.addAll([contract]);40 // Emit an event for changing ownership41 let event = getFactory().newEvent('org.example.mynetwork', 'changeOwner');42 event.batch = tx.batch;43 event.oldOwner = oldOwnerId;44 event.newOwner = tx.newOwner.id;45 emit(event);46}47/**48 * Giving ownership to wholesaleperson49 * @param {org.example.mynetwork.Wholesale} wtx The transaction instance.50 * @transaction51 */52async function wholesale(wtx) {53 // Save the old value of the asset.54 const oldOwnerId = wtx.batch.ownerId;55 // Update the asset with the new value.56 wtx.batch.ownerId = wtx.newOwner.id;57 const contract = wtx.start;58 contract.status = 'WHOLESALE';59 // Get the asset registry for the asset.60 const assetRegistry = await getAssetRegistry('org.example.mynetwork.Package');61 // Update the asset in the asset registry.62 await assetRegistry.update(wtx.batch); 63 const contractRegistry = await getAssetRegistry('org.example.mynetwork.makeContract');64 await contractRegistry.update(wtx.start);65 // Emit an event for changing ownership66 let event = getFactory().newEvent('org.example.mynetwork', 'changeOwner');67 event.batch = wtx.batch;68 event.oldOwner = oldOwnerId;69 event.newOwner = wtx.newOwner.id;70 emit(event);71}72/**73 * Giving ownership to retailer and ending contract74 * @param {org.example.mynetwork.Retail} rtx The transaction instance75 * @transaction 76 */77 async function retail(rtx) {78 // Save the old value of the asset.79 const oldOwnerId = rtx.batch.ownerId;80 // Update the asset with the new value.81 rtx.batch.ownerId = rtx.newOwner.id;82 83 const contract = rtx.start;84 contract.status = 'RETAIL';85 const assetRegistry = await getAssetRegistry('org.example.mynetwork.Package');86 // Update the asset in the asset registry.87 await assetRegistry.update(rtx.batch); 88 const contractRegistry = await getAssetRegistry('org.example.mynetwork.makeContract');89 await contractRegistry.update(rtx.start);90 const econtract = getFactory().newResource('org.example.mynetwork', 'endContract', 'ECON_001');91 econtract.manufacturer = getFactory().newRelationship('org.example.mynetwork', 'Manufacturer', '');92 econtract.shipper = getFactory().newRelationship('org.example.mynetwork', 'Shipper', '');93 econtract.wholesaleperson = getFactory().newRelationship('org.example.mynetwork', 'Wholesaleperson', '');94 econtract.retailer = getFactory().newRelationship('org.example.mynetwork', 'Retailer', '');95 econtract.box = getFactory().newRelationship('org.example.mynetwork', 'Package', '');96 econtract.initContract = getFactory().newRelationship('org.example.mynetwork', 'makeContract', 'CON_001');97 const today = retail.timestamp;98 econtract.endTime = today; // the contract created at this time99 econtract.status = 'RETAIL' //giving status of shipment100 const econtractRegistry = await getAssetRegistry('org.example.mynetwork.endContract');101 await econtractRegistry.addAll([econtract]);102 // Emit an event for changing ownership103 let event = getFactory().newEvent('org.example.mynetwork', 'changeOwner');104 event.batch = wtx.batch;105 event.oldOwner = oldOwnerId;106 event.newOwner = wtx.newOwner.id;107 emit(event);108}109/**110 * A temperature reading has been received for a shipment111 * @param {org.example.mynetwork.TemperatureReading} temperatureReading - the TemperatureReading transaction112 * @transaction113 */114async function temperatureReading(temperatureReading) { // eslint-disable-line no-unused-vars115 const box = temperatureReading.package;116 console.log('Adding temperature ' + temperatureReading.mean + ' to shipment ' + box.$identifier);117 if (box.temperature_cur) {118 box.temperature_cur.push(temperatureReading);119 } else {120 box.temperature_cur = [temperatureReading];121 }122 // add the temp reading to the shipment123 const shipmentRegistry = await getAssetRegistry('org.example.mynetwork.Package');124 await shipmentRegistry.update(box);125}126/**127 * A geographic location has been received for a shipment128 * @param {org.example.mynetwork.LocationReading} locationReading - the LocationReading transaction129 * @transaction130 */131async function locationReading(locationReading) { // eslint-disable-line no-unused-vars132 const box = locationReading.package;133 console.log('Adding location ' + locationReading.coordinate + ' to shipment ' + box.$identifier);134 if (box.location) {135 box.location.push(locationReading);136 } else {137 box.location = [locationReading];138 }139 // add the location reading to the shipment140 const shipmentRegistry = await getAssetRegistry('org.example.mynetwork.Package');141 await shipmentRegistry.update(box);142}143/**144 * Creating new package145 * @param {org.example.mynetwork.createPackage} cptx The transaction instance.146 * @transaction147 */148 async function CreatePackage(cptx) {149 const shipment = getFactory().newResource('org.example.mynetwork', 'Package', 'BAT_0001');150 shipment.shipmentId = '314f';151 shipment.expirydate = '';152 shipment.unitCount = 5000;153 shipment.meanTemperature = 5;154 shipment.ownerId = '1232';155 shipment.owner = getFactory().newRelationship('org.example.mynetwork', 'Manufacturer', 'M_0001');156 //adding the package157 const shipmentRegistry = await getAssetRegistry('org.example.mynetwork.Package');158 await shipmentRegistry.addAll([shipment]);159}160/**161 * Creating new manufacturer162 * @param {org.example.mynetwork.createManufacturer} cmtx The transaction instance163 * @transaction164 */165 async function CreateManufacturer (cmtx) {166 const manufacturer = getFactory().newResource('org.example.mynetwork', 'Manufacturer', 'MAN_0001');167 const manufacturerAddress = getFactory().newConcept('org.example.mynetwork','Address');168 manufacturer.firstName = 'ABC';169 manufacturer.lastName = 'DEF';170 manufacturerAddress.city = 'XYZ';171 manufacturerAddress.zip = '111111';172 manufacturerAddress.state = 'PQR';173 manufacturer.address = manufacturerAddress;174 //adding the manufacturer175 const manufacturerRegistry = await getParticipantRegistry('org.example.mynetwork.Manufacturer');176 await manufacturerRegistry.addAll([manufacturer]);177}178/**179 * Creating new shipper180 * @param {org.example.mynetwork.createShipper} cstx The transaction instance181 * @transaction182 */183async function CreateShipper (cstx) {184 const shipper = getFactory().newResource('org.example.mynetwork', 'Shipper', 'SH_0001');185 const shipperAddress = getFactory().newConcept('org.example.mynetwork', 'Address');186 shipper.firstName = 'AAA';187 shipper.lastName = 'BBB';188 shipperAddress.city = 'XXX';189 shipperAddress.zip = '000000';190 shipperAddress.state = 'PPP';191 shipper.address = shipperAddress;192 //adding the shipper193 const shipperRegistry = await getParticipantRegistry('org.example.mynetwork.Shipper');194 await shipperRegistry.addAll([shipper]);195}196/**197 * Creating new wholesaleperson198 * @param {org.example.mynetwork.createWholesaleperson} cwtx The transaction instance199 * @transaction200 */201async function CreateWholesaleperson (cwtx) {202 const wholesaleperson = getFactory().newResource('org.example.mynetwork', 'Wholesaleperson', 'W_0001');203 const wholesalepersonAddress = getFactory().newConcept('org.example.mynetwork', 'Address');204 wholesaleperson.firstName = 'CCC';205 wholesaleperson.lastName = 'DDD';206 wholesalepersonAddress.city = 'YYY';207 wholesalepersonAddress.zip = '222222';208 wholesalepersonAddress.state = 'QQQ';209 wholesaleperson.address = wholesalepersonAddress;210 //adding the wholesaleperson211 const wholesalepersonRegistry = await getParticipantRegistry('org.example.mynetwork.Wholesaleperson');212 await wholesalepersonRegistry.addAll([wholesaleperson]);213}214/**215 * Creating new retailer216 * @param {org.example.mynetwork.createRetailer} crtx The transaction instance217 * @transaction218 */219async function CreateRetailer (crtx) {220 const retailer = getFactory().newResource('org.example.mynetwork', 'Retailer', 'RE_0001');221 const retailerAddress = getFactory().newConcept('org.example.mynetwork', 'Address');222 retailer.firstName = 'EEE';223 retailer.lastName = 'FFF';224 retailerAddress.city = 'ZZZ';225 retailerAddress.zip = '333333';226 retailerAddress.state = 'RRR';227 retailer.address = retailerAddress228 //adding the retailer229 const retailerRegistry = await getParticipantRegistry('org.example.mynetwork.Retailer');230 await retailerRegistry.addAll([retailer]);...

Full Screen

Full Screen

TypeList.test.js

Source:TypeList.test.js Github

copy

Full Screen

...53 });54 });55 describe("getFactory", () => {56 it("gets default factory function on empty list", () => {57 expect(typeList.getFactory('foo')).toBe(defaultFactory);58 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);59 });60 it("gets a factory function with single token", () => {61 typeList.addFactory('foo', fa);62 expect(typeList.getFactory('foo')).toBe(fa);63 expect(typeList.getFactory('bar')).toBe(defaultFactory);64 });65 it("gets a factory function without using wildcards", () => {66 typeList.addFactory('foo.b', fa);67 expect(typeList.getFactory('foo.b')).toBe(fa);68 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);69 });70 it("gets a factory function using * wildcard", () => {71 typeList.addFactory('foo.*', fa);72 expect(typeList.getFactory('foo.bar')).toBe(fa);73 expect(typeList.getFactory('foo.bar.baz')).toBe(defaultFactory);74 });75 it("gets a factory function using > wildcard", () => {76 typeList.addFactory('foo.>', fa);77 expect(typeList.getFactory('foo.bar')).toBe(fa);78 expect(typeList.getFactory('foo.bar.baz')).toBe(fa);79 });80 it("gets a factory function using only * wildcard", () => {81 typeList.addFactory('*', fa);82 expect(typeList.getFactory('foo')).toBe(fa);83 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);84 });85 it("gets a factory function using only > wildcard", () => {86 typeList.addFactory('>', fa);87 expect(typeList.getFactory('foo')).toBe(fa);88 expect(typeList.getFactory('foo.bar')).toBe(fa);89 });90 it("gets default factory function on partial match", () => {91 typeList.addFactory('foo.bar', fa);92 expect(typeList.getFactory('foo')).toBe(defaultFactory);93 });94 });95 describe("removeFactory", () => {96 it("gets default factory function after removing without wildcard", () => {97 typeList.addFactory('foo', fa);98 expect(typeList.removeFactory('foo')).toBe(fa);99 expect(typeList.getFactory('foo')).toBe(defaultFactory);100 typeList.addFactory('foo.bar', fa);101 expect(typeList.removeFactory('foo.bar')).toBe(fa);102 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);103 });104 it("gets default factory function after removing * wildcard", () => {105 typeList.addFactory('foo.*', fa);106 typeList.addFactory('foo.bar.*', fb);107 expect(typeList.removeFactory('foo.*')).toBe(fa);108 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);109 expect(typeList.getFactory('foo.bar.baz')).toBe(fb);110 });111 it("gets default factory function after removing > wildcard", () => {112 typeList.addFactory('foo.>', fa);113 expect(typeList.removeFactory('foo.>')).toBe(fa);114 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);115 expect(typeList.getFactory('foo.bar.baz')).toBe(defaultFactory);116 });117 it("gets a default factory function removing only * wildcard", () => {118 typeList.addFactory('*', fa);119 expect(typeList.removeFactory('*')).toBe(fa);120 expect(typeList.getFactory('foo')).toBe(defaultFactory);121 });122 it("gets a default factory function removing only > wildcard", () => {123 typeList.addFactory('>', fa);124 expect(typeList.removeFactory('>')).toBe(fa);125 expect(typeList.getFactory('foo')).toBe(defaultFactory);126 expect(typeList.getFactory('foo.bar')).toBe(defaultFactory);127 });128 it("gets factory function on match after removing longer pattern", () => {129 typeList.addFactory('foo', fa);130 typeList.addFactory('foo.bar', fb);131 expect(typeList.removeFactory('foo.bar')).toBe(fb);132 expect(typeList.getFactory('foo')).toBe(fa);133 });134 });135 describe("factory priority", () => {136 it("matches text before * wildcard", () => {137 typeList.addFactory('foo.bar', fa);138 typeList.addFactory('foo.*', fb);139 expect(typeList.getFactory('foo.bar')).toBe(fa);140 });141 it("matches text before > wildcard", () => {142 typeList.addFactory('foo.bar', fa);143 typeList.addFactory('foo.>', fb);144 expect(typeList.getFactory('foo.bar')).toBe(fa);145 });146 it("matches * wildcard before > wildcard", () => {147 typeList.addFactory('foo.*', fa);148 typeList.addFactory('foo.>', fb);149 expect(typeList.getFactory('foo.bar')).toBe(fa);150 });151 it("matches tokens with priority left to right", () => {152 typeList.addFactory('foo.bar.>', fa);153 typeList.addFactory('foo.*.baz', fb);154 typeList.addFactory('foo.>', fb);155 expect(typeList.getFactory('foo.bar.baz')).toBe(fa);156 });157 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getFactory } from 'ts-auto-mock';2import { type } from 'ts-auto-mock';3import { mock } from 'ts-auto-mock';4import { Mock } from 'ts-auto-mock';5import { mockAll } from 'ts-auto-mock';6import { MockAll } from 'ts-auto-mock';7import { mockPartial } from 'ts-auto-mock';8import { MockPartial } from 'ts-auto-mock';9import { mockFunction } from 'ts-auto-mock';10import { MockFunction } from 'ts-auto-mock';11import { mockStatic } from 'ts-auto-mock';12import { MockStatic } from 'ts-auto-mock';13import { mockReset } from 'ts-auto-mock';14import { mockDeep } from 'ts-auto-mock';15import { MockDeep } from 'ts-auto-mock';16import { mockInterface } from 'ts-auto-mock';17import { MockInterface } from 'ts-auto-mock';18import { mockInstanceOf } from 'ts-auto-mock';19import { MockInstanceOf } from 'ts-auto-mock';20import { mockAuto } from 'ts-auto-mock';21import { MockAuto } from 'ts-auto-mock';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {getFactory} from 'ts-auto-mock';2const factory = getFactory();3const mock = factory.create<MyClass>();4console.log(mock);5import {getMock} from 'ts-auto-mock';6const mock = getMock<MyClass>();7console.log(mock);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getFactory } from 'ts-auto-mock';2import { IMyInterface } from './myInterface';3const factory = getFactory<IMyInterface>();4const myMock = factory.create();5myMock.myMethod();6describe('test1', () => {7 it('should be able to use the mock', () => {8 expect(myMock.myMethod()).toBe(1);9 });10});11import { getFactory } from 'ts-auto-mock';12import { IMyInterface } from './myInterface';13const factory = getFactory<IMyInterface>();14const myMock = factory.create();15myMock.myMethod();16describe('test2', () => {17 it('should be able to use the mock', () => {18 expect(myMock.myMethod()).toBe(1);19 });20});21import { getFactoryAndMock } from 'ts-auto-mock';22import { IMyInterface } from './myInterface';23const { factory, mock } = getFactoryAndMock<IMyInterface>();24mock.myMethod();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getFactory } from 'ts-auto-mock';2const factory = getFactory<InterfaceName>();3const mock = factory.create();4const mock = factory.create({5});6const mock = factory.create({7}, "name");8const mock = factory.create("name");9const mock = factory.create("name", {10});11const mock = factory.create("name", {12});13const mock = factory.create("name", {14});15const mock = factory.create("name", {16});17const mock = factory.create("name", {18});19const mock = factory.create("name", {20});21const mock = factory.create("name", {22});23const mock = factory.create("name", {24});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getFactory } from 'ts-auto-mock';2const factory = getFactory();3const myObject = factory<IInterface>();4const myObject2 = factory<MyClass>();5const myObject3 = factory<MyClassWithConstructor>(1);6const myObject4 = factory<MyClassWithConstructor>(1, "test");7const myObject5 = factory<MyClassWithConstructor>(1, "test", true);8const myObject6 = factory<MyClassWithConstructor>(1, "test", true, {test: 1});9const myObject7 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3]);10const myObject8 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3], new Date());11const myObject9 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3], new Date(), new Error());12const myObject10 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3], new Date(), new Error(), new RegExp("test"));13const myObject11 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3], new Date(), new Error(), new RegExp("test"), new Set());14const myObject12 = factory<MyClassWithConstructor>(1, "test", true, {test: 1}, [1,2,3], new Date(), new Error(), new RegExp("test"), new Set(), new Map());

Full Screen

Using AI Code Generation

copy

Full Screen

1import {getFactory} from 'ts-auto-mock';2import {Test2} from './test2';3export function test1(): void {4 const factory: Test2 = getFactory<Test2>();5 const result = factory.test2Method();6 console.log(result);7}8export class Test2 {9 test2Method(): string {10 return 'test2';11 }12}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ts-auto-mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful