How to use instances2 method in ng-mocks

Best JavaScript code snippet using ng-mocks

sample5.js

Source:sample5.js Github

copy

Full Screen

1phina.namespace(function() {2 var enable1 = true;3 var enable2 = true;4 phina.main(function() {5 phina.asset.AssetLoader()6 .on("load", function() {7 start();8 })9 .load({10 image: {11 "sample.png": "./sample.png",12 },13 vertexShader: {14 "sample1.vs": "./sample1.vs",15 "sample2.vs": "./sample2.vs",16 },17 fragmentShader: {18 "sample1.fs": "./sample1.fs",19 "sample2.fs": "./sample2.fs",20 },21 });22 });23 var start = function() {24 var canvas = document.getElementById("app");25 canvas.width = 512;26 canvas.height = 512;27 var range = 1000;28 var vMat = mat4.lookAt(mat4.create(), [0, 0, 2000], [0, 0, 0], [0, 1, 0]);29 var pMat = mat4.perspective(mat4.create(), 45, 1, 0.1, 5000);30 var mat = mat4.create();31 mat4.translate(mat, mat, [0, 0, 0]);32 mat4.scale(mat, mat, [60, 60, 60]);33 var gl = canvas.getContext("webgl");34 var ext = phigl.Extensions.getInstancedArrays(gl);35 gl.clearColor(0.0, 0.0, 0.0, 1.0);36 gl.clearDepth(1.0);37 gl.enable(gl.DEPTH_TEST);38 gl.depthFunc(gl.LEQUAL);39 gl.enable(gl.BLEND);40 gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);41 if (enable1) {42 var drawable1 = phigl.InstancedDrawable(gl, ext)43 .setProgram(phigl.Program(gl).attach("sample1.vs").attach("sample1.fs").link())44 .setIndexValues([0, 1, 2, 1, 3, 2])45 .declareAttributes("position")46 .setAttributeDataArray([{47 unitSize: 3,48 data: [49 //50 -0.5, +0.5, 0,51 //52 +0.5, +0.5, 0,53 //54 -0.5, -0.5, 0,55 //56 +0.5, -0.5, 0,57 ],58 }, ])59 .declareInstanceAttributes("instancePosition", "rotY")60 .declareUniforms("mMatrix", "vMatrix", "pMatrix")61 .on("predraw", function() {62 gl.disable(gl.DEPTH_TEST);63 })64 .on("postdraw", function() {65 gl.enable(gl.DEPTH_TEST);66 });67 var instanceCount1 = 1200;68 var instances1 = Array.range(0, instanceCount1).map(function() {69 return [Math.randfloat(-range, range), Math.randfloat(-range, range), Math.randfloat(-range, range), Math.randfloat(0, Math.PI * 2)];70 }).flatten();71 drawable1.setInstanceAttributeData(instances1);72 var dirs1 = [];73 for (var i = 0; i < instances1.length; i += 4) {74 dirs1[i + 0] = Math.randfloat(-6, 6);75 dirs1[i + 1] = Math.randfloat(-6, 6);76 dirs1[i + 2] = Math.randfloat(-6, 6);77 dirs1[i + 3] = Math.randfloat(-0.02, 0.02);78 }79 drawable1.uniforms["vMatrix"].setValue(vMat);80 drawable1.uniforms["pMatrix"].setValue(pMat);81 drawable1.uniforms["mMatrix"].setValue(mat);82 }83 if (enable2) {84 var drawable2 = phigl.InstancedDrawable(gl, ext)85 .setProgram(phigl.Program(gl).attach("sample2.vs").attach("sample2.fs").link())86 .setIndexValues([0, 1, 2, 1, 3, 2])87 .declareAttributes("noitisop", "uv")88 .setAttributeDataArray([{89 unitSize: 3,90 data: [91 //92 -0.5, +0.5, 0,93 //94 +0.5, +0.5, 0,95 //96 -0.5, -0.5, 0,97 //98 +0.5, -0.5, 0,99 ],100 }, {101 unitSize: 2,102 data: [103 //104 0, 1,105 //106 1, 1,107 //108 0, 0,109 //110 1, 0,111 ],112 }, ])113 .declareInstanceAttributes("instancePosition", "rotY")114 .declareUniforms("mMatrix", "vMatrix", "pMatrix", "texture")115 .on("predraw", function() {116 gl.disable(gl.DEPTH_TEST);117 })118 .on("postdraw", function() {119 gl.enable(gl.DEPTH_TEST);120 });121 var instanceCount2 = 100;122 var instances2 = Array.range(0, instanceCount2).map(function() {123 return [124 Math.randfloat(-range, range),125 Math.randfloat(-range, range),126 Math.randfloat(-range, range),127 Math.randfloat(0, Math.PI * 2),128 ];129 }).flatten();130 drawable2.setInstanceAttributeData(instances2);131 var dirs2 = [];132 for (var i = 0; i < instances2.length; i += 4) {133 dirs2[i + 0] = Math.randfloat(-6, 6);134 dirs2[i + 1] = Math.randfloat(-6, 6);135 dirs2[i + 2] = Math.randfloat(-6, 6);136 dirs2[i + 3] = Math.randfloat(-0.01, 0.01);137 }138 drawable2.uniforms["vMatrix"].setValue(vMat);139 drawable2.uniforms["pMatrix"].setValue(pMat);140 drawable2.uniforms["mMatrix"].setValue(mat);141 drawable2.uniforms["texture"].setValue(0).setTexture(phigl.Texture(gl, "sample.png"));142 }143 phina.app.BaseApp()144 .enableStats()145 .on("enterframe", function() {146 mat4.lookAt(vMat, [Math.sin(this.frame * 0.004) * 1000, 0, Math.cos(this.frame * 0.004) * 3000], [0, 0, 0], [0, 1, 0]);147 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);148 if (enable1) {149 for (var i = 0; i < instances1.length; i += 4) {150 instances1[i + 0] += dirs1[i + 0];151 instances1[i + 1] += dirs1[i + 1];152 instances1[i + 2] += dirs1[i + 2];153 if (instances1[i + 0] < -range || range < instances1[i + 0]) dirs1[i + 0] *= -1;154 if (instances1[i + 1] < -range || range < instances1[i + 1]) dirs1[i + 1] *= -1;155 if (instances1[i + 2] < -range || range < instances1[i + 2]) dirs1[i + 2] *= -1;156 instances1[i + 3] += dirs1[i + 3];157 }158 drawable1.setInstanceAttributeData(instances1);159 drawable1.draw(instanceCount1);160 }161 if (enable2) {162 for (var i = 0; i < instances2.length; i += 4) {163 instances2[i + 0] += dirs2[i + 0];164 instances2[i + 1] += dirs2[i + 1];165 instances2[i + 2] += dirs2[i + 2];166 if (instances2[i + 0] < -range || range < instances2[i + 0]) dirs2[i + 0] *= -1;167 if (instances2[i + 1] < -range || range < instances2[i + 1]) dirs2[i + 1] *= -1;168 if (instances2[i + 2] < -range || range < instances2[i + 2]) dirs2[i + 2] *= -1;169 instances1[i + 3] += dirs1[i + 3];170 }171 drawable2.setInstanceAttributeData(instances2);172 drawable2.draw(instanceCount2);173 }174 gl.flush();175 })176 .run().fps = 60;177 };...

Full Screen

Full Screen

deno_ci_ins_2d.js

Source:deno_ci_ins_2d.js Github

copy

Full Screen

1/**2 * Created by leonlin on 16/11/3.3 */4define(["simulate"], function(simulate){5 return function(data, tools, callback) {6 var Info = tools.Info;7 var nodesDes = tools.nodesDes;8 var kpisDes = tools.kpisDes;9 var instance = tools.instance;10 var simulateFn = tools.simulate;11 var services = {};12 services.dictionaryService = tools.dictionaryService;13 var getInfo_back = function(){14 var result = [];15 var insort = [];16 var simulateBack = function(data){17 var xAxis = [], instances1 = [], instances2 = [];18 var loop = function(item){19 if(xAxis.indexOf(item.instance) == -1){20 xAxis.push(item.instance);21 };22 };23 for(var i in data){24 loop(data[i])25 };26 xAxis = xAxis.sort();27 var getLegend = function(){28 return instances1;29 };30 var getxAxis = function(){31 return [insort];32 };33 var getSeries = function(){34 var rs = result.map(function(item){35 var obj = {};36 obj.total = item.total;37 obj.name = item.name.ins1;38 var n = 0;39 obj.data = item.value.map(function(itm){40 return {41 name : itm.ins2 ? itm.ins2 : "",42 value : itm.value ? itm.value : 043 }44 });45 return obj;46 });47 return rs;48 };49 var loopNodeDes = function(node){50 var loopKpisDes = function(kpi){51 var loop = function(item){52 var ins1, ins2;53 if(item.instance){54 ins1 = item.instance.split(",")[0];55 ins2 = item.instance.split(",")[1];56 if(instances1.indexOf(ins1) == -1){57 instances1.push(ins1);58 }59 if(instances2.indexOf(ins2) == -1){60 instances2.push(ins2);61 }62 }63 if(ins2){64 var find = result.find(function(elem){65 return elem.name.ci == node.label && elem.name.kpi == kpi.label && elem.name.ins1 == ins1;66 });67 if(find){68 item.ins2 = ins2 ? ins2 : "企业";69 var some = find.value.find(function(ele){70 if(ele){71 return ele.instance == item.instance;72 } else {73 return false;74 };75 });76 var inx = instances2.indexOf(ins2);77 if(!some){78 if(inx == 10){79 }80 find.value[inx] = item;81 };82 } else {83 var obj = {84 name :{85 ci : node.label,86 kpi : kpi.label,87 ins1 : ins188 },89 value : [],90 total : 091 };92 var inx = instances2.indexOf(ins2);93 item.ins2 = ins2;94 obj.value[inx] = item;95 result.push(obj);96 }97 };98 };99 for(var i in data){100 loop(data[i])101 };102 };103 for(var i in kpisDes){104 loopKpisDes(kpisDes[i])105 }106 };107 for(var i in nodesDes){108 loopNodeDes(nodesDes[i])109 };110 for(var i in result){111 for(var j=0; j<instances2.length; j++){112 if(result[i].value[j] == undefined){113 result[i].value[j] = {114 };115 }116 }117 }118 for(var i in result[0].value){119 var rs = 0120 for(var j in result){121 if(result[j].value[i]){122 if(result[j].value[i].value){123 rs += result[j].value[i].value;124 }125 }126 };127 for(var j in result){128 if(result[j].value[i]){129 result[j].value[i].total = rs;130 };131 };132 };133 for(var i in result){134 result[i].value = result[i].value.sort(function(a,b){135 return a.total - b.total;136 });137 }138 for(var i in result){139 for(var j=0; j<instances2.length; j++){140 if(insort[j] == undefined){141 if(j == 3){142 ;143 }144 if(result[i].value[j].ins2 != undefined){145 insort[j] = result[i].value[j].ins2;146 }147 };148 }149 }150 callback({151 getLegend : getLegend,152 getxAxis : getxAxis,153 getSeries : getSeries154 });155 };156 simulateBack(data);157 //simulate("ci_2d", nodesDes, kpisDes, instance, simulateFn, services, simulateBack);158 };159 Info.get("../localdb/simulate.json", getInfo_back);160 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppComponent } from './app.component';3import { AppModule } from './app.module';4describe('AppComponent', () => {5 beforeEach(() => MockBuilder(AppComponent, AppModule));6 it('should create the app', () => {7 const fixture = MockRender(AppComponent);8 const app = fixture.point.componentInstance;9 expect(app).toBeTruthy();10 });11 it('should have one button', () => {12 const fixture = MockRender(AppComponent);13 const buttons = ngMocks.instances2('button');14 expect(buttons.length).toBe(1);15 });16});17import { Component } from '@angular/core';18@Component({19})20export class AppComponent {21 title = 'ng-mocks';22}23import { NgModule } from '@angular/core';24import { BrowserModule } from '@angular/platform-browser';25import { AppComponent } from './app.component';26@NgModule({27 imports: [BrowserModule],28})29export class AppModule {}30{31 "compilerOptions": {32 },33}34{35 "compilerOptions": {36 "importHelpers": true,37 }38}39{

Full Screen

Using AI Code Generation

copy

Full Screen

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 create the app', () => {7 const fixture = MockRender(AppComponent);8 const app = fixture.point.componentInstance;9 expect(app).toBeTruthy();10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { TestBed } from '@angular/core/testing';2import { AppComponent } from './app.component';3import { AppModule } from './app.module';4import { instances2 } from 'ng-mocks';5describe('AppComponent', () => {6 beforeEach(async () => {7 await TestBed.configureTestingModule({8 imports: [AppModule],9 }).compileComponents();10 });11 it('should create the app', () => {12 const fixture = TestBed.createComponent(AppComponent);13 const app = fixture.componentInstance;14 expect(app).toBeTruthy();15 });16 it(`should have as title 'app'`, () => {17 const fixture = TestBed.createComponent(AppComponent);18 const app = fixture.componentInstance;19 expect(app.title).toEqual('app');20 });21 it('should render title', () => {22 const fixture = TestBed.createComponent(AppComponent);23 fixture.detectChanges();24 const compiled = fixture.nativeElement;25 expect(compiled.querySelector('.content span').textContent).toContain(26 );27 });28 it('should have a button', () => {29 const fixture = TestBed.createComponent(AppComponent);30 const app = fixture.componentInstance;31 const button = app.button;32 expect(button).toBeTruthy();33 });34 it('should have a button with a label', () => {35 const fixture = TestBed.createComponent(AppComponent);36 const app = fixture.componentInstance;37 const button = app.button;38 expect(button.label).toBeTruthy();39 });40 it('should have a button with a label of "Click me"', () => {41 const fixture = TestBed.createComponent(AppComponent);42 const app = fixture.componentInstance;43 const button = app.button;44 expect(button.label).toEqual('Click me');45 });46 it('should have a button with a label of "Click me" and a click handler', () => {47 const fixture = TestBed.createComponent(AppComponent);48 const app = fixture.componentInstance;49 const button = app.button;50 expect(button.label).toEqual('Click me');51 expect(button.click).toBeTruthy();52 });53 it('should have a button with a label of "Click me" and a click handler that changes the title', () => {54 const fixture = TestBed.createComponent(AppComponent);55 const app = fixture.componentInstance;56 const button = app.button;57 expect(button.label).toEqual('Click me');58 expect(button.click).toBeTruthy();59 expect(app.title).toEqual('app');60 button.click();61 expect(app.title).toEqual('app was clicked');62 });

Full Screen

Using AI Code Generation

copy

Full Screen

1import { instances2 } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('should work', () => {5 const fixture = MockRender(MyComponent);6 const instances = instances2(fixture.debugElement);7 expect(instances.length).toBe(1);8 expect(instances[0] instanceof MyComponent).toBe(true);9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { instances2 } from 'ng-mocks';2import { createComponent } from 'ng-mocks';3import { TestComponent } from './test.component';4describe('TestComponent', () => {5 it('should create', () => {6 const fixture = createComponent(TestComponent);7 const component = instances2(TestComponent).component;8 expect(component).toBeTruthy();9 });10});11import { Component, OnInit } from '@angular/core';12@Component({13})14export class TestComponent implements OnInit {15 constructor() { }16 ngOnInit() { }17}18h1 { color: blue; }19import { async, ComponentFixture, TestBed } from '@angular/core/testing';20import { TestComponent } from './test.component';21describe('TestComponent', () => {22 let component: TestComponent;23 let fixture: ComponentFixture<TestComponent>;24 beforeEach(async(() => {25 TestBed.configureTestingModule({26 })27 .compileComponents();28 }));29 beforeEach(() => {30 fixture = TestBed.createComponent(TestComponent);31 component = fixture.componentInstance;32 fixture.detectChanges();33 });34 it('should create', () => {35 expect(component).toBeTruthy();36 });37});38import { OnInit } from '@angular/core';39export declare class TestComponent implements OnInit {40 constructor();41 ngOnInit(): void;42}43"use strict";44Object.defineProperty(exports, "__esModule", { value: true });45var core_1 = require("@angular/core");46var TestComponent = /** @class */ (function () {47 function TestComponent() { }48 TestComponent.prototype.ngOnInit = function () { };49 TestComponent = __decorate([50 core_1.Component({51 })52 ], TestComponent);53 return TestComponent;54}());55exports.TestComponent = TestComponent;56{"version":3,"file":"test.component.js","sourceRoot":"","sources":["test.component.ts"],"names":[],"mappings":";;;;;;;;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { NgMocks } from 'ng-mocks';2const instances = NgMocks.instances2(ChildComponent);3import { NgMocks } from 'ng-mocks';4const instances = NgMocks.instances(ChildComponent);5import { NgMocks } from 'ng-mocks';6const instance = NgMocks.instance2(ChildComponent);7import { NgMocks } from 'ng-mocks';8const instance = NgMocks.instance(ChildComponent);9import { NgMocks } from 'ng-mocks';10const instance = NgMocks.findInstance2(ChildComponent);11import { NgMocks } from 'ng-mocks';12const instance = NgMocks.findInstance(ChildComponent);13import { NgMocks } from 'ng-mocks';14const instances = NgMocks.findInstances2(ChildComponent);15import { NgMocks } from 'ng-mocks';16const instances = NgMocks.findInstances(ChildComponent);17import { NgMocks } from 'ng-mocks';18const debugElement = NgMocks.find(ChildComponent);19import { NgMocks } from 'ng-mocks';20const debugElement = NgMocks.find(ChildComponent, 'child');21import { NgMocks } from 'ng-mocks';22const debugElements = NgMocks.findAll(ChildComponent);23import { NgMocks } from 'ng-mocks';24const debugElements = NgMocks.findAll(ChildComponent, 'child');25import { NgMocks } from 'ng-mocks';26const instance = NgMocks.findInstance(ChildComponent);27import { NgMocks } from 'ng-mocks';28const instance = NgMocks.findInstance(

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ComponentFixture, TestBed } from '@angular/core/testing';2import { AppComponent } from './app.component';3import { MyService } from './my.service';4import { instances2 } from 'ng-mocks';5describe('AppComponent', () => {6 let component: AppComponent;7 let fixture: ComponentFixture<AppComponent>;8 beforeEach(async () => {9 await TestBed.configureTestingModule({10 instances2([11 { provide: MyService, useValue: { name: 'mocked service' } },12 }).compileComponents();13 });14 beforeEach(() => {15 fixture = TestBed.createComponent(AppComponent);16 component = fixture.componentInstance;17 fixture.detectChanges();18 });19 it('should create', () => {20 expect(component).toBeTruthy();21 });22});23import { Injectable } from '@angular/core';24@Injectable()25export class MyService {26 name = 'real service';27}28import { Component } from '@angular/core';29import { MyService } from './my.service';30@Component({31 <h1>{{ title }}</h1>32 <p>service name: {{ myService.name }}</p>33})34export class AppComponent {35 title = 'ng-mocks-test';36 constructor(public myService: MyService) {}37}38import { ComponentFixture, TestBed } from '@angular/core/testing';39import { AppComponent } from './app.component';40import { MyService } from './my.service';41import { instances2 } from 'ng-mocks';42describe('AppComponent', () => {43 let component: AppComponent;44 let fixture: ComponentFixture<AppComponent>;45 beforeEach(async () => {46 await TestBed.configureTestingModule({

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