Best JavaScript code snippet using ng-mocks
ValidatorSpec.js
Source:ValidatorSpec.js
1'use strict';2var Validator = require('lib/provider/activiti/element-templates/Validator');3describe('element-templates - Validator', function() {4 function errors(validator) {5 return validator.getErrors().map(function(e) {6 return e.message;7 });8 }9 function valid(validator) {10 return validator.getValidTemplates();11 }12 it('should accept vip-ordering example template', function() {13 // given14 var templates = new Validator();15 var templateDescriptors = require('./fixtures/vip-ordering');16 // when17 templates.addAll(templateDescriptors);18 // then19 expect(errors(templates)).to.be.empty;20 expect(valid(templates)).to.have.length(1);21 });22 it('should accept misc example template', function() {23 // given24 var templates = new Validator();25 var templateDescriptors = require('./fixtures/misc');26 // when27 templates.addAll(templateDescriptors);28 // then29 expect(errors(templates)).to.be.empty;30 expect(valid(templates)).to.have.length(1);31 });32 it('should accept call-activity-variables template', function() {33 // given34 var templates = new Validator();35 var templateDescriptors = require('./fixtures/call-activity-variables');36 // when37 templates.addAll(templateDescriptors);38 // then39 expect(errors(templates)).to.be.empty;40 expect(valid(templates)).to.have.length(1);41 });42 it('should accept dropdown example template', function() {43 // given44 var templates = new Validator();45 var templateDescriptors = require('./fixtures/dropdown');46 // when47 templates.addAll(templateDescriptors);48 // then49 expect(errors(templates)).to.be.empty;50 expect(valid(templates)).to.have.length(1);51 });52 it('should reject missing id', function() {53 // given54 var templates = new Validator();55 var templateDescriptors = require('./fixtures/error-id-missing');56 // when57 templates.addAll(templateDescriptors);58 // then59 expect(errors(templates)).to.contain('missing template id');60 expect(valid(templates)).to.be.empty;61 });62 it('should reject duplicate id', function() {63 // given64 var templates = new Validator();65 var templateDescriptors = require('./fixtures/error-id-duplicate');66 // when67 templates.addAll(templateDescriptors);68 // then69 expect(errors(templates)).to.contain('template id <foo> already used');70 expect(valid(templates)).to.have.length(1);71 });72 it('should reject missing appliesTo', function() {73 // given74 var templates = new Validator();75 var templateDescriptors = require('./fixtures/error-appliesTo-missing');76 // when77 templates.addAll(templateDescriptors);78 // then79 expect(errors(templates)).to.contain('template(id: foo) missing appliesTo=[]');80 expect(valid(templates)).to.be.empty;81 });82 it('should reject missing properties', function() {83 // given84 var templates = new Validator();85 var templateDescriptors = require('./fixtures/error-properties-missing');86 // when87 templates.addAll(templateDescriptors);88 // then89 expect(errors(templates)).to.contain('template(id: foo) missing properties=[]');90 expect(valid(templates)).to.be.empty;91 });92 it('should reject missing dropdown choices', function() {93 // given94 var templates = new Validator();95 var templateDescriptors = require('./fixtures/error-dropdown-choices-missing');96 // when97 templates.addAll(templateDescriptors);98 // then99 expect(errors(templates)).to.eql([100 'must provide choices=[] with Dropdown type'101 ]);102 expect(valid(templates)).to.be.empty;103 });104 it('should reject invalid dropdown choices', function() {105 // given106 var templates = new Validator();107 var templateDescriptors = require('./fixtures/error-dropdown-choices-invalid');108 // when109 templates.addAll(templateDescriptors);110 // then111 expect(errors(templates)).to.eql([112 '{ name, value } must be specified for Dropdown choices'113 ]);114 expect(valid(templates)).to.be.empty;115 });116 it('should reject invalid property', function() {117 // given118 var templates = new Validator();119 var templateDescriptors = require('./fixtures/error-property-invalid');120 // when121 templates.addAll(templateDescriptors);122 // then123 expect(errors(templates)).to.eql([124 'invalid property type <InvalidType>; must be any of { ' +125 'String, Text, Boolean, Hidden, Dropdown ' +126 '}',127 'invalid property.binding type <alsoInvalid>; must be any of { ' +128 'property, activiti:property, activiti:inputParameter, ' +129 'activiti:outputParameter, activiti:in, activiti:out, ' +130 'activiti:in:businessKey, activiti:executionListener, ' +131 'activiti:field ' +132 '}'133 ]);134 expect(valid(templates)).to.be.empty;135 });136 it('should reject invalid bindings', function() {137 // given138 var templates = new Validator();139 var templateDescriptors = require('./fixtures/error-bindings-invalid');140 // when141 templates.addAll(templateDescriptors);142 // then143 expect(errors(templates)).to.eql([144 'property.binding <property> requires name',145 'property.binding <activiti:property> requires name',146 'property.binding <activiti:inputParameter> requires name',147 'property.binding <activiti:outputParameter> requires source',148 'property.binding <activiti:in> requires variables or target',149 'property.binding <activiti:out> requires variables, sourceExpression or source'150 ]);151 expect(valid(templates)).to.be.empty;152 });153 it('should accept type "hidden" for execution listeners', function() {154 // given155 var templates = new Validator();156 var templateDescriptors = require('./fixtures/execution-listener');157 // when158 templates.addAll(templateDescriptors);159 // then160 expect(errors(templates)).to.be.empty;161 expect(valid(templates)).to.have.length(1);162 });163 it('should reject invalid types for execution listeners', function() {164 // given165 var templates = new Validator();166 var templateDescriptors = require('./fixtures/error-execution-listener-invalid-type');167 // when168 templates.addAll(templateDescriptors);169 // then170 expect(errors(templates)).to.eql([171 'invalid property type <String> for activiti:executionListener; must be <Hidden>',172 'invalid property type <Text> for activiti:executionListener; must be <Hidden>',173 'invalid property type <Boolean> for activiti:executionListener; must be <Hidden>',174 'invalid property type <Dropdown> for activiti:executionListener; must be <Hidden>'175 ]);176 expect(valid(templates)).to.have.length(0);177 });178 it('should reject invalid scopes type', function() {179 // given180 var templates = new Validator();181 var templateDescriptors = require('./fixtures/error-scopes-invalid');182 // when183 templates.addAll(templateDescriptors);184 // then185 expect(errors(templates)).to.contain('template(id: foo) invalid scopes, should be scopes={}');186 expect(valid(templates)).to.be.empty;187 });188 it('should reject invalid scopes content', function() {189 // given190 var templates = new Validator();191 var templateDescriptors = require('./fixtures/error-scopes-invalid-scope');192 // when193 templates.addAll(templateDescriptors);194 // then195 expect(errors(templates)).to.contain('template(id: foo) invalid scope, should be scope={}');196 expect(valid(templates)).to.be.empty;197 });198 it('should reject missing scope properties', function() {199 // given200 var templates = new Validator();201 var templateDescriptors = require('./fixtures/error-scopes-properties-missing');202 // when203 templates.addAll(templateDescriptors);204 // then205 expect(errors(templates)).to.contain(206 'template(id: foo) missing properties=[] in scope <activiti:Connector>'207 );208 expect(valid(templates)).to.be.empty;209 });210 it('should reject scope with invalid property', function() {211 // given212 var templates = new Validator();213 var templateDescriptors = require('./fixtures/error-scopes-property-invalid');214 // when215 templates.addAll(templateDescriptors);216 // then217 expect(errors(templates)).to.eql([218 'invalid property type <InvalidType>; must be any of { ' +219 'String, Text, Boolean, Hidden, Dropdown ' +220 '}',221 'invalid property.binding type <alsoInvalid>; must be any of { ' +222 'property, activiti:property, activiti:inputParameter, ' +223 'activiti:outputParameter, activiti:in, activiti:out, ' +224 'activiti:in:businessKey, activiti:executionListener, ' +225 'activiti:field ' +226 '}'227 ]);228 expect(valid(templates)).to.be.empty;229 });230 it('should accept scopes example template', function() {231 // given232 var templates = new Validator();233 var templateDescriptors = require('./fixtures/scopes');234 // when235 templates.addAll(templateDescriptors);236 // then237 expect(errors(templates)).to.be.empty;238 expect(valid(templates)).to.have.length(1);239 });240 it('should accept field injections example template', function() {241 // given242 var templates = new Validator();243 var templateDescriptors = require('./fixtures/field-injections');244 // when245 templates.addAll(templateDescriptors);246 // then247 expect(errors(templates)).to.be.empty;248 expect(valid(templates)).to.have.length(1);249 });...
plugin.js
Source:plugin.js
1/**2 * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license4 */5( function() {6 CKEDITOR.plugins.add( 'templates', {7 requires: 'dialog,ajax',8 // jscs:disable maximumLineLength9 lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,oc,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%10 // jscs:enable maximumLineLength11 icons: 'templates,templates-rtl', // %REMOVE_LINE_CORE%12 hidpi: true, // %REMOVE_LINE_CORE%13 init: function( editor ) {14 CKEDITOR.dialog.add( 'templates', CKEDITOR.getUrl( this.path + 'dialogs/templates.js' ) );15 editor.addCommand( 'templates', new CKEDITOR.dialogCommand( 'templates' ) );16 editor.ui.addButton && editor.ui.addButton( 'Templates', {17 label: editor.lang.templates.button,18 command: 'templates',19 toolbar: 'doctools,10'20 } );21 }22 } );23 var templates = {},24 loadedTemplatesFiles = {};25 /**26 * Adds templates' collection to the list of all available templates.27 *28 * @member CKEDITOR29 * @param {String} name Name of the templates' collection.30 * @param {CKEDITOR.plugins.templates.collectionDefinition} definition Definition of templates' collection.31 */32 CKEDITOR.addTemplates = function( name, definition ) {33 templates[ name ] = definition;34 };35 /**36 * Gets templates' collection by its name.37 *38 * @member CKEDITOR39 * @param {String} name Name of the templates' collection.40 * @returns {CKEDITOR.plugins.templates.collectionDefinition}41 */42 CKEDITOR.getTemplates = function( name ) {43 return templates[ name ];44 };45 /**46 * Loads files that contains templates' collection definition.47 *48 * @member CKEDITOR49 * @param {String[]} templateFiles Array of files' paths.50 * @param {Function} callback Function to be run after loading all files.51 */52 CKEDITOR.loadTemplates = function( templateFiles, callback ) {53 // Holds the templates files to be loaded.54 var toLoad = [];55 // Look for pending template files to get loaded.56 for ( var i = 0, count = templateFiles.length; i < count; i++ ) {57 if ( !loadedTemplatesFiles[ templateFiles[ i ] ] ) {58 toLoad.push( templateFiles[ i ] );59 loadedTemplatesFiles[ templateFiles[ i ] ] = 1;60 }61 }62 if ( toLoad.length )63 CKEDITOR.scriptLoader.load( toLoad, callback );64 else65 setTimeout( callback, 0 );66 };67} )();68/**69 * The templates definition set to use. It accepts a list of names separated by70 * comma. It must match definitions loaded with the {@link #templates_files} setting.71 *72 * config.templates = 'my_templates';73 *74 * @cfg {String} [templates='default']75 * @member CKEDITOR.config76 */77/**78 * The list of templates definition files to load.79 *80 * config.templates_files = [81 * '/editor_templates/site_default.js',82 * 'http://www.example.com/user_templates.js'83 * ];84 *85 * For a sample template file86 * [see `templates/default.js`](https://github.com/ckeditor/ckeditor4/blob/master/plugins/templates/templates/default.js).87 * For more information on template definiton see {@link CKEDITOR.plugins.templates.collectionDefinition}.88 *89 * @cfg {String[]}90 * @member CKEDITOR.config91 */92CKEDITOR.config.templates_files = [93 CKEDITOR.getUrl( 'plugins/templates/templates/default.js' )94];95/**96 * Whether the "Replace actual contents" checkbox is checked by default in the97 * Templates dialog.98 *99 * config.templates_replaceContent = false;100 *101 * @cfg {Boolean}102 * @member CKEDITOR.config103 */...
ElementTemplatesLoader.js
Source:ElementTemplatesLoader.js
1'use strict';2var Validator = require('./Validator');3/**4 * The guy responsible for template loading.5 *6 * Provide the actual templates via the `config.elementTemplates`.7 *8 * That configuration can either be an array of template9 * descriptors or a node style callback to retrieve10 * the templates asynchronously.11 *12 * @param {Array<TemplateDescriptor>|Function} loadTemplates13 * @param {EventBus} eventBus14 * @param {ElementTemplates} elementTemplates15 */16function ElementTemplatesLoader(loadTemplates, eventBus, elementTemplates) {17 this._loadTemplates = loadTemplates;18 this._eventBus = eventBus;19 this._elementTemplates = elementTemplates;20 var self = this;21 eventBus.on('diagram.init', function() {22 self.reload();23 });24}25module.exports = ElementTemplatesLoader;26ElementTemplatesLoader.$inject = [27 'config.elementTemplates',28 'eventBus',29 'elementTemplates'30];31ElementTemplatesLoader.prototype.reload = function() {32 var self = this;33 var loadTemplates = this._loadTemplates;34 // no templates specified35 if (typeof loadTemplates === 'undefined') {36 return;37 }38 // template loader function specified39 if (typeof loadTemplates === 'function') {40 return loadTemplates(function(err, templates) {41 if (err) {42 return self.templateErrors([ err ]);43 }44 self.setTemplates(templates);45 });46 }47 // templates array specified48 if (loadTemplates.length) {49 return this.setTemplates(loadTemplates);50 }51};52ElementTemplatesLoader.prototype.setTemplates = function(templates) {53 var elementTemplates = this._elementTemplates;54 var validator = new Validator().addAll(templates);55 var errors = validator.getErrors(),56 validTemplates = validator.getValidTemplates();57 elementTemplates.set(validTemplates);58 if (errors.length) {59 this.templateErrors(errors);60 }61 this.templatesChanged();62};63ElementTemplatesLoader.prototype.templatesChanged = function() {64 this._eventBus.fire('elementTemplates.changed');65};66ElementTemplatesLoader.prototype.templateErrors = function(errors) {67 this._eventBus.fire('elementTemplates.errors', {68 errors: errors69 });...
Using AI Code Generation
1import { MockBuilder, MockRender } from 'ng-mocks';2import { AppModule } from './app.module';3import { AppComponent } from './app.component';4describe('AppComponent', () => {5 beforeEach(() => MockBuilder(AppComponent, AppModule));6 it('should render title', () => {7 const fixture = MockRender(AppComponent);8 expect(fixture.nativeElement.querySelector('h1').textContent).toContain(9 );10 });11});12import { TestBed } from '@angular/core/testing';13import { AppComponent } from './app.component';14describe('AppComponent', () => {15 beforeEach(async () => {16 await TestBed.configureTestingModule({17 }).compileComponents();18 });19 it('should render title', () => {20 const fixture = TestBed.createComponent(AppComponent);21 fixture.detectChanges();22 expect(fixture.nativeElement.querySelector('h1').textContent).toContain(23 );24 });25});
Using AI Code Generation
1import { MockBuilder, MockRender } from 'ng-mocks';2import { AppModule } from './app.module';3import { AppComponent } from './app.component';4beforeEach(() => MockBuilder(AppComponent, AppModule));5it('renders the component', () => {6 const fixture = MockRender(AppComponent);7 expect(fixture).toBeDefined();8});9import { ComponentFixture, TestBed } from '@angular/core/testing';10import { AppComponent } from './app.component';11describe('AppComponent', () => {12 let component: AppComponent;13 let fixture: ComponentFixture<AppComponent>;14 beforeEach(async () => {15 await TestBed.configureTestingModule({16 }).compileComponents();17 });18 beforeEach(() => {19 fixture = TestBed.createComponent(AppComponent);20 component = fixture.componentInstance;21 fixture.detectChanges();22 });23 it('should create', () => {24 expect(component).toBeTruthy();25 });26});27import { MockRender } from 'ng-mocks';28import { AppComponent } from './app.component';29describe('AppComponent', () => {30 it('renders the component', () => {31 const fixture = MockRender(AppComponent);32 expect(fixture).toBeDefined();33 });34});35import { MockBuilder, MockRender } from 'ng-mocks';36import { AppComponent } from './app.component';37describe('AppComponent', () => {38 beforeEach(() => MockBuilder(AppComponent));39 it('renders the component', () => {40 const fixture = MockRender(AppComponent);41 expect(fixture).toBeDefined();42 });43});44import { MockBuilder, MockRender } from 'ng-mocks';45import { AppComponent } from './app.component';46import { MyService } from './my.service';47describe('AppComponent', () => {48 beforeEach(() => MockBuilder(AppComponent).mock(MyService));49 it('renders the component', () => {50 const fixture = MockRender(AppComponent);51 expect(fixture).toBeDefined();52 });53});54import { MockBuilder, MockRender, MockService } from 'ng-mocks';55import { AppComponent } from './
Using AI Code Generation
1import { MockBuilder, MockRender } from 'ng-mocks';2import { MyComponent } from './my.component';3beforeEach(() => MockBuilder(MyComponent));4it('should render', () => {5 const fixture = MockRender(MyComponent);6 expect(fixture.point.componentInstance).toBeDefined();7});8it('should render with template', () => {9 const fixture = MockRender(`10 </my-component>`);11 expect(fixture.point.nativeElement.innerHTML).toContain('Inner');12});13import { async, ComponentFixture, TestBed } from '@angular/core/testing';14import { MyComponent } from './my.component';15describe('MyComponent', () => {16 let component: MyComponent;17 let fixture: ComponentFixture<MyComponent>;18 beforeEach(async(() => {19 TestBed.configureTestingModule({20 }).compileComponents();21 }));22 beforeEach(() => {23 fixture = TestBed.createComponent(MyComponent);24 component = fixture.componentInstance;25 fixture.detectChanges();26 });27 it('should create', () => {28 expect(component).toBeTruthy();29 });30});31import { render } from '@testing-library/angular';32import { MyComponent } from './my.component';33describe('MyComponent', () => {34 it('should render', async () => {35 const { getByText } = await render(MyComponent, {36 });37 expect(getByText('Inner')).toBeDefined();38 });39});40import { render } from 'ng-mocks';41import { MyComponent } from './my.component';42describe('MyComponent', () => {43 it('should render', async () => {44 const { getByText } = await render(MyComponent, {45 });46 expect(getByText('Inner')).toBeDefined();47 });48});49import { render } from 'ng-mocks';50import { MyComponent } from './my.component';51describe('MyComponent', () =>
Using AI Code Generation
1import { Component } from '@angular/core';2import { TestBed } from 'ng-mocks';3import { MyComponent } from './my.component';4describe('MyComponent', () => {5 beforeEach(() => {6 TestBed.configureTestingModule({7 });8 });9 it('should create', () => {10 const fixture = TestBed.createComponent(MyComponent);11 const component = fixture.componentInstance;12 expect(component).toBeTruthy();13 });14});15import { Component, Input } from '@angular/core';16@Component({17 <div>{{name}}</div>18})19export class MyComponent {20 @Input() name: string;21}22<div>{{name}}</div>23import { Component } from '@angular/core';24import { TestBed } from 'ng-mocks';25import { MyComponent } from './my.component';26describe('MyComponent', () => {27 beforeEach(() => {28 TestBed.configureTestingModule({29 });30 });31 it('should create', () => {32 const fixture = TestBed.createComponent(MyComponent);33 const component = fixture.componentInstance;34 expect(component).toBeTruthy();35 });36});37import { Component, Input } from '@angular/core';38@Component({39 <div>{{name}}</div>40})41export class MyComponent {42 @Input() name: string;43}44<div>{{name}}</div>45import { Component } from '@angular/core';46import { TestBed } from 'ng-mocks';47import { MyComponent } from './my.component';48describe('MyComponent', () => {49 beforeEach(() => {50 TestBed.configureTestingModule({51 });52 });53 it('should create', () => {54 const fixture = TestBed.createComponent(MyComponent);55 const component = fixture.componentInstance;56 expect(component).toBeTruthy();57 });58});59import { Component, Input } from '@angular/core';60@Component({61 <div>{{name}}</div>62})
Using AI Code Generation
1import { MockBuilder } from 'ng-mocks';2import { AppModule } from './app.module';3beforeEach(() => MockBuilder(AppModule));4import { MockBuilder } from 'ng-mocks';5import { AppModule } from './app.module';6beforeEach(() => MockBuilder(AppModule).keep(TestBed));7import { MockBuilder } from 'ng-mocks';8import { AppModule } from './app.module';9beforeEach(() => MockBuilder(AppModule).keep(TestBed));10import { MockBuilder } from 'ng-mocks';11import { AppModule } from './app.module';12beforeEach(() => MockBuilder(AppModule).keep(TestBed));13import { MockBuilder } from 'ng-mocks';14import { AppModule } from './app.module';15beforeEach(() => MockBuilder(AppModule).keep(TestBed));16import { MockBuilder } from 'ng-mocks';17import { AppModule } from './app.module';18beforeEach(() => MockBuilder(AppModule).keep(TestBed));19import { MockBuilder } from 'ng-mocks';20import { AppModule } from './app.module';21beforeEach(() => MockBuilder(AppModule).keep(TestBed));22import { MockBuilder } from 'ng-mocks';23import { AppModule } from './app.module';24beforeEach(() => MockBuilder(AppModule).keep(TestBed));25import { MockBuilder } from 'ng-mocks';26import { AppModule } from './app.module';27beforeEach(() => MockBuilder(AppModule).keep(TestBed));28import { MockBuilder } from 'ng-mocks';29import { AppModule } from './app.module';30beforeEach(() => MockBuilder(AppModule).keep(TestBed));31import { MockBuilder } from 'ng-mocks';32import { AppModule } from './app.module';33beforeEach(() => MockBuilder(AppModule).keep(TestBed));34import { MockBuilder } from 'ng-mocks';35import { AppModule } from './app.module
Using AI Code Generation
1import { createComponent } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('renders the component', () => {5 const fixture = createComponent(MyComponent);6 expect(fixture).toBeDefined();7 });8});
Using AI Code Generation
1import { MockBuilder, MockRender } from 'ng-mocks';2import { TestBed } from '@angular/core/testing';3import { MyComponent } from './my.component';4describe('MyComponent', () => {5 beforeEach(() => MockBuilder(MyComponent));6 beforeEach(() => TestBed.configureTestingModule({7 }));8 it('should create an instance', () => {9 const fixture = MockRender(MyComponent);10 const fixture = TestBed.createComponent(MyComponent);11 fixture.detectChanges();12 expect(fixture.componentInstance).toBeTruthy();13 });14});15import { Component } from '@angular/core';16@Component({17})18export class MyComponent { }19import { MyComponent } from './my.component';20describe('MyComponent', () => {21 it('should create an instance', () => {22 expect(new MyComponent()).toBeTruthy();23 });24});25h1 {26 color: red;27}28import { MockBuilder, MockRender } from 'ng-mocks';29import { MyComponent } from './my.component';30describe('MyComponent', () => {31 beforeEach(() => MockBuilder(MyComponent));32 it('should create an instance', () => {33 const fixture = MockRender(MyComponent);34 expect(fixture.componentInstance).toBeTruthy();35 });36});37import { MockBuilder, MockRender } from 'ng-mocks';38import { MyComponent } from './my.component';39import { MyService } from './my.service';40describe('MyComponent', () => {41 beforeEach(() => MockBuilder(MyComponent)42 .mock(MyService)43 );44 it('should create an instance', () => {45 const fixture = MockRender(MyComponent);46 expect(fixture.componentInstance).toBeTruthy();47 });
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!