How to use myModule method in ng-mocks

Best JavaScript code snippet using ng-mocks

injector_spec.js

Source:injector_spec.js Github

copy

Full Screen

1'use strict';2var _ = require('lodash');3var setupModuleLoader = require('../src/loader');4var createInjector = require('../src/injector');5describe('injector', function() {6 beforeEach(function() {7 delete window.angular;8 setupModuleLoader(window);9 });10 it('can be created', function() {11 var injector = createInjector([]);12 expect(injector).toBeDefined();13 });14 it('has a constant that has been registered to a module', function() {15 var module = window.angular.module('myModule', []);16 module.constant('aConstant', 42);17 var injector = createInjector(['myModule']);18 expect(injector.has('aConstant')).toBe(true);19 });20 it('does not have a non-registered constant', function() {21 var module = window.angular.module('myModule', []);22 var injector = createInjector(['myModule']);23 expect(injector.has('aConstant')).toBe(false);24 });25 it('does not allow a constant called hasOwnProperty', function() {26 var module = window.angular.module('myModule', []);27 module.constant('hasOwnProperty', false);28 expect(function() {29 createInjector(['myModule']);30 }).toThrow();31 });32 it('can return a registered constant', function() {33 var module = window.angular.module('myModule', []);34 module.constant('aConstant', 42);35 var injector = createInjector(['myModule']);36 expect(injector.get('aConstant')).toBe(42);37 });38 it('loads multiple modules', function() {39 var module1 = window.angular.module('myModule', []);40 var module2 = window.angular.module('myOtherModule', []);41 module1.constant('aConstant', 42);42 module2.constant('anotherConstant', 43);43 var injector = createInjector(['myModule', 'myOtherModule']);44 expect(injector.has('aConstant')).toBe(true);45 expect(injector.has('anotherConstant')).toBe(true);46 });47 it('loads the required modules of a module', function() {48 var module1 = window.angular.module('myModule', []);49 var module2 = window.angular.module('myOtherModule', ['myModule']);50 module1.constant('aConstant', 42);51 module2.constant('anotherConstant', 43);52 var injector = createInjector(['myOtherModule']);53 expect(injector.has('aConstant')).toBe(true);54 expect(injector.has('anotherConstant')).toBe(true);55 });56 it('loads the transitively required modules of a module', function() {57 var module1 = window.angular.module('myModule', []);58 var module2 = window.angular.module('myOtherModule', ['myModule']);59 var module3 = window.angular.module('myThirdModule', ['myOtherModule']);60 module1.constant('aConstant', 42);61 module2.constant('anotherConstant', 43);62 module3.constant('aThirdConstant', 44);63 var injector = createInjector(['myThirdModule']);64 expect(injector.has('aConstant')).toBe(true);65 expect(injector.has('anotherConstant')).toBe(true);66 expect(injector.has('aThirdConstant')).toBe(true);67 });68 it('loads each module only once', function() {69 window.angular.module('myModule', ['myOtherModule']);70 window.angular.module('myOtherModule', ['myModule']);71 createInjector(['myModule']);72 });73 it('invokes an annotated function with dependency injection', function() {74 var module = window.angular.module('myModule', []);75 module.constant('a', 1);76 module.constant('b', 2);77 var injector = createInjector(['myModule']);78 var fn = function(one, two) { return one + two; };79 fn.$inject = ['a', 'b'];80 expect(injector.invoke(fn)).toBe(3);81 });82 it('does not accept non-strings as injection tokens', function() {83 var module = window.angular.module('myModule', []);84 module.constant('a', 1);85 var injector = createInjector(['myModule']);86 var fn = function(one, two) { return one + two; };87 fn.$inject = ['a', 2];88 expect(function() {89 injector.invoke(fn);90 }).toThrow();91 });92 it('invokes a function with the given this context', function() {93 var module = window.angular.module('myModule', []);94 module.constant('a', 1);95 var injector = createInjector(['myModule']);96 var obj = {97 two: 2,98 fn: function(one) { return one + this.two; }99 };100 obj.fn.$inject = ['a'];101 expect(injector.invoke(obj.fn, obj)).toBe(3);102 });103 it('overrides dependencies with locals when invoking', function() {104 var module = window.angular.module('myModule', []);105 module.constant('a', 1);106 module.constant('b', 2);107 var injector = createInjector(['myModule']);108 var fn = function(one, two) { return one + two; };109 fn.$inject = ['a', 'b'];110 expect(injector.invoke(fn, undefined, {b: 3})).toBe(4);111 });112 describe('annotate', function() {113 it('returns a functions $inject annotation when it has one', function() {114 var injector = createInjector([]);115 var fn = function() { };116 fn.$inject = ['a', 'b'];117 expect(injector.annotate(fn)).toEqual(['a', 'b']);118 });119 it('returns the array-style annotations of a function', function() {120 var injector = createInjector([]);121 var fn = ['a', 'b', function() { }];122 expect(injector.annotate(fn)).toEqual(['a', 'b']);123 });124 it('returns an empty array for a non-annotated function with no arguments', function() {125 var injector = createInjector([]);126 var fn = function() { };127 expect(injector.annotate(fn)).toEqual([]);128 });129 it('returns annotations parsed from a non-annotated function', function() {130 var injector = createInjector([]);131 var fn = function(a, b) { };132 expect(injector.annotate(fn)).toEqual(['a', 'b']);133 });134 it('strips comments from argument lists when parsing', function() {135 var injector = createInjector([]);136 var fn = function(a, /*b,*/ c) { };137 expect(injector.annotate(fn)).toEqual(['a', 'c']);138 });139 it('strips several comments from argument lists when parsing', function() {140 var injector = createInjector([]);141 var fn = function(a, /*b,*/ c/*, d*/) { };142 expect(injector.annotate(fn)).toEqual(['a', 'c']);143 });144 it('strips // comments from argument lists when parsing', function() {145 var injector = createInjector([]);146 var fn = function(a, //b,147 c) { };148 expect(injector.annotate(fn)).toEqual(['a', 'c']);149 });150 it('strips surrounding underscores from argument names when parsing', function() {151 var injector = createInjector([]);152 var fn = function(a, _b_, c_, _d, an_argument) { };153 expect(injector.annotate(fn)).toEqual(['a', 'b', 'c_', '_d', 'an_argument']);154 });155 it('throws when using a non-annotated function in strict mode', function() {156 var injector = createInjector([], true);157 var fn = function(a, b, c) { };158 expect(function() {159 injector.annotate(fn);160 }).toThrow();161 });162 });163 it('invokes an array-annotated function with dependency injection', function() {164 var module = window.angular.module('myModule', []);165 module.constant('a', 1);166 module.constant('b', 2);167 var injector = createInjector(['myModule']);168 var fn = ['a', 'b', function(one, two) { return one + two; }];169 expect(injector.invoke(fn)).toBe(3);170 });171 it('invokes a non-annotated function with dependency injection', function() {172 var module = window.angular.module('myModule', []);173 module.constant('a', 1);174 module.constant('b', 2);175 var injector = createInjector(['myModule']);176 var fn = function(a, b) { return a + b; };177 expect(injector.invoke(fn)).toBe(3);178 });179 it('instantiates an annotated constructor function', function() {180 var module = window.angular.module('myModule', []);181 module.constant('a', 1);182 module.constant('b', 2);183 var injector = createInjector(['myModule']);184 function Type(one, two) {185 this.result = one + two;186 }187 Type.$inject = ['a', 'b'];188 var instance = injector.instantiate(Type);189 expect(instance.result).toBe(3);190 });191 it('instantiates an array-annotated constructor function', function() {192 var module = window.angular.module('myModule', []);193 module.constant('a', 1);194 module.constant('b', 2);195 var injector = createInjector(['myModule']);196 function Type(one, two) {197 this.result = one + two;198 }199 var instance = injector.instantiate(['a', 'b', Type]);200 expect(instance.result).toBe(3);201 });202 it('instantiates a non-annotated constructor function', function() {203 var module = window.angular.module('myModule', []);204 module.constant('a', 1);205 module.constant('b', 2);206 var injector = createInjector(['myModule']);207 function Type(a, b) {208 this.result = a + b;209 }210 var instance = injector.instantiate(Type);211 expect(instance.result).toBe(3);212 });213 it('uses the prototype of the constructor when instantiating', function() {214 function BaseType() { }215 BaseType.prototype.getValue = _.constant(42);216 function Type() { this.v = this.getValue(); }217 Type.prototype = BaseType.prototype;218 var module = window.angular.module('myModule', []);219 var injector = createInjector(['myModule']);220 var instance = injector.instantiate(Type);221 expect(instance.v).toBe(42);222 });223 it('supports locals when instantiating', function() {224 var module = window.angular.module('myModule', []);225 module.constant('a', 1);226 module.constant('b', 2);227 var injector = createInjector(['myModule']);228 function Type(a, b) {229 this.result = a + b;230 }231 var instance = injector.instantiate(Type, {b: 3});232 expect(instance.result).toBe(4);233 });234 it('allows registering a provider and uses its $get', function() {235 var module = window.angular.module('myModule', []);236 module.provider('a', {237 $get: function() {238 return 42;239 }240 });241 var injector = createInjector(['myModule']);242 expect(injector.has('a')).toBe(true);243 expect(injector.get('a')).toBe(42);244 });245 it('injects the $get method of a provider', function() {246 var module = window.angular.module('myModule', []);247 module.constant('a', 1);248 module.provider('b', {249 $get: function(a) {250 return a + 2;251 }252 });253 var injector = createInjector(['myModule']);254 expect(injector.get('b')).toBe(3);255 });256 it('injects the $get method of a provider lazily', function() {257 var module = window.angular.module('myModule', []);258 module.provider('b', {259 $get: function(a) {260 return a + 2;261 }262 });263 module.provider('a', {$get: _.constant(1)});264 var injector = createInjector(['myModule']);265 expect(injector.get('b')).toBe(3);266 });267 it('instantiates a dependency only once', function() {268 var module = window.angular.module('myModule', []);269 module.provider('a', {$get: function() { return {}; }});270 var injector = createInjector(['myModule']);271 expect(injector.get('a')).toBe(injector.get('a'));272 });273 it('notifies the user about a circular dependency', function() {274 var module = window.angular.module('myModule', []);275 module.provider('a', {$get: function(b) { }});276 module.provider('b', {$get: function(c) { }});277 module.provider('c', {$get: function(a) { }});278 var injector = createInjector(['myModule']);279 expect(function() {280 injector.get('a');281 }).toThrowError('Circular dependency found: a <- c <- b <- a');282 });283 it('cleans up the circular marker when instantiation fails', function() {284 var module = window.angular.module('myModule', []);285 module.provider('a', {$get: function() {286 throw 'Failing instantiation!';287 }});288 var injector = createInjector(['myModule']);289 expect(function() {290 injector.get('a');291 }).toThrow('Failing instantiation!');292 expect(function() {293 injector.get('a');294 }).toThrow('Failing instantiation!');295 });296 it('instantiates a provider if given as a constructor function', function() {297 var module = window.angular.module('myModule', []);298 module.provider('a', function AProvider() {299 this.$get = function() { return 42; };300 });301 var injector = createInjector(['myModule']);302 expect(injector.get('a')).toBe(42);303 });304 it('injects the given provider constructor function', function() {305 var module = window.angular.module('myModule', []);306 module.constant('b', 2);307 module.provider('a', function AProvider(b) {308 this.$get = function() { return 1 + b; };309 });310 var injector = createInjector(['myModule']);311 expect(injector.get('a')).toBe(3);312 });313 it('injects another provider to a provider constructor function', function() {314 var module = window.angular.module('myModule', []);315 module.provider('a', function AProvider() {316 var value = 1;317 this.setValue = function(v) { value = v; };318 this.$get = function() { return value; };319 });320 module.provider('b', function BProvider(aProvider) {321 aProvider.setValue(2);322 this.$get = function() { };323 });324 var injector = createInjector(['myModule']);325 expect(injector.get('a')).toBe(2);326 });327 it('does not inject an instance to a provider constructor function', function() {328 var module = window.angular.module('myModule', []);329 module.provider('a', function AProvider() {330 this.$get = function() { return 1; };331 });332 module.provider('b', function BProvider(a) {333 this.$get = function() { return a; };334 });335 expect(function() {336 createInjector(['myModule']);337 }).toThrow();338 });339 it('does not inject a provider to a $get function', function() {340 var module = window.angular.module('myModule', []);341 module.provider('a', function AProvider() {342 this.$get = function() { return 1; };343 });344 module.provider('b', function BProvider() {345 this.$get = function(aProvider) { return aProvider.$get(); };346 });347 var injector = createInjector(['myModule']);348 expect(function() {349 injector.get('b');350 }).toThrow();351 });352 it('does not inject a provider to invoke', function() {353 var module = window.angular.module('myModule', []);354 module.provider('a', function AProvider() {355 this.$get = function() { return 1; };356 });357 var injector = createInjector(['myModule']);358 expect(function() {359 injector.invoke(function(aProvider) { });360 }).toThrow();361 });362 it('does not give access to providers through get', function() {363 var module = window.angular.module('myModule', []);364 module.provider('a', function AProvider() {365 this.$get = function() { return 1; };366 });367 var injector = createInjector(['myModule']);368 expect(function() {369 injector.get('aProvider');370 }).toThrow();371 });372 it('registers constants first to make them available to providers', function() {373 var module = window.angular.module('myModule', []);374 module.provider('a', function AProvider(b) {375 this.$get = function() { return b; };376 });377 module.constant('b', 42);378 var injector = createInjector(['myModule']);379 expect(injector.get('a')).toBe(42);380 });381 it('allows injecting the instance injector to $get', function() {382 var module = window.angular.module('myModule', []);383 module.constant('a', 42);384 module.provider('b', function BProvider() {385 this.$get = function($injector) {386 return $injector.get('a');387 };388 });389 var injector = createInjector(['myModule']);390 expect(injector.get('b')).toBe(42);391 });392 it('allows injecting the provider injector to provider', function() {393 var module = window.angular.module('myModule', []);394 module.provider('a', function AProvider() {395 this.value = 42;396 this.$get = function() { return this.value; };397 });398 module.provider('b', function BProvider($injector) {399 var aProvider = $injector.get('aProvider');400 this.$get = function() {401 return aProvider.value;402 };403 });404 var injector = createInjector(['myModule']);405 expect(injector.get('b')).toBe(42);406 });407 it('allows injecting the $provide service to providers', function() {408 var module = window.angular.module('myModule', []);409 module.provider('a', function AProvider($provide) {410 $provide.constant('b', 2);411 this.$get = function(b) { return 1 + b; };412 });413 var injector = createInjector(['myModule']);414 expect(injector.get('a')).toBe(3);415 });416 it('does not allow injecting the $provide service to $get', function() {417 var module = window.angular.module('myModule', []);418 module.provider('a', function AProvider() {419 this.$get = function($provide) { };420 });421 var injector = createInjector(['myModule']);422 expect(function() {423 injector.get('a');424 }).toThrow();425 });426 it('runs config blocks when the injector is created', function() {427 var module = window.angular.module('myModule', []);428 var hasRun = false;429 module.config(function() {430 hasRun = true;431 });432 createInjector(['myModule']);433 expect(hasRun).toBe(true);434 });435 it('injects config blocks with provider injector', function() {436 var module = window.angular.module('myModule', []);437 module.config(function($provide) {438 $provide.constant('a', 42);439 });440 var injector = createInjector(['myModule']);441 expect(injector.get('a')).toBe(42);442 });443 it('allows registering config blocks before providers', function() {444 var module = window.angular.module('myModule', []);445 module.config(function(aProvider) { });446 module.provider('a', function() {447 this.$get = _.constant(42);448 });449 var injector = createInjector(['myModule']);450 expect(injector.get('a')).toBe(42);451 });452 it('runs a config block added during module registration', function() {453 var module = window.angular.module('myModule', [], function($provide) {454 $provide.constant('a', 42);455 });456 var injector = createInjector(['myModule']);457 expect(injector.get('a')).toBe(42);458 });459 it('runs run blocks when the injector is created', function() {460 var module = window.angular.module('myModule', []);461 var hasRun = false;462 module.run(function() {463 hasRun = true;464 });465 createInjector(['myModule']);466 expect(hasRun).toBe(true);467 });468 it('injects run blocks with the instance injector', function() {469 var module = window.angular.module('myModule', []);470 module.provider('a', {$get: _.constant(42)});471 var gotA;472 module.run(function(a) {473 gotA = a;474 });475 createInjector(['myModule']);476 expect(gotA).toBe(42);477 });478 it('configures all modules before running any run blocks', function() {479 var module1 = window.angular.module('myModule', []);480 module1.provider('a', {$get: _.constant(1)});481 var result;482 module1.run(function(a, b) {483 result = a + b;484 });485 var module2 = window.angular.module('myOtherModule', []);486 module2.provider('b', {$get: _.constant(2)});487 createInjector(['myModule', 'myOtherModule']);488 expect(result).toBe(3);489 });490 it('runs a function module dependency as a config block', function() {491 window.angular.module('myModule', [function($provide) {492 $provide.constant('a', 42);493 }]);494 var injector = createInjector(['myModule']);495 expect(injector.get('a')).toBe(42);496 });497 it('runs a function module with array injection as a config block', function() {498 window.angular.module('myModule', [['$provide', function($provide) {499 $provide.constant('a', 42);500 }]]);501 var injector = createInjector(['myModule']);502 expect(injector.get('a')).toBe(42);503 });504 it('supports returning a run block from a function module', function() {505 var result;506 var requiredModule = function($provide) {507 $provide.constant('a', 42);508 return function(a) {509 result = a;510 };511 };512 window.angular.module('myModule', [requiredModule]);513 createInjector(['myModule']);514 expect(result).toBe(42);515 });516 it('only loads function modules once', function() {517 var loadedTimes = 0;518 var fnModule = function() {519 loadedTimes++;520 };521 window.angular.module('myModule', [fnModule, fnModule]);522 createInjector(['myModule']);523 expect(loadedTimes).toBe(1);524 });525 it('allows registering a factory', function() {526 var module = window.angular.module('myModule', []);527 module.factory('a', function() { return 42; });528 var injector = createInjector(['myModule']);529 expect(injector.get('a')).toBe(42);530 });531 it('injects a factory function with instances', function() {532 var module = window.angular.module('myModule', []);533 module.factory('a', function() { return 1; });534 module.factory('b', function(a) { return a + 2; });535 var injector = createInjector(['myModule']);536 expect(injector.get('b')).toBe(3);537 });538 it('only calls a factory function once', function() {539 var module = window.angular.module('myModule', []);540 module.factory('a', function() { return {}; });541 var injector = createInjector(['myModule']);542 expect(injector.get('a')).toBe(injector.get('a'));543 });544 it('forces a factory to return a value', function() {545 var module = window.angular.module('myModule', []);546 module.factory('a', function() { });547 module.factory('b', function() { return null; });548 var injector = createInjector(['myModule']);549 expect(function() {550 injector.get('a');551 }).toThrow();552 expect(injector.get('b')).toBeNull();553 });554 it('allows registering a value', function() {555 var module = window.angular.module('myModule', []);556 module.value('a', 42);557 var injector = createInjector(['myModule']);558 expect(injector.get('a')).toBe(42);559 });560 it('does not make values available to config blocks', function() {561 var module = window.angular.module('myModule', []);562 module.value('a', 42);563 module.config(function(a) {564 });565 expect(function() {566 createInjector(['myModule']);567 }).toThrow();568 });569 it('allows an undefined value', function() {570 var module = window.angular.module('myModule', []);571 module.value('a', undefined);572 var injector = createInjector(['myModule']);573 expect(injector.get('a')).toBeUndefined();574 });575 it('allows registering a service', function() {576 var module = window.angular.module('myModule', []);577 module.service('aService', function MyService() {578 this.getValue = function() { return 42; };579 });580 var injector = createInjector(['myModule']);581 expect(injector.get('aService').getValue()).toBe(42);582 });583 it('injects service constructors with instances', function() {584 var module = window.angular.module('myModule', []);585 module.value('theValue', 42);586 module.service('aService', function MyService(theValue) {587 this.getValue = function() { return theValue; };588 });589 var injector = createInjector(['myModule']);590 expect(injector.get('aService').getValue()).toBe(42);591 });592 it('only instantiates services once', function() {593 var module = window.angular.module('myModule', []);594 module.service('aService', function MyService() {595 });596 var injector = createInjector(['myModule']);597 expect(injector.get('aService')).toBe(injector.get('aService'));598 });599 it('allows changing an instance using a decorator', function() {600 var module = window.angular.module('myModule', []);601 module.factory('aValue', function() {602 return {};603 });604 module.decorator('aValue', function($delegate) {605 $delegate.decoratedKey = 42;606 });607 var injector = createInjector(['myModule']);608 expect(injector.get('aValue').decoratedKey).toBe(42);609 });610 it('allows multiple decorators per service', function() {611 var module = window.angular.module('myModule', []);612 module.factory('aValue', function() {613 return {};614 });615 module.decorator('aValue', function($delegate) {616 $delegate.decoratedKey = 42;617 });618 module.decorator('aValue', function($delegate) {619 $delegate.otherDecoratedKey = 43;620 });621 var injector = createInjector(['myModule']);622 expect(injector.get('aValue').decoratedKey).toBe(42);623 expect(injector.get('aValue').otherDecoratedKey).toBe(43);624 });625 it('uses dependency injection with decorators', function() {626 var module = window.angular.module('myModule', []);627 module.factory('aValue', function() {628 return {};629 });630 module.constant('a', 42);631 module.decorator('aValue', function(a, $delegate) {632 $delegate.decoratedKey = a;633 });634 var injector = createInjector(['myModule']);635 expect(injector.get('aValue').decoratedKey).toBe(42);636 });...

Full Screen

Full Screen

moduleIds.js

Source:moduleIds.js Github

copy

Full Screen

1define(["doh", "dojo", "dojo/_base/url"], function(doh, dojo){2 var compactPath = function(path){3 var4 result= [],5 segment, lastSegment;6 path= path.split("/");7 while(path.length){8 segment= path.shift();9 if(segment==".." && result.length && lastSegment!=".."){10 result.pop();11 }else if(segment!="."){12 result.push(lastSegment= segment);13 } // else ignore "."14 }15 return result.join("/");16 };17 doh.register("dojo.tests._base._loader.modulesIds", [18 function compactPath(t){19 var compactPath = require.compactPath;20 t.is(compactPath("../../dojo/../../mytests"), "../../../mytests");21 t.is(compactPath("module"), "module");22 t.is(compactPath("a/./b"), "a/b");23 t.is(compactPath("a/../b"), "b");24 t.is(compactPath("a/./b/./c/./d"), "a/b/c/d");25 t.is(compactPath("a/../b/../c/../d"), "d");26 t.is(compactPath("a/b/c/../../d"), "a/d");27 t.is(compactPath("a/b/c/././d"), "a/b/c/d");28 t.is(compactPath("./a/b"), "a/b");29 t.is(compactPath("../a/b"), "../a/b");30 t.is(compactPath(""), "");31 },32 function testModuleIds(t){33 require({34 packages:[{35 // canonical...36 name:"pack1",37 location:"../packages/pack1Root"38 }, {39 // nonstandard main40 name:"pack2",41 main:"pack2Main",42 location:"/pack2Root"43 }, {44 // nonstandard main45 name:"pack3",46 main:"public/main",47 location:"/pack3Root"48 }]49 });50 function get(mid, refmod){51 return require.getModuleInfo(mid, refmod, require.packs, require.modules, "../../dojo/", require.mapProgs, require.pathsMapProg, 1);52 }53 function check(result, expectedPid, expectedMidSansPid, expectedUrl){54 t.is(result.pid, expectedPid);55 t.is(result.mid, expectedPid + "/" + expectedMidSansPid);56 t.is(result.url, expectedUrl + ".js");57 }58 // non-relative module id resolution...59 var pack1Root= "../../packages/pack1Root/";60 // the various mains...61 check(get("pack1"), "pack1", "main", pack1Root + "main");62 check(get("pack2"), "pack2", "pack2Main", "/pack2Root/pack2Main");63 check(get("pack3"), "pack3", "public/main", "/pack3Root/public/main");64 // modules...65 check(get("pack1/myModule"), "pack1", "myModule", pack1Root + "myModule");66 check(get("pack2/myModule"), "pack2", "myModule", "/pack2Root/myModule");67 check(get("pack3/myModule"), "pack3", "myModule", "/pack3Root/myModule");68 // relative module id resolution; relative to module in top-level69 var refmod= {mid:"pack1/main", pack:require.packs.pack1};70 check(get(".", refmod), "pack1", "main", pack1Root + "main");71 check(get("./myModule", refmod), "pack1", "myModule", pack1Root + "myModule");72 check(get("./myModule/mySubmodule", refmod), "pack1", "myModule/mySubmodule", pack1Root + "myModule/mySubmodule");73 // relative module id resolution; relative to module74 refmod= {mid:"pack1/sub/publicModule", pack:require.packs.pack1};75 check(get(".", refmod), "pack1", "sub", pack1Root + "sub");76 check(get("./myModule", refmod), "pack1", "sub/myModule", pack1Root + "sub/myModule");77 check(get("..", refmod), "pack1", "main", pack1Root + "main");78 check(get("../myModule", refmod), "pack1", "myModule", pack1Root + "myModule");79 check(get("../util/myModule", refmod), "pack1", "util/myModule", pack1Root + "util/myModule");80 },81 function baseUrl(t){82 var originalBaseUrl = dojo.config["baseUrl"] || "./";83 t.assertEqual(originalBaseUrl, dojo.baseUrl);84 },85 function moduleUrl(t){86 var expected = require.toUrl("dojo/tests/myTest.html");87 t.is(null, dojo.moduleUrl());88 t.is(null, dojo.moduleUrl(null));89 t.is(null, dojo.moduleUrl(null, "myTest.html"));90 // note we expect a trailing slash91 t.is(expected.substring(0, expected.length - 11), dojo.moduleUrl("dojo.tests"));92 t.is(expected, dojo.moduleUrl("dojo.tests", "myTest.html"));93 },94 function modulePaths(t){95 dojo.registerModulePath("mycoolmod", "../some/path/mycoolpath");96 dojo.registerModulePath("mycoolmod.widget", "http://some.domain.com/another/path/mycoolpath/widget");97 t.assertEqual(compactPath(require.baseUrl + "../some/path/mycoolpath/util/"), dojo.moduleUrl("mycoolmod.util"));98 t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/", dojo.moduleUrl("mycoolmod.widget"));99 t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/thingy/", dojo.moduleUrl("mycoolmod.widget.thingy"));100 },101 function moduleUrls(t){102 dojo.registerModulePath("mycoolmod", "some/path/mycoolpath");103 dojo.registerModulePath("mycoolmod2", "/some/path/mycoolpath2");104 dojo.registerModulePath("mycoolmod.widget", "http://some.domain.com/another/path/mycoolpath/widget");105 dojo.registerModulePath("ipv4.widget", "http://ipv4user:ipv4passwd@some.domain.com:2357/another/path/ipv4/widget");106 dojo.registerModulePath("ipv6.widget", "ftp://ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113/another/path/ipv6/widget");107 dojo.registerModulePath("ipv6.widget2", "https://[0:0:0:0:0:1]/another/path/ipv6/widget2");108 var basePrefix = require.baseUrl;109 t.assertEqual(compactPath(basePrefix + "some/path/mycoolpath/my/favorite.html"),110 dojo.moduleUrl("mycoolmod", "my/favorite.html"));111 t.assertEqual(compactPath(basePrefix + "some/path/mycoolpath/my/favorite.html"),112 dojo.moduleUrl("mycoolmod.my", "favorite.html"));113 t.assertEqual("/some/path/mycoolpath2/my/favorite.html",114 dojo.moduleUrl("mycoolmod2", "my/favorite.html"));115 t.assertEqual("/some/path/mycoolpath2/my/favorite.html",116 dojo.moduleUrl("mycoolmod2.my", "favorite.html"));117 t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/my/favorite.html",118 dojo.moduleUrl("mycoolmod.widget", "my/favorite.html"));119 t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/my/favorite.html",120 dojo.moduleUrl("mycoolmod.widget.my", "favorite.html"));121 // individual component testing122 t.assertEqual("http://ipv4user:ipv4passwd@some.domain.com:2357/another/path/ipv4/widget/components.html",123 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).uri);124 t.assertEqual("http",125 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).scheme);126 t.assertEqual("ipv4user:ipv4passwd@some.domain.com:2357",127 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).authority);128 t.assertEqual("ipv4user",129 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).user);130 t.assertEqual("ipv4passwd",131 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).password);132 t.assertEqual("some.domain.com",133 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).host);134 t.assertEqual("2357",135 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).port);136 t.assertEqual("/another/path/ipv4/widget/components.html",137 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html?query"))).path);138 t.assertEqual("q=somequery",139 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html?q=somequery"))).query);140 t.assertEqual("fragment",141 (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html#fragment"))).fragment);142 t.assertEqual("ftp://ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113/another/path/ipv6/widget/components.html",143 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).uri);144 t.assertEqual("ftp",145 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).scheme);146 t.assertEqual("ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113",147 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).authority);148 t.assertEqual("ipv6user",149 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).user);150 t.assertEqual("ipv6passwd",151 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).password);152 t.assertEqual("::2001:0db8:3c4d:0015:0:0:abcd:ef12",153 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).host);154 t.assertEqual("1113",155 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).port);156 t.assertEqual("/another/path/ipv6/widget/components.html",157 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?query"))).path);158 t.assertEqual("somequery",159 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?somequery"))).query);160 t.assertEqual("somefragment",161 (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?somequery#somefragment"))).fragment);162 t.assertEqual("https://[0:0:0:0:0:1]/another/path/ipv6/widget2/components.html",163 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).uri);164 t.assertEqual("https",165 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).scheme);166 t.assertEqual("[0:0:0:0:0:1]",167 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).authority);168 t.assertEqual(null,169 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).user);170 t.assertEqual(null,171 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).password);172 t.assertEqual("0:0:0:0:0:1",173 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).host);174 t.assertEqual(null,175 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).port);176 t.assertEqual("/another/path/ipv6/widget2/components.html",177 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).path);178 t.assertEqual(null,179 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).query);180 t.assertEqual(null,181 (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).fragment);182 }183 ]);...

Full Screen

Full Screen

micro_app_module.js

Source:micro_app_module.js Github

copy

Full Screen

1function MyModule(id = ''){2 this.id = id;3 this.exports = {};4 this.filename = null;5 this.loaded = false;6}7MyModule.prototype.require = function(id){8 return MyModule._load(id);9}10MyModule._cache = Object.create(null)11MyModule._extensions = Object.create(null);12MyModule._load = function(request){13 let filename = request;14 let cacheModule = MyModule._cache[filename]15 if(cacheModule !== undefined){16 return cacheModule.exports;17 }18 let module = new MyModule(filename);19 module.load(filename);20 return module.exports;21}22MyModule.prototype.load = function(filename){23 let splits = filename.split('.');24 let extname = '.'+splits[splits.length-1];25 MyModule._extensions[extname](this,filename);26 this.loaded = true;27}28MyModule._extensions['.js'] = function(module, filename) {29 // ͬ²½ajaxÇëÇóÈ¡»ØjsÎļþ30 let response = $.ajax({31 url: 'dist/' + filename,32 async: false,33 })34 if(response.status == 200){ // ±àÒëjsÎļþ35 let content = response.responseText;36 module._compile(content, filename);37 }38 39}40MyModule.wrapper = [41 '(function (exports, require, module) { ',42 '\n});'43];44MyModule.wrap = function (script) {45 return MyModule.wrapper[0] + script + MyModule.wrapper[1];46};47MyModule.prototype._compile = function(content, filename){48 let wrapper = MyModule.wrap(content);49 compiledWrapper = eval(wrapper)50 compiledWrapper(this.exports, this.require, this);51}52MyModule._extensions['.json'] = function (module, filename) {53 const content = fs.readFileSync(filename, 'utf8');54 module.exports = JSONParse(content);55}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender } from 'ng-mocks';2import { MyComponent } from './my.component';3import { MyModule } from './my.module';4describe('MyComponent', () => {5 beforeEach(() => MockBuilder(MyComponent).keep(MyModule));6 it('renders the component', () => {7 const fixture = MockRender(MyComponent);8 expect(fixture.nativeElement.innerHTML).toContain('my works!');9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { myModule } from 'ng-mocks';2import { myModule } from 'ng-mocks';3import { myModule } from 'ng-mocks';4import { myModule } from 'ng-mocks';5import { myModule } from 'ng-mocks';6import { myModule } from 'ng-mocks';7import { myModule } from 'ng-mocks';8import { myModule } from 'ng-mocks';9import { myModule } from 'ng-mocks';10import { myModule } from 'ng-mocks';11import { myModule } from 'ng-mocks';12import { myModule } from 'ng-mocks';13import { myModule } from 'ng-mocks';14import { myModule } from 'ng-mocks';15import { myModule } from 'ng-mocks';16import { myModule } from 'ng-mocks';17import { myModule } from 'ng-mocks';18import { myModule } from 'ng-mocks';19import { myModule } from 'ng-mocks';20import { myModule } from 'ng

Full Screen

Using AI Code Generation

copy

Full Screen

1import { myModule } from 'ng-mocks';2import { myModule } from 'ng-mocks';3import { myModule } from 'ng-mocks';4import { myModule } from 'ng-mocks';5import { myModule } from 'ng-mocks';6import { myModule } from 'ng-mocks';7import { myModule } from 'ng-mocks';8import { myModule } from 'ng-mocks';9import { myModule } from 'ng-mocks';10import { myModule } from 'ng-mocks';11import { myModule } from 'ng-mocks';12import { myModule } from 'ng-mocks';13import { myModule } from 'ng-mocks';14import { myModule } from 'ng-mocks';15import { myModule } from 'ng-mocks';16import { myModule } from 'ng-mocks';17import { myModule } from 'ng-mocks';18import { myModule } from 'ng-mocks';19import { myModule } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mockModule } from 'ng-mocks';2import { mockModule } from 'ng-mocks';3import { AppModule } from './app.module';4describe('AppComponent', () => {5 beforeEach(async(() => {6 TestBed.configureTestingModule({7 imports: [AppModule],8 }).compileComponents();9 }));10 it('should create the app', () => {11 const fixture = TestBed.createComponent(AppComponent);12 const app = fixture.debugElement.componentInstance;13 expect(app).toBeTruthy();14 });15 it(`should have as title 'app'`, () => {16 const fixture = TestBed.createComponent(AppComponent);17 const app = fixture.debugElement.componentInstance;18 expect(app.title).toEqual('app');19 });20 it('should render title in a h1 tag', () => {21 const fixture = TestBed.createComponent(AppComponent);22 fixture.detectChanges();23 const compiled = fixture.debugElement.nativeElement;24 expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');25 });26});27import { BrowserModule } from '@angular/platform-browser';28import { NgModule } from '@angular/core';29import { AppComponent } from './app.component';30@NgModule({31 imports: [32})33export class AppModule { }34import { Component } from '@angular/core';35@Component({36})37export class AppComponent {38 title = 'app';39}40body {41 margin: 0;42 font-family: Roboto, "Helvetica Neue", sans-serif;43}44import { Component, OnInit } from '@angular/core';45@Component({46})47export class AppHeaderComponent implements OnInit {48 constructor() { }49 ngOnInit() {50 }51}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('myModule', function () {2 var $httpBackend;3 beforeEach(module('myModule'));4 beforeEach(inject(function (_$httpBackend_) {5 $httpBackend = _$httpBackend_;6 }));7 it('should make a request', function () {8 $httpBackend.expectGET('/api/endpoint').respond(200, 'success');9 $httpBackend.flush();10 });11});12angular.module('myModule', [])13.config(function ($httpProvider) {14 $httpProvider.interceptors.push('myModuleInterceptor');15})16.factory('myModuleInterceptor', function () {17 return {18 request: function (config) {19 config.url = '/api/endpoint';20 return config;21 }22 };23});24angular.module('myModule', [])25.config(function ($httpProvider) {26 $httpProvider.interceptors.push('myModuleInterceptor');27})28.factory('myModuleInterceptor', function () {29 return {30 request: function (config) {31 config.url = '/api/endpoint';32 return config;33 }34 };35});36angular.module('myModule', [])37.config(function ($httpProvider) {38 $httpProvider.interceptors.push('myModuleInterceptor');39})40.factory('myModuleInterceptor', function () {41 return {42 request: function (config) {43 config.url = '/api/endpoint';44 return config;45 }46 };47});48angular.module('myModule', [])49.config(function ($httpProvider) {50 $httpProvider.interceptors.push('myModuleInterceptor');51})52.factory('myModuleInterceptor', function () {53 return {54 request: function (config) {55 config.url = '/api/endpoint';56 return config;57 }58 };59});60angular.module('myModule', [])61.config(function ($httpProvider) {62 $httpProvider.interceptors.push('myModuleInterceptor');63})64.factory('myModuleInterceptor', function () {65 return {66 request: function (config) {67 config.url = '/api/endpoint';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {mock} from 'ng-mocks';2import {MyModule} from './my-module'3describe('MyModule', () => {4 it('should have a method', () => {5 const myModule = mock(MyModule);6 expect(myModule.myMethod).toBeDefined();7 });8});9import {Injectable} from '@angular/core';10@Injectable()11export class MyModule {12 myMethod() {13 return 'myMethod';14 }15}

Full Screen

Using AI Code Generation

copy

Full Screen

1I am trying to use ng-mocks library to help me test my angular modules. I am having trouble getting the library to work with my test files. I am using the following import statement in my test files:2import { myModule } from 'ng-mocks';3My test files are in the same directory as the module I am trying to test. The test files are named test.js. I am using mocha for my test runner. The error that I am getting is: Error: Cannot find module 'myModule'. I have tried using the following import statement:4import { myModule } from 'ng-mocks/dist/ng-mocks';5But I get the same error. I am not sure what I am doing wrong. Can someone help me figure out how to get this import statement to work?6I am trying to use ng-mocks library to help me test my angular modules. I am having trouble getting the library to work with my test files. I am using the following import statement in my test files:7import { myModule } from 'ng-mocks';8My test files are in the same directory as the module I am trying to test. The test files are named test.js. I am using mocha for my test runner. The error that I am getting is: Error: Cannot find module 'myModule'. I have tried using the following import statement:9import { myModule } from 'ng-mocks/dist/ng-mocks';

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