How to use sinon.match method in sinon

Best JavaScript code snippet using sinon

ScopeFactoryTest.js

Source:ScopeFactoryTest.js Github

copy

Full Screen

1/*2 * PHPCore - PHP environment runtime components3 * Copyright (c) Dan Phillimore (asmblah)4 * https://github.com/uniter/phpcore/5 *6 * Released under the MIT license7 * https://github.com/uniter/phpcore/raw/master/MIT-LICENSE.txt8 */9'use strict';10var expect = require('chai').expect,11 phpCommon = require('phpcommon'),12 sinon = require('sinon'),13 CallStack = require('../../src/CallStack'),14 Class = require('../../src/Class').sync(),15 ClosureFactory = require('../../src/ClosureFactory').sync(),16 Environment = require('../../src/Environment'),17 FunctionSpecFactory = require('../../src/Function/FunctionSpecFactory'),18 Module = require('../../src/Module'),19 Namespace = require('../../src/Namespace').sync(),20 ReferenceFactory = require('../../src/ReferenceFactory').sync(),21 ScopeFactory = require('../../src/ScopeFactory'),22 SuperGlobalScope = require('../../src/SuperGlobalScope').sync(),23 Translator = phpCommon.Translator,24 Value = require('../../src/Value').sync(),25 ValueFactory = require('../../src/ValueFactory').sync(),26 VariableFactory = require('../../src/VariableFactory').sync();27describe('ScopeFactory', function () {28 var callStack,29 closureFactory,30 factory,31 functionSpecFactory,32 globalNamespace,33 globalScope,34 LoadScope,35 ModuleScope,36 NamespaceScope,37 referenceFactory,38 Scope,39 superGlobalScope,40 translator,41 valueFactory,42 variableFactory;43 beforeEach(function () {44 callStack = sinon.createStubInstance(CallStack);45 closureFactory = sinon.createStubInstance(ClosureFactory);46 functionSpecFactory = sinon.createStubInstance(FunctionSpecFactory);47 LoadScope = sinon.stub();48 ModuleScope = sinon.stub();49 NamespaceScope = sinon.stub();50 Scope = sinon.stub();51 globalNamespace = sinon.createStubInstance(Namespace);52 globalScope = sinon.createStubInstance(Scope);53 referenceFactory = sinon.createStubInstance(ReferenceFactory);54 superGlobalScope = sinon.createStubInstance(SuperGlobalScope);55 translator = sinon.createStubInstance(Translator);56 valueFactory = sinon.createStubInstance(ValueFactory);57 variableFactory = sinon.createStubInstance(VariableFactory);58 factory = new ScopeFactory(59 ModuleScope,60 LoadScope,61 Scope,62 NamespaceScope,63 callStack,64 translator,65 superGlobalScope,66 functionSpecFactory,67 valueFactory,68 variableFactory,69 referenceFactory70 );71 factory.setClosureFactory(closureFactory);72 factory.setGlobalNamespace(globalNamespace);73 factory.setGlobalScope(globalScope);74 });75 describe('create()', function () {76 var callCreate,77 currentClass,78 currentFunction,79 name,80 thisObject;81 beforeEach(function () {82 name = 'MyNamespace';83 currentClass = sinon.createStubInstance(Class);84 currentFunction = sinon.stub();85 thisObject = sinon.createStubInstance(Value);86 callCreate = function () {87 return factory.create(88 currentClass,89 currentFunction,90 thisObject91 );92 };93 });94 it('should return an instance of Scope', function () {95 expect(callCreate()).to.be.an.instanceOf(Scope);96 });97 it('should create one scope', function () {98 callCreate();99 expect(Scope).to.have.been.calledOnce;100 });101 it('should pass the CallStack to the scope', function () {102 callCreate();103 expect(Scope).to.have.been.calledWith(sinon.match.same(callStack));104 });105 it('should pass the Translator to the scope', function () {106 callCreate();107 expect(Scope).to.have.been.calledWith(108 sinon.match.any,109 sinon.match.same(translator)110 );111 });112 it('should pass the global scope to the scope', function () {113 callCreate();114 expect(Scope).to.have.been.calledWith(115 sinon.match.any,116 sinon.match.any,117 sinon.match.same(globalScope)118 );119 });120 it('should pass the SuperGlobalScope to the scope', function () {121 callCreate();122 expect(Scope).to.have.been.calledWith(123 sinon.match.any,124 sinon.match.any,125 sinon.match.any,126 sinon.match.same(superGlobalScope)127 );128 });129 it('should pass the ClosureFactory to the scope', function () {130 callCreate();131 expect(Scope).to.have.been.calledWith(132 sinon.match.any,133 sinon.match.any,134 sinon.match.any,135 sinon.match.any,136 sinon.match.same(closureFactory)137 );138 });139 it('should pass the FunctionSpecFactory to the scope', function () {140 callCreate();141 expect(Scope).to.have.been.calledWith(142 sinon.match.any,143 sinon.match.any,144 sinon.match.any,145 sinon.match.any,146 sinon.match.any,147 sinon.match.same(functionSpecFactory)148 );149 });150 it('should pass the ValueFactory to the scope', function () {151 callCreate();152 expect(Scope).to.have.been.calledWith(153 sinon.match.any,154 sinon.match.any,155 sinon.match.any,156 sinon.match.any,157 sinon.match.any,158 sinon.match.any,159 sinon.match.same(valueFactory)160 );161 });162 it('should pass the VariableFactory to the scope', function () {163 callCreate();164 expect(Scope).to.have.been.calledWith(165 sinon.match.any,166 sinon.match.any,167 sinon.match.any,168 sinon.match.any,169 sinon.match.any,170 sinon.match.any,171 sinon.match.any,172 sinon.match.same(variableFactory)173 );174 });175 it('should pass the ReferenceFactory to the scope', function () {176 callCreate();177 expect(Scope).to.have.been.calledWith(178 sinon.match.any,179 sinon.match.any,180 sinon.match.any,181 sinon.match.any,182 sinon.match.any,183 sinon.match.any,184 sinon.match.any,185 sinon.match.any,186 sinon.match.same(referenceFactory)187 );188 });189 it('should pass the current class to the scope when specified', function () {190 callCreate();191 expect(Scope).to.have.been.calledWith(192 sinon.match.any,193 sinon.match.any,194 sinon.match.any,195 sinon.match.any,196 sinon.match.any,197 sinon.match.any,198 sinon.match.any,199 sinon.match.any,200 sinon.match.any,201 sinon.match.same(currentClass)202 );203 });204 it('should pass null as the current class to the scope when not specified', function () {205 currentClass = null;206 callCreate();207 expect(Scope).to.have.been.calledWith(208 sinon.match.any,209 sinon.match.any,210 sinon.match.any,211 sinon.match.any,212 sinon.match.any,213 sinon.match.any,214 sinon.match.any,215 sinon.match.any,216 sinon.match.any,217 null218 );219 });220 it('should pass the current function to the scope when specified', function () {221 callCreate();222 expect(Scope).to.have.been.calledWith(223 sinon.match.any,224 sinon.match.any,225 sinon.match.any,226 sinon.match.any,227 sinon.match.any,228 sinon.match.any,229 sinon.match.any,230 sinon.match.any,231 sinon.match.any,232 sinon.match.any,233 sinon.match.same(currentFunction)234 );235 });236 it('should pass null as the current function to the scope when not specified', function () {237 currentFunction = false;238 callCreate();239 expect(Scope).to.have.been.calledWith(240 sinon.match.any,241 sinon.match.any,242 sinon.match.any,243 sinon.match.any,244 sinon.match.any,245 sinon.match.any,246 sinon.match.any,247 sinon.match.any,248 sinon.match.any,249 sinon.match.any,250 null251 );252 });253 it('should pass the thisObject to the scope when specified', function () {254 callCreate();255 expect(Scope).to.have.been.calledWith(256 sinon.match.any,257 sinon.match.any,258 sinon.match.any,259 sinon.match.any,260 sinon.match.any,261 sinon.match.any,262 sinon.match.any,263 sinon.match.any,264 sinon.match.any,265 sinon.match.any,266 sinon.match.any,267 sinon.match.same(thisObject)268 );269 });270 it('should pass null as the thisObject to the scope when not specified', function () {271 thisObject = false;272 callCreate();273 expect(Scope).to.have.been.calledWith(274 sinon.match.any,275 sinon.match.any,276 sinon.match.any,277 sinon.match.any,278 sinon.match.any,279 sinon.match.any,280 sinon.match.any,281 sinon.match.any,282 sinon.match.any,283 sinon.match.any,284 sinon.match.any,285 null286 );287 });288 });289 describe('createLoadScope()', function () {290 var callCreateLoadScope,291 effectiveScope;292 beforeEach(function () {293 effectiveScope = sinon.createStubInstance(Scope);294 callCreateLoadScope = function () {295 return factory.createLoadScope(effectiveScope, '/path/to/my/caller.php', 'eval');296 };297 });298 it('should return an instance of LoadScope', function () {299 expect(callCreateLoadScope()).to.be.an.instanceOf(LoadScope);300 });301 it('should pass the ValueFactory to the scope', function () {302 callCreateLoadScope();303 expect(LoadScope).to.have.been.calledOnce;304 expect(LoadScope).to.have.been.calledWith(305 sinon.match.same(valueFactory)306 );307 });308 it('should pass the effective scope to the scope', function () {309 callCreateLoadScope();310 expect(LoadScope).to.have.been.calledOnce;311 expect(LoadScope).to.have.been.calledWith(312 sinon.match.any,313 sinon.match.same(effectiveScope)314 );315 });316 it('should pass the caller file path to the scope', function () {317 callCreateLoadScope();318 expect(LoadScope).to.have.been.calledOnce;319 expect(LoadScope).to.have.been.calledWith(320 sinon.match.any,321 sinon.match.any,322 '/path/to/my/caller.php'323 );324 });325 it('should pass the type to the scope', function () {326 callCreateLoadScope();327 expect(LoadScope).to.have.been.calledOnce;328 expect(LoadScope).to.have.been.calledWith(329 sinon.match.any,330 sinon.match.any,331 sinon.match.any,332 'eval'333 );334 });335 });336 describe('createModuleScope()', function () {337 var callCreateModuleScope,338 environment,339 module,340 namespace,341 topLevelNamespaceScope;342 beforeEach(function () {343 environment = sinon.createStubInstance(Environment);344 module = sinon.createStubInstance(Module);345 namespace = sinon.createStubInstance(Namespace);346 topLevelNamespaceScope = sinon.createStubInstance(NamespaceScope);347 callCreateModuleScope = function () {348 return factory.createModuleScope(module, topLevelNamespaceScope, environment);349 };350 });351 it('should return an instance of ModuleScope', function () {352 expect(callCreateModuleScope()).to.be.an.instanceOf(ModuleScope);353 });354 it('should pass the ValueFactory to the scope', function () {355 callCreateModuleScope();356 expect(ModuleScope).to.have.been.calledOnce;357 expect(ModuleScope).to.have.been.calledWith(358 sinon.match.same(valueFactory)359 );360 });361 it('should pass the ScopeFactory to the scope', function () {362 callCreateModuleScope();363 expect(ModuleScope).to.have.been.calledOnce;364 expect(ModuleScope).to.have.been.calledWith(365 sinon.match.any,366 sinon.match.same(factory)367 );368 });369 it('should pass the global namespace to the scope', function () {370 callCreateModuleScope();371 expect(ModuleScope).to.have.been.calledOnce;372 expect(ModuleScope).to.have.been.calledWith(373 sinon.match.any,374 sinon.match.any,375 sinon.match.same(globalNamespace)376 );377 });378 it('should pass the module to the scope', function () {379 callCreateModuleScope();380 expect(ModuleScope).to.have.been.calledOnce;381 expect(ModuleScope).to.have.been.calledWith(382 sinon.match.any,383 sinon.match.any,384 sinon.match.any,385 sinon.match.same(module)386 );387 });388 it('should pass the top-level NamespaceScope to the scope', function () {389 callCreateModuleScope();390 expect(ModuleScope).to.have.been.calledOnce;391 expect(ModuleScope).to.have.been.calledWith(392 sinon.match.any,393 sinon.match.any,394 sinon.match.any,395 sinon.match.any,396 sinon.match.same(topLevelNamespaceScope)397 );398 });399 it('should pass the Environment to the scope', function () {400 callCreateModuleScope();401 expect(ModuleScope).to.have.been.calledOnce;402 expect(ModuleScope).to.have.been.calledWith(403 sinon.match.any,404 sinon.match.any,405 sinon.match.any,406 sinon.match.any,407 sinon.match.any,408 sinon.match.same(environment)409 );410 });411 });412 describe('createNamespaceScope()', function () {413 var callCreateNamespaceScope,414 module,415 namespace;416 beforeEach(function () {417 module = sinon.createStubInstance(Module);418 namespace = sinon.createStubInstance(Namespace);419 callCreateNamespaceScope = function () {420 return factory.createNamespaceScope(namespace, module);421 };422 });423 it('should return an instance of NamespaceScope', function () {424 expect(callCreateNamespaceScope()).to.be.an.instanceOf(NamespaceScope);425 });426 it('should pass the ScopeFactory to the scope', function () {427 callCreateNamespaceScope();428 expect(NamespaceScope).to.have.been.calledOnce;429 expect(NamespaceScope).to.have.been.calledWith(430 sinon.match.same(factory)431 );432 });433 it('should pass the global namespace to the scope', function () {434 callCreateNamespaceScope();435 expect(NamespaceScope).to.have.been.calledOnce;436 expect(NamespaceScope).to.have.been.calledWith(437 sinon.match.any,438 sinon.match.same(globalNamespace)439 );440 });441 it('should pass the ValueFactory to the scope', function () {442 callCreateNamespaceScope();443 expect(NamespaceScope).to.have.been.calledOnce;444 expect(NamespaceScope).to.have.been.calledWith(445 sinon.match.any,446 sinon.match.any,447 sinon.match.same(valueFactory)448 );449 });450 it('should pass the CallStack to the scope', function () {451 callCreateNamespaceScope();452 expect(NamespaceScope).to.have.been.calledOnce;453 expect(NamespaceScope).to.have.been.calledWith(454 sinon.match.any,455 sinon.match.any,456 sinon.match.any,457 sinon.match.same(callStack)458 );459 });460 it('should pass the module to the scope', function () {461 callCreateNamespaceScope();462 expect(NamespaceScope).to.have.been.calledOnce;463 expect(NamespaceScope).to.have.been.calledWith(464 sinon.match.any,465 sinon.match.any,466 sinon.match.any,467 sinon.match.any,468 sinon.match.same(module)469 );470 });471 it('should pass the namespace to the scope', function () {472 callCreateNamespaceScope();473 expect(NamespaceScope).to.have.been.calledOnce;474 expect(NamespaceScope).to.have.been.calledWith(475 sinon.match.any,476 sinon.match.any,477 sinon.match.any,478 sinon.match.any,479 sinon.match.any,480 sinon.match.same(namespace)481 );482 });483 });...

Full Screen

Full Screen

ClosureFactoryTest.js

Source:ClosureFactoryTest.js Github

copy

Full Screen

1/*2 * PHPCore - PHP environment runtime components3 * Copyright (c) Dan Phillimore (asmblah)4 * https://github.com/uniter/phpcore/5 *6 * Released under the MIT license7 * https://github.com/uniter/phpcore/raw/master/MIT-LICENSE.txt8 */9'use strict';10var expect = require('chai').expect,11 sinon = require('sinon'),12 CallStack = require('../../src/CallStack'),13 Class = require('../../src/Class').sync(),14 ClosureFactory = require('../../src/ClosureFactory').sync(),15 FunctionFactory = require('../../src/FunctionFactory').sync(),16 FunctionSpec = require('../../src/Function/FunctionSpec'),17 NamespaceScope = require('../../src/NamespaceScope').sync(),18 ObjectValue = require('../../src/Value/Object').sync(),19 Scope = require('../../src/Scope').sync(),20 ValueFactory = require('../../src/ValueFactory').sync();21describe('ClosureFactory', function () {22 var callStack,23 Closure,24 factory,25 functionFactory,26 valueFactory;27 beforeEach(function () {28 callStack = sinon.createStubInstance(CallStack);29 Closure = sinon.stub();30 functionFactory = sinon.createStubInstance(FunctionFactory);31 valueFactory = new ValueFactory();32 factory = new ClosureFactory(functionFactory, valueFactory, callStack, Closure);33 });34 describe('create()', function () {35 var callCreate,36 enclosingScope,37 functionSpec,38 namespaceScope,39 scopeClass,40 thisObject,41 thisObjectClass,42 unwrappedFunction,43 wrappedFunction;44 beforeEach(function () {45 enclosingScope = sinon.createStubInstance(Scope);46 functionSpec = sinon.createStubInstance(FunctionSpec);47 namespaceScope = sinon.createStubInstance(NamespaceScope);48 scopeClass = sinon.createStubInstance(Class);49 thisObject = sinon.createStubInstance(ObjectValue);50 thisObjectClass = sinon.createStubInstance(Class);51 unwrappedFunction = sinon.stub();52 wrappedFunction = sinon.stub();53 functionFactory.create.returns(wrappedFunction);54 thisObject.getClass.returns(thisObjectClass);55 callCreate = function (dontUseScopeClass, dontUseThisObject) {56 return factory.create(57 enclosingScope,58 unwrappedFunction,59 namespaceScope,60 dontUseScopeClass ? null : scopeClass,61 dontUseThisObject ? null : thisObject,62 functionSpec63 );64 }.bind(this);65 });66 it('should pass the NamespaceScope to the FunctionFactory', function () {67 callCreate();68 expect(functionFactory.create).to.have.been.calledOnce;69 expect(functionFactory.create).to.have.been.calledWith(70 sinon.match.same(namespaceScope)71 );72 });73 it('should pass the scope Class to the FunctionFactory when provided', function () {74 callCreate();75 expect(functionFactory.create).to.have.been.calledOnce;76 expect(functionFactory.create).to.have.been.calledWith(77 sinon.match.any,78 sinon.match.same(scopeClass)79 );80 });81 it('should pass the Class of `$this` object to the FunctionFactory when not provided', function () {82 factory.create(83 enclosingScope,84 unwrappedFunction,85 namespaceScope,86 null,87 thisObject88 );89 expect(functionFactory.create).to.have.been.calledOnce;90 expect(functionFactory.create).to.have.been.calledWith(91 sinon.match.any,92 sinon.match.same(thisObjectClass)93 );94 });95 it('should pass null as scope Class to the FunctionFactory when not provided and no `$this`', function () {96 factory.create(97 enclosingScope,98 unwrappedFunction,99 namespaceScope,100 null,101 null102 );103 expect(functionFactory.create).to.have.been.calledOnce;104 expect(functionFactory.create).to.have.been.calledWith(105 sinon.match.any,106 null107 );108 });109 it('should pass null as scope Class to the FunctionFactory when NullValue provided and no `$this`', function () {110 factory.create(111 enclosingScope,112 unwrappedFunction,113 namespaceScope,114 null,115 valueFactory.createNull()116 );117 expect(functionFactory.create).to.have.been.calledOnce;118 expect(functionFactory.create).to.have.been.calledWith(119 sinon.match.any,120 null121 );122 });123 it('should pass the unwrapped function to the FunctionFactory', function () {124 callCreate();125 expect(functionFactory.create).to.have.been.calledOnce;126 expect(functionFactory.create).to.have.been.calledWith(127 sinon.match.any,128 sinon.match.any,129 sinon.match.same(unwrappedFunction)130 );131 });132 it('should pass null as the function name to the FunctionFactory, as closures have no name', function () {133 callCreate();134 expect(functionFactory.create).to.have.been.calledOnce;135 expect(functionFactory.create).to.have.been.calledWith(136 sinon.match.any,137 sinon.match.any,138 sinon.match.any,139 null140 );141 });142 it('should pass null as the $this object to FunctionFactory - will be specified on invocation', function () {143 callCreate();144 expect(functionFactory.create).to.have.been.calledOnce;145 expect(functionFactory.create).to.have.been.calledWith(146 sinon.match.any,147 sinon.match.any,148 sinon.match.any,149 sinon.match.any,150 null151 );152 });153 it('should pass the static class from the call stack to the FunctionFactory, if specified and not Closure', function () {154 var staticClass = sinon.createStubInstance(Class);155 staticClass.is.withArgs('Closure').returns(false);156 callStack.getStaticClass.returns(staticClass);157 callCreate();158 expect(functionFactory.create).to.have.been.calledOnce;159 expect(functionFactory.create).to.have.been.calledWith(160 sinon.match.any,161 sinon.match.any,162 sinon.match.any,163 sinon.match.any,164 sinon.match.any,165 sinon.match.same(staticClass)166 );167 });168 it('should pass the scope class from the call stack to the FunctionFactory, if static class is specified but is Closure', function () {169 var staticClass = sinon.createStubInstance(Class);170 staticClass.is.withArgs('Closure').returns(true);171 callStack.getStaticClass.returns(staticClass);172 callCreate();173 expect(functionFactory.create).to.have.been.calledOnce;174 expect(functionFactory.create).to.have.been.calledWith(175 sinon.match.any,176 sinon.match.any,177 sinon.match.any,178 sinon.match.any,179 sinon.match.any,180 sinon.match.same(scopeClass)181 );182 });183 it('should pass the scope class as the static class to the FunctionFactory, if set', function () {184 callCreate();185 expect(functionFactory.create).to.have.been.calledOnce;186 expect(functionFactory.create).to.have.been.calledWith(187 sinon.match.any,188 sinon.match.any,189 sinon.match.any,190 sinon.match.any,191 sinon.match.any,192 sinon.match.same(scopeClass)193 );194 });195 it('should pass the $this object\'s class as the scope class if none explicitly provided', function () {196 callCreate(true);197 expect(functionFactory.create).to.have.been.calledOnce;198 expect(functionFactory.create).to.have.been.calledWith(199 sinon.match.any,200 sinon.match.any,201 sinon.match.any,202 sinon.match.any,203 sinon.match.any,204 sinon.match.same(thisObjectClass)205 );206 });207 it('should pass null as the static class to the FunctionFactory if there is not one nor a $this', function () {208 callCreate(true, true);209 expect(functionFactory.create).to.have.been.calledOnce;210 expect(functionFactory.create).to.have.been.calledWith(211 sinon.match.any,212 sinon.match.any,213 sinon.match.any,214 sinon.match.any,215 sinon.match.any,216 null217 );218 });219 it('should pass the FunctionSpec to the FunctionFactory', function () {220 callCreate(true, true);221 expect(functionFactory.create).to.have.been.calledOnce;222 expect(functionFactory.create).to.have.been.calledWith(223 sinon.match.any,224 sinon.match.any,225 sinon.match.any,226 sinon.match.any,227 sinon.match.any,228 sinon.match.any,229 sinon.match.same(functionSpec)230 );231 });232 it('should pass the factory to the Closure', function () {233 callCreate();234 expect(Closure).to.have.been.calledOnce;235 expect(Closure).to.have.been.calledWith(236 sinon.match.same(factory)237 );238 });239 it('should pass the ValueFactory to the Closure', function () {240 callCreate();241 expect(Closure).to.have.been.calledOnce;242 expect(Closure).to.have.been.calledWith(243 sinon.match.any,244 sinon.match.same(valueFactory)245 );246 });247 it('should pass the NamespaceScope to the Closure', function () {248 callCreate();249 expect(Closure).to.have.been.calledOnce;250 expect(Closure).to.have.been.calledWith(251 sinon.match.any,252 sinon.match.any,253 sinon.match.same(namespaceScope)254 );255 });256 it('should pass the enclosing Scope to the Closure', function () {257 callCreate();258 expect(Closure).to.have.been.calledOnce;259 expect(Closure).to.have.been.calledWith(260 sinon.match.any,261 sinon.match.any,262 sinon.match.any,263 sinon.match.same(enclosingScope)264 );265 });266 it('should pass the unwrapped function to the Closure', function () {267 callCreate();268 expect(Closure).to.have.been.calledOnce;269 expect(Closure).to.have.been.calledWith(270 sinon.match.any,271 sinon.match.any,272 sinon.match.any,273 sinon.match.any,274 sinon.match.same(unwrappedFunction)275 );276 });277 it('should pass the created wrapped function to the Closure', function () {278 callCreate();279 expect(Closure).to.have.been.calledOnce;280 expect(Closure).to.have.been.calledWith(281 sinon.match.any,282 sinon.match.any,283 sinon.match.any,284 sinon.match.any,285 sinon.match.any,286 sinon.match.same(wrappedFunction)287 );288 });289 it('should pass the `$this` object to the Closure', function () {290 callCreate();291 expect(Closure).to.have.been.calledOnce;292 expect(Closure).to.have.been.calledWith(293 sinon.match.any,294 sinon.match.any,295 sinon.match.any,296 sinon.match.any,297 sinon.match.any,298 sinon.match.any,299 sinon.match.same(thisObject)300 );301 });302 it('should pass the FunctionSpec to the Closure', function () {303 callCreate();304 expect(Closure).to.have.been.calledOnce;305 expect(Closure).to.have.been.calledWith(306 sinon.match.any,307 sinon.match.any,308 sinon.match.any,309 sinon.match.any,310 sinon.match.any,311 sinon.match.any,312 sinon.match.any,313 sinon.match.same(functionSpec)314 );315 });316 it('should return the created Closure', function () {317 var closure = sinon.createStubInstance(Closure);318 Closure.returns(closure);319 expect(callCreate()).to.equal(closure);320 });321 });...

Full Screen

Full Screen

NamespaceFactoryTest.js

Source:NamespaceFactoryTest.js Github

copy

Full Screen

1/*2 * PHPCore - PHP environment runtime components3 * Copyright (c) Dan Phillimore (asmblah)4 * https://github.com/uniter/phpcore/5 *6 * Released under the MIT license7 * https://github.com/uniter/phpcore/raw/master/MIT-LICENSE.txt8 */9'use strict';10var expect = require('chai').expect,11 sinon = require('sinon'),12 CallStack = require('../../src/CallStack'),13 ClassAutoloader = require('../../src/ClassAutoloader').sync(),14 ClassDefiner = require('../../src/Class/ClassDefiner'),15 FunctionFactory = require('../../src/FunctionFactory').sync(),16 FunctionSpecFactory = require('../../src/Function/FunctionSpecFactory'),17 FutureFactory = require('../../src/Control/FutureFactory'),18 NamespaceFactory = require('../../src/NamespaceFactory'),19 ValueFactory = require('../../src/ValueFactory').sync();20describe('NamespaceFactory', function () {21 var callStack,22 classAutoloader,23 classDefiner,24 factory,25 functionFactory,26 functionSpecFactory,27 futureFactory,28 Namespace,29 valueFactory;30 beforeEach(function () {31 callStack = sinon.createStubInstance(CallStack);32 classAutoloader = sinon.createStubInstance(ClassAutoloader);33 classDefiner = sinon.createStubInstance(ClassDefiner);34 functionFactory = sinon.createStubInstance(FunctionFactory);35 functionSpecFactory = sinon.createStubInstance(FunctionSpecFactory);36 futureFactory = sinon.createStubInstance(FutureFactory);37 Namespace = sinon.stub();38 valueFactory = sinon.createStubInstance(ValueFactory);39 factory = new NamespaceFactory(40 Namespace,41 callStack,42 futureFactory,43 functionFactory,44 functionSpecFactory,45 valueFactory,46 classAutoloader,47 classDefiner48 );49 });50 describe('create()', function () {51 var callCreate,52 name,53 parentNamespace;54 beforeEach(function () {55 name = 'MyNamespace';56 parentNamespace = sinon.createStubInstance(Namespace);57 callCreate = function () {58 return factory.create(parentNamespace, name);59 };60 });61 it('should return an instance of Namespace', function () {62 expect(callCreate()).to.be.an.instanceOf(Namespace);63 });64 it('should create one namespace', function () {65 callCreate();66 expect(Namespace).to.have.been.calledOnce;67 });68 it('should pass the CallStack to the namespace', function () {69 callCreate();70 expect(Namespace).to.have.been.calledWith(sinon.match.same(callStack));71 });72 it('should pass the FutureFactory to the namespace', function () {73 callCreate();74 expect(Namespace).to.have.been.calledWith(75 sinon.match.any,76 sinon.match.same(futureFactory)77 );78 });79 it('should pass the ValueFactory to the namespace', function () {80 callCreate();81 expect(Namespace).to.have.been.calledWith(82 sinon.match.any,83 sinon.match.any,84 sinon.match.same(valueFactory)85 );86 });87 it('should pass the NamespaceFactory to the namespace', function () {88 callCreate();89 expect(Namespace).to.have.been.calledWith(90 sinon.match.any,91 sinon.match.any,92 sinon.match.any,93 sinon.match.same(factory)94 );95 });96 it('should pass the FunctionFactory to the namespace', function () {97 callCreate();98 expect(Namespace).to.have.been.calledWith(99 sinon.match.any,100 sinon.match.any,101 sinon.match.any,102 sinon.match.any,103 sinon.match.same(functionFactory)104 );105 });106 it('should pass the FunctionSpecFactory to the namespace', function () {107 callCreate();108 expect(Namespace).to.have.been.calledWith(109 sinon.match.any,110 sinon.match.any,111 sinon.match.any,112 sinon.match.any,113 sinon.match.any,114 sinon.match.same(functionSpecFactory)115 );116 });117 it('should pass the ClassAutoloader to the namespace', function () {118 callCreate();119 expect(Namespace).to.have.been.calledWith(120 sinon.match.any,121 sinon.match.any,122 sinon.match.any,123 sinon.match.any,124 sinon.match.any,125 sinon.match.any,126 sinon.match.same(classAutoloader)127 );128 });129 it('should pass the ClassDefiner to the namespace', function () {130 callCreate();131 expect(Namespace).to.have.been.calledWith(132 sinon.match.any,133 sinon.match.any,134 sinon.match.any,135 sinon.match.any,136 sinon.match.any,137 sinon.match.any,138 sinon.match.any,139 sinon.match.same(classDefiner)140 );141 });142 it('should pass the parent namespace to the namespace when specified', function () {143 callCreate();144 expect(Namespace).to.have.been.calledWith(145 sinon.match.any,146 sinon.match.any,147 sinon.match.any,148 sinon.match.any,149 sinon.match.any,150 sinon.match.any,151 sinon.match.any,152 sinon.match.any,153 sinon.match.same(parentNamespace)154 );155 });156 it('should pass null as the parent namespace when not specified', function () {157 parentNamespace = null;158 callCreate();159 expect(Namespace).to.have.been.calledWith(160 sinon.match.any,161 sinon.match.any,162 sinon.match.any,163 sinon.match.any,164 sinon.match.any,165 sinon.match.any,166 sinon.match.any,167 sinon.match.any,168 null169 );170 });171 it('should pass the name to the namespace when specified', function () {172 callCreate();173 expect(Namespace).to.have.been.calledWith(174 sinon.match.any,175 sinon.match.any,176 sinon.match.any,177 sinon.match.any,178 sinon.match.any,179 sinon.match.any,180 sinon.match.any,181 sinon.match.any,182 sinon.match.any,183 'MyNamespace'184 );185 });186 it('should pass the empty string as the name when not specified', function () {187 name = '';188 callCreate();189 expect(Namespace).to.have.been.calledWith(190 sinon.match.any,191 sinon.match.any,192 sinon.match.any,193 sinon.match.any,194 sinon.match.any,195 sinon.match.any,196 sinon.match.any,197 sinon.match.any,198 sinon.match.any,199 ''200 );201 });202 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const sinon = require('sinon');3const myObj = {4 method: (arg1, arg2) => {5 return arg1 + arg2;6 }7};8describe('myObj', () => {9 describe('#method', () => {10 it('should return the sum of its arguments', () => {11 const spy = sinon.spy(myObj, 'method');12 myObj.method(2, 3);13 myObj.method(2, 4);14 assert(spy.calledTwice);15 assert(spy.calledWith(sinon.match.number, 3));16 assert(spy.calledWith(2, sinon.match.number));17 });18 });19});

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const sinon = require('sinon');3const myObj = {4 myMethod: function (arg1, arg2) {5 console.log(arg1, arg2);6 }7};8sinon.spy(myObj, 'myMethod');9myObj.myMethod(1, 2);10assert(myObj.myMethod.calledWith(sinon.match.number));11assert(myObj.myMethod.calledWith(sinon.match.has('foo', 'bar')));12assert(myObj.myMethod.calledWith(sinon.match(function (value) {13 return value > 10;14})));15assert(myObj.myMethod.calledWith(sinon.match.has('foo', sinon.match(function (value) {16 return value > 10;17}))));18const assert = require('assert');19const sinon = require('sinon');20const myObj = {21 myMethod: function (arg1, arg2) {22 console.log(arg1, arg2);23 }24};25sinon.spy(myObj, 'myMethod');26myObj.myMethod(1, 2);27assert(myObj.myMethod.calledWith(sinon.match.any));28const assert = require('assert');29const sinon = require('sinon');30const myObj = {31 myMethod: function (arg1, arg2) {32 console.log(arg1, arg2);33 }34};35sinon.spy(myObj, 'myMethod');36myObj.myMethod(1, 2);37assert(myObj.myMethod.calledWith(sinon.match.defined));38const assert = require('assert');39const sinon = require('sinon');40const myObj = {41 myMethod: function (arg1, arg2) {42 console.log(arg1, arg2);43 }44};45sinon.spy(myObj, 'myMethod');46myObj.myMethod(1, 2);47assert(myObj.myMethod.calledWith(sinon.match.truthy));48const assert = require('assert');49const sinon = require('sinon');50const myObj = {51 myMethod: function (arg1, arg2) {52 console.log(arg1, arg2);53 }54};

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myMethod: function (arg1, arg2, callback) {5 callback(arg1 + arg2);6 }7};8var callback = sinon.spy();9myObj.myMethod(1, 2, callback);10assert(callback.calledWith(3));11assert(callback.calledWith(sinon.match.number));12assert(callback.calledWith(sinon.match(function (value) {13 return value > 2;14})));15assert(callback.calledWith(sinon.match.has('foo', 'bar')));16assert(callback.calledWith(sinon.match.has('foo', sinon.match.typeOf('string'))));17assert(callback.calledWith(sinon.match.has('foo', sinon.match(function (value) {18 return value > 2;19}))));20assert(callback.calledWith(sinon.match.hasOwn('foo')));21assert(callback.calledWith(sinon.match.hasOwn('foo', 'bar')));22assert(callback.calledWith(sinon.match.hasOwn('foo', sinon.match.typeOf('string'))));23assert(callback.calledWith(sinon.match.hasOwn('foo', sinon.match(function (value) {24 return value > 2;25}))));26var sinon = require('sinon');27var assert = require('assert');28var myObj = {29 myMethod: function (arg1, arg2, callback) {30 callback(arg1 + arg2);31 }32};33var callback = sinon.spy();34myObj.myMethod(1, 2, callback);35assert(callback.calledWith(sinon.match.defined));36assert(!callback.calledWith(sinon.match.defined, undefined));37var sinon = require('sinon');38var assert = require('assert');39var myObj = {40 myMethod: function (arg1, arg2, callback) {41 callback(arg1 + arg2);42 }43};44var callback = sinon.spy();45myObj.myMethod(1, 2, callback);46assert(callback.calledWith(sinon.match.truthy));47assert(!callback.calledWith(sinon.match.truthy, false));48var sinon = require('sinon');49var assert = require('assert');50var myObj = {51 myMethod: function (arg1, arg2, callback) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var callback = sinon.spy();3var proxyquire = require('proxyquire');4var stub = sinon.stub().returns(callback);5var foo = proxyquire('./foo', {6});7foo(1, 2);8console.log(callback.calledWith(sinon.match.number));9console.log(callback.calledWith(sinon.match.string));10console.log(callback.calledWith(sinon.match({a: 1})));11console.log(callback.calledWith(sinon.match({a: 1, b: 2})));12console.log(callback.calledWith(sinon.match(function(value) {13 return value > 5;14})));15console.log(callback.calledWith(sinon.match(function(value) {16 return value > 10;17})));18console.log(callback.calledWith(sinon.match.instanceOf(Date)));19console.log(callback.calledWith(sinon.match.instanceOf(Object)));20console.log(callback.calledWith(sinon.match.has('a', 1)));21console.log(callback.calledWith(sinon.match.has('b', 2)));22console.log(callback.calledWith(sinon.match.has('a')));23console.log(callback.calledWith(sinon.match.has('b')));24console.log(callback.calledWith(sinon.match.hasOwn('a', 1)));25console.log(callback.calledWith(sinon.match.hasOwn('b', 2)));26console.log(callback.calledWith(sinon.match.hasOwn('a')));27console.log(callback.calledWith(sinon.match.hasOwn('b')));28console.log(callback.calledWith(sinon.match.typeOf('number')));29console.log(callback.calledWith(sinon.match.typeOf('string')));30console.log(callback.calledWith(sinon.match.same({a: 1})));31console.log(callback.calledWith(sinon.match.same({a: 1, b: 2})));32console.log(callback.calledWith(sinon.match.same({a: 1, b: 2, c: 3})));33console.log(callback.calledWith(sinon.match.same({a: 1, b: 2, c: 3, d: 4})));34console.log(callback.calledWith(sinon.match.defined));35console.log(callback.calledWith(sinon.match.truthy

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var sinon = require('sinon');3var obj = {4 method: function (arg) {5 return arg;6 }7};8var spy = sinon.spy(obj, "method");9obj.method(42);10assert(spy.calledWith(sinon.match.number));11assert(!spy.calledWith(sinon.match.string));

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var match = sinon.match;3var obj = {4 method: function (arg) {5 }6};7sinon.spy(obj, "method");8obj.method(42);9obj.method("Hello World");10obj.method(true);

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2var sinon = require('sinon');3var sinonTest = require('sinon-test')(sinon);4describe('sinon match method', function() {5 it('should return true if match is called with correct argument', sinonTest(function() {6 var callback = sinon.stub();7 callback('hello');8 expect(callback.calledWith(sinon.match('hello'))).to.be.true;9 }));10});11var expect = require('chai').expect;12var sinon = require('sinon');13var sinonTest = require('sinon-test')(sinon);14describe('sinon match method', function() {15 it('should return true if match is called with correct argument', sinonTest(function() {16 var callback = sinon.stub();17 callback('hello');18 expect(callback.calledWith(sinon.match('hello'))).to.be.true;19 }));20});21var expect = require('chai').expect;22var sinon = require('sinon');23var sinonTest = require('sinon-test')(sinon);24describe('sinon match method', function() {25 it('should return true if match is called with correct argument', sinonTest(function() {26 var callback = sinon.stub();27 callback('hello');28 expect(callback.calledWith(sinon.match('hello'))).to.be.true;29 }));30});31var expect = require('chai').expect;32var sinon = require('sinon');33var sinonTest = require('sinon-test')(sinon);34describe('sinon match method', function() {35 it('should return true if match is called with correct argument', sinonTest(function() {36 var callback = sinon.stub();37 callback('hello');38 expect(callback.calledWith(sinon.match('hello'))).to.be.true;39 }));40});41var expect = require('chai').expect;42var sinon = require('sinon');43var sinonTest = require('sinon-test')(sinon);44describe('sinon match method', function() {45 it('should return true if match is called with correct argument', sinonTest(function() {46 var callback = sinon.stub();47 callback('hello');48 expect(callback.called

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObject = {4 foo: function (bar, baz) {5 return bar + baz;6 }7};8var stub = sinon.stub(myObject, 'foo');9myObject.foo(1, 2);10assert(stub.calledWith(sinon.match.number, sinon.match.string));11assert(stub.calledWith(sinon.match.number, sinon.match.string));12assert(stub.calledWith(sinon.match.number, sinon.match.string));13assert(stub.calledWith(sinon.match.number, sinon.match.string));14assert(stub.calledWith(sinon.match.number, sinon.match.string));15assert(stub.calledWith(sinon.match.number, sinon.match.string));16assert(stub.calledWith(sinon.match.number, sinon.match.string));17assert(stub.calledWith(sinon.match.number, sinon.match.string));18assert(stub.calledWith(sinon.match.number, sinon.match.string));19assert(stub.calledWith(sinon.match.number, sinon.match.string));20stub.restore();21var myObject = {22 foo: function (bar, baz) {23 return bar + baz;24 }25};26var stub = sinon.stub(myObject, 'foo');27myObject.foo(1, 2);28assert(stub.calledWith(sinon.match.number, sinon.match.string));29stub.restore();

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('sinon', function () {2 it('should match', function () {3 var spy = sinon.spy();4 spy('hello', 2);5 assert(spy.calledWith(sinon.match.string));6 });7});8describe('sinon', function () {9 it('should match', function () {10 var spy = sinon.spy();11 spy('hello', 2);12 assert(spy.calledWith(sinon.match.string));13 });14});15describe('sinon', function () {16 it('should match', function () {17 var spy = sinon.spy();18 spy('hello', 2);19 assert(spy.calledWith(sinon.match.string));20 });21});22describe('sinon', function () {23 it('should match', function () {24 var spy = sinon.spy();25 spy('hello', 2);26 assert(spy.calledWith(sinon.match.string));27 });28});29describe('sinon', function () {30 it('should match', function () {31 var spy = sinon.spy();32 spy('hello', 2);33 assert(spy.calledWith(sinon.match.string));34 });35});36describe('sinon', function () {37 it('should match', function () {38 var spy = sinon.spy();39 spy('hello', 2);40 assert(spy.calledWith(sinon.match.string));41 });42});43describe('sinon', function () {44 it('should match', function () {45 var spy = sinon.spy();46 spy('hello', 2);47 assert(spy.calledWith(sinon.match.string));48 });49});50describe('sinon', function () {51 it('should match', function () {52 var spy = sinon.spy();53 spy('hello', 2);54 assert(spy.calledWith(sinon.match.string));55 });56});57describe('sinon', function () {58 it('should match', function () {59 var spy = sinon.spy();60 spy('hello', 2);61 assert(spy.calledWith(sinon.match.string));62 });63});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var test = function (obj) {4 console.log(obj);5}6var arg = sinon.match.typeOf('object');7test(arg);8assert(arg.test({}));9assert(!arg.test('string'));

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 sinon 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