How to use configInstance method in ng-mocks

Best JavaScript code snippet using ng-mocks

advanced-transformation.js

Source:advanced-transformation.js Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * You may obtain a copy of the License at5 *6 * http://www.apache.org/licenses/LICENSE-2.07 *8 * Unless required by applicable law or agreed to in writing, software9 * distributed under the License is distributed on an "AS IS" BASIS,10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11 * See the License for the specific language governing permissions and12 * limitations under the License.13 */14import Transformation from './transformation';15import {16 getCurrentChart, getCurrentChartAxis, getCurrentChartParam,17 serializeSharedAxes, useSharedAxis,18 getCurrentChartAxisSpecs, getCurrentChartParamSpecs,19 initializeConfig, resetAxisConfig, resetParameterConfig,20 isAggregatorAxis, isGroupAxis, isKeyAxis, isSingleDimensionAxis,21 removeDuplicatedColumnsInMultiDimensionAxis, applyMaxAxisCount,22 isInputWidget, isOptionWidget, isCheckboxWidget, isTextareaWidget, parseParameter,23 getTransformer,24} from './advanced-transformation-util';25const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html';26export default class AdvancedTransformation extends Transformation {27 constructor(config, spec) {28 super(config);29 this.columns = []; /** [{ name, index, comment }] */30 this.props = {};31 this.spec = spec;32 initializeConfig(config, spec);33 }34 emitConfigChange(conf) {35 conf.chartChanged = false;36 conf.parameterChanged = false;37 this.emitConfig(conf);38 }39 emitChartChange(conf) {40 conf.chartChanged = true;41 conf.parameterChanged = false;42 this.emitConfig(conf);43 }44 emitParameterChange(conf) {45 conf.chartChanged = false;46 conf.parameterChanged = true;47 this.emitConfig(conf);48 }49 getSetting() {50 const self = this; /** for closure */51 const configInstance = self.config; /** for closure */52 if (self.spec.initialized) {53 self.spec.initialized = false;54 self.emitConfig(configInstance);55 }56 return {57 template: SETTING_TEMPLATE,58 scope: {59 config: configInstance,60 columns: self.columns,61 resetAxisConfig: () => {62 resetAxisConfig(configInstance);63 self.emitChartChange(configInstance);64 },65 resetParameterConfig: () => {66 resetParameterConfig(configInstance);67 self.emitParameterChange(configInstance);68 },69 toggleColumnPanel: () => {70 configInstance.panel.columnPanelOpened = !configInstance.panel.columnPanelOpened;71 self.emitConfigChange(configInstance);72 },73 toggleParameterPanel: () => {74 configInstance.panel.parameterPanelOpened = !configInstance.panel.parameterPanelOpened;75 self.emitConfigChange(configInstance);76 },77 getAxisAnnotation: (axisSpec) => {78 let anno = `${axisSpec.name}`;79 if (axisSpec.valueType) {80 anno = `${anno} (${axisSpec.valueType})`;81 }82 return anno;83 },84 getAxisTypeAnnotation: (axisSpec) => {85 let anno = '';86 let minAxisCount = axisSpec.minAxisCount;87 let maxAxisCount = axisSpec.maxAxisCount;88 if (isSingleDimensionAxis(axisSpec)) {89 maxAxisCount = 1;90 }91 let comment = '';92 if (minAxisCount) {93 comment = `min: ${minAxisCount}`;94 }95 if (minAxisCount && maxAxisCount) {96 comment = `${comment}, `;97 }98 if (maxAxisCount) {99 comment = `${comment}max: ${maxAxisCount}`;100 }101 if (comment !== '') {102 anno = `${anno} (${comment})`;103 }104 return anno;105 },106 getAxisAnnotationColor: (axisSpec) => {107 if (isAggregatorAxis(axisSpec)) {108 return {'background-color': '#5782bd'};109 } else if (isGroupAxis(axisSpec)) {110 return {'background-color': '#cd5c5c'};111 } else if (isKeyAxis(axisSpec)) {112 return {'background-color': '#906ebd'};113 } else {114 return {'background-color': '#62bda9'};115 }116 },117 useSharedAxis: (chartName) => {118 return useSharedAxis(configInstance, chartName);119 },120 isGroupAxis: (axisSpec) => {121 return isGroupAxis(axisSpec);122 },123 isKeyAxis: (axisSpec) => {124 return isKeyAxis(axisSpec);125 },126 isAggregatorAxis: (axisSpec) => {127 return isAggregatorAxis(axisSpec);128 },129 isSingleDimensionAxis: (axisSpec) => {130 return isSingleDimensionAxis(axisSpec);131 },132 getSingleDimensionAxis: (axisSpec) => {133 return getCurrentChartAxis(configInstance)[axisSpec.name];134 },135 chartChanged: (selected) => {136 configInstance.chart.current = selected;137 self.emitChartChange(configInstance);138 },139 axisChanged: function(e, ui, axisSpec) {140 removeDuplicatedColumnsInMultiDimensionAxis(configInstance, axisSpec);141 applyMaxAxisCount(configInstance, axisSpec);142 self.emitChartChange(configInstance);143 },144 aggregatorChanged: (colIndex, axisSpec, aggregator) => {145 if (isSingleDimensionAxis(axisSpec)) {146 getCurrentChartAxis(configInstance)[axisSpec.name].aggr = aggregator;147 } else {148 getCurrentChartAxis(configInstance)[axisSpec.name][colIndex].aggr = aggregator;149 removeDuplicatedColumnsInMultiDimensionAxis(configInstance, axisSpec);150 }151 self.emitChartChange(configInstance);152 },153 removeFromAxis: function(colIndex, axisSpec) {154 if (isSingleDimensionAxis(axisSpec)) {155 getCurrentChartAxis(configInstance)[axisSpec.name] = null;156 } else {157 getCurrentChartAxis(configInstance)[axisSpec.name].splice(colIndex, 1);158 }159 self.emitChartChange(configInstance);160 },161 isInputWidget: function(paramSpec) {162 return isInputWidget(paramSpec);163 },164 isCheckboxWidget: function(paramSpec) {165 return isCheckboxWidget(paramSpec);166 },167 isOptionWidget: function(paramSpec) {168 return isOptionWidget(paramSpec);169 },170 isTextareaWidget: function(paramSpec) {171 return isTextareaWidget(paramSpec);172 },173 parameterChanged: (paramSpec) => {174 configInstance.chartChanged = false;175 configInstance.parameterChanged = true;176 self.emitParameterChange(configInstance);177 },178 parameterOnKeyDown: function(event, paramSpec) {179 const code = event.keyCode || event.which;180 if (code === 13 && isInputWidget(paramSpec)) {181 self.emitParameterChange(configInstance);182 } else if (code === 13 && event.shiftKey && isTextareaWidget(paramSpec)) {183 self.emitParameterChange(configInstance);184 }185 event.stopPropagation(); /** avoid to conflict with paragraph shortcuts */186 },187 },188 };189 }190 transform(tableData) {191 this.columns = tableData.columns; /** used in `getSetting` */192 /** initialize in `transform` instead of `getSetting` because this method is called before */193 serializeSharedAxes(this.config);194 const conf = this.config;195 const chart = getCurrentChart(conf);196 const axis = getCurrentChartAxis(conf);197 const axisSpecs = getCurrentChartAxisSpecs(conf);198 const param = getCurrentChartParam(conf);199 const paramSpecs = getCurrentChartParamSpecs(conf);200 const parsedParam = parseParameter(paramSpecs, param);201 let {transformer, column} = getTransformer(conf, tableData.rows, axisSpecs, axis);202 return {203 chartChanged: conf.chartChanged,204 parameterChanged: conf.parameterChanged,205 chart: chart, /** current chart */206 axis: axis, /** persisted axis */207 parameter: parsedParam, /** persisted parameter */208 column: column,209 transformer: transformer,210 };211 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 * Created by: Hau Vo3 *4 * This file will be storing all file configurations in the future5 */6import RNConfig from 'react-native-config'7import { info } from '../utils/logger'8let configInstance = null9const config = () => {10 if (configInstance) return configInstance11 configInstance = {12 ...RNConfig,13 SIGNATURE_IMAGE_DIR: 'SIGN',14 POD_IMAGE_DIR: 'POD',15 GOOGLE_DIRECTIONS_API: 'https://maps.googleapis.com/maps/api/directions',16 GOOGLE_DIRECTIONS_API_WAYPOINT_LIMIT: 23,17 DIFFERENT_UPDATE_USER_LOCATION: 0.2 // 200m different18 }19 info(configInstance)20 return configInstance21}22export default config23export const overrideEndpoint = (24 endpoint,25 chatEnv,26 theme,27 slug,28 shouldShowServiceType29) => {30 if (configInstance) {31 if (endpoint) configInstance.BASE_URL = endpoint32 if (chatEnv) configInstance.CHAT_ENV = chatEnv33 if (theme) configInstance.THEME = theme34 if (slug) configInstance.COMPANY_SLUG = slug35 configInstance.SHOW_SERVICE_TYPE = shouldShowServiceType36 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configInstance } from 'ng-mocks';2import { mockInstance } from 'ng-mocks';3import { mockProvider } from 'ng-mocks';4import { mockReset } from 'ng-mocks';5import { mockService } from 'ng-mocks';6import { mockStatic } from 'ng-mocks';7import { mockWithProvider } from 'ng-mocks';8import { ngMocksUniverse } from 'ng-mocks';9import { ngMocksUniverseGet } from 'ng-mocks';10import { ngMocksUniverseSet } from 'ng-mocks';11import { ngMocksUniverseSymbol } from 'ng-mocks';12import { ngMocksUniverseSymbolGet } from 'ng-mocks';13import { ngMocksUniverseSymbolSet } from 'ng-mocks';14import { ngMocksUniverseSymbolUnset } from 'ng-mocks';15import { ngMocksUniverseUnset } from 'ng-mocks';16import { ngMocksUniverseUnsetSymbol } from 'ng-mocks';17import { ngMocksUniverseUnsetSymbolGet } from 'ng-mocks';18import { ngMocksUniverseUnsetSymbolSet } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configInstance } from 'ng-mocks';2import { AppComponent } from './app.component';3import { MyService } from './my.service';4describe('AppComponent', () => {5 beforeEach(async(() => {6 TestBed.configureTestingModule({7 }).compileComponents();8 }));9 it('should create the app', () => {10 const fixture = TestBed.createComponent(AppComponent);11 const app = fixture.debugElement.componentInstance;12 expect(app).toBeTruthy();13 });14 it('should have as title \'ng-mocks\'', () => {15 const fixture = TestBed.createComponent(AppComponent);16 const app = fixture.debugElement.componentInstance;17 expect(app.title).toEqual('ng-mocks');18 });19 it('should render title in a h1 tag', () => {20 const fixture = TestBed.createComponent(AppComponent);21 fixture.detectChanges();22 const compiled = fixture.debugElement.nativeElement;23 expect(compiled.querySelector('h1').textContent).toContain('Welcome to ng-mocks!');24 });25 it('should call the service', () => {26 const fixture = TestBed.createComponent(AppComponent);27 const app = fixture.debugElement.componentInstance;28 const myService = fixture.debugElement.injector.get(MyService);29 const spy = spyOn(myService, 'doSomething').and.returnValue('Hello world');30 app.doSomething();31 expect(spy).toHaveBeenCalled();32 });33 it('should call the service with a value', () => {34 const fixture = TestBed.createComponent(AppComponent);35 const app = fixture.debugElement.componentInstance;36 const myService = fixture.debugElement.injector.get(MyService);37 const spy = spyOn(myService, 'doSomething').and.returnValue('Hello world');38 app.doSomething();39 expect(spy).toHaveBeenCalledWith('Hello world');40 });41 it('should call the service with a value', () => {42 const fixture = TestBed.createComponent(AppComponent);43 const app = fixture.debugElement.componentInstance;44 const myService = fixture.debugElement.injector.get(MyService);45 const spy = spyOn(myService, 'doSomething').and.returnValue('Hello world');46 app.doSomething();47 expect(spy).toHaveBeenCalledWith('Hello world');48 });49 it('should call the service with a value', () => {50 const fixture = TestBed.createComponent(AppComponent);51 const app = fixture.debugElement.componentInstance;52 const myService = fixture.debugElement.injector.get(MyService);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configInstance } from 'ng-mocks';2import { mockInstance } from 'ng-mocks';3describe('TestComponent', () => {4 let component: TestComponent;5 let fixture: ComponentFixture<TestComponent>;6 let mockService: any;7 beforeEach(async(() => {8 mockService = jasmine.createSpyObj('Service', ['get']);9 TestBed.configureTestingModule({10 { provide: Service, useValue: mockService },11 }).compileComponents();12 }));13 beforeEach(() => {14 fixture = TestBed.createComponent(TestComponent);15 component = fixture.componentInstance;16 fixture.detectChanges();17 });18 it('should create', () => {19 expect(component).toBeTruthy();20 });21 it('should call service', () => {22 const spy = mockInstance(mockService, 'get', { name: 'test' });23 component.ngOnInit();24 expect(spy).toHaveBeenCalled();25 });26});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('HttpClient', () => {2 beforeEach(() => MockBuilder(HttpClient, HttpClientTestingModule));3 it('should work', inject([HttpClient, HttpTestingController], (http: HttpClient, backend: HttpTestingController) => {4 const spy = jasmine.createSpy();5 expect(spy).toHaveBeenCalledWith({ hello: 'world' });6 }));7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TestBed } from '@angular/core/testing';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('should work', () => {5 const fixture = TestBed.configureTestingModule({6 }).createComponent(MyComponent);7 const component = fixture.componentInstance;8 component.ngOnInit();9 expect(component).toBeDefined();10 });11});12import { TestBed } from '@angular/core/testing';13import { MyComponent } from './my.component';14describe('MyComponent', () => {15 it('should work', () => {16 const fixture = TestBed.configureTestingModule({17 }).createComponent(MyComponent);18 const component = fixture.componentInstance;19 component.ngOnInit();20 expect(component).toBeDefined();21 });22});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configInstance } from 'ng-mocks';2import { MyService } from './my.service';3describe('Mocking service', () => {4 it('should use the mocked service', () => {5 configInstance(MyService, { get: () => 'mocked' });6 });7});8import { MyService } from './my.service';9describe('Mocking service', () => {10 it('should use the mocked service', () => {11 spyOn(MyService.prototype, 'get').and.returnValue('mocked');12 });13});14import { MyService } from './my.service';15describe('Mocking service', () => {16 it('should use the mocked service', () => {17 const mock = createMock(MyService);18 mock.get.and.returnValue('mocked');19 });20});21import { MyService } from './my.service';22import { OtherService } from './other.service';23describe('Mocking service', () => {24 it('should use the mocked service', () => {25 const mock = createMock(MyService, OtherService);26 mock.get.and.returnValue('mocked');27 });28});29import { MyService } from './my.service';

Full Screen

Using AI Code Generation

copy

Full Screen

1 const configInstance = ngMocks.configInstance(Config, 'config', { 2 });3 const serviceInstance = ngMocks.configInstance(Service, 'service', {4 });5 serviceInstance.testMethod();6 expect(configInstance.someValue).toBe('some value');7 });8});

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 ng-mocks 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