mock

How can I mock an ES6 module import using Jest?

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm beginning to think this isn't possible, but I want to ask anyway. I want to test that one of my ES6 modules calls another ES6 module in a particular way. With Jasmine this is super easy -- The app code: // myModule.js import dependency from './dependency'; export default (x) => { dependency.doSomething(x * 2); } And the test code: //myModule-test.js import myModule from '../myModule'; import dependency from '../dependency'; describe('myModule', () => { it('calls the dependency with double the input', () => { spyOn(dependency,

Swagger mock server

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an API reference in Swagger file. I want to create a very simple mock server, so that when I call eg.: mymockurl.com/users it will return a predefined json (no need to connect to a database). What's the easiest way to do this? I'm not a backend guy. 回答1: SwaggerHub provides a mock server for OpenAPI 2.0 and 3.0 specs. Mocking is supported on both free and paid plans. To use the mock server, import your spec into SwaggerHub and enable "API Auto Mocking". Mock responses can be JSON, YAML and XML, and are generated based on

Rhino Mock Entity Framework using UnitofWork Pattern not working

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is my first attempt at something like this, so hopefully this is simple. I have created a WCF service which uses Entity Framework to access the database. I have implemented a UnitOfWork interface so my service can use EF while still being testable. Here is my service: public class ProjectService : IProjectService { private IUnitOfWork db = null; public ProjectService(IUnitOfWork unitofwork) { db = unitofwork; } public int RegisterSite(int CPUID) { if (db.Servers.Count(x => x.CPUID == CPUID) > 0) { // do something } return 0; } } Here is

How to mock a boto3 client object/call

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to mock one particular boto3 function. My module, Cleanup, imports boto3. Cleanup also has a class, "cleaner". During init, cleaner creates an ec2 client: self.ec2_client = boto3.client('ec2') I want to mock the ec2 client method: desribe_tags(), which python says is: <bound method EC2.describe_tags of <botocore.client.EC2 object at 0x7fd98660add0>> the furthest I've gotten is importing botocore in my test file and trying: mock.patch(Cleaner.botocore.client.EC2.describe_tags) which fails with: AttributeError: 'module' object has

How to mock DriverManager.getConnection(…)?

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a class, which connects to an H2 database and runs several SQL statements. public class H2Persistence implements IPersistence { private Connection conn; @Override public void open() { try { Class.forName("org.h2.Driver"); conn = DriverManager.getConnection(CONN_TYPE_USER_HOME); final Statement stmt = conn.createStatement(); stmt.executeUpdate("CREATE TABLE PERSON(" + "ID BIGINT,"+ "AGEGROUP VARCHAR(255),"+ "MONTHLY_INCOME_LEVEL VARCHAR(255)," + "GENDER VARCHAR(1),"+ "HOUSEHOLD_ID BIGINT)"); } catch (ClassNotFoundException e) { e

Mock final class in Spock

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can spock mock final classes? If so, how? Search results brought up this gist , which would seem to imply so, but I can't find any examples of doing so. I've also found forum posts that say mocking final classes isn't supported. 回答1: This specification: @Grab('org.spockframework:spock-core:1.0-groovy-2.4') @Grab('cglib:cglib-nodep:3.1') import spock.lang.* class Test extends Specification { def 'lol'() { given: def s = Mock(String) { size() >> 10 } expect: s.size() == 10 } } ends with the following exception: JUnit 4 Runner, Tests: 1,

How to mock aws-sdk gem?

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some code that uploads a file to Amazon S3, using the aws-sdk gem. Apparently it does an HTTP put to upload the file. Is there a good way to mock this functionality of the aws-sdk gem? I tried using Webmock, but the aws-sdk gem seems to do a get latest/meta-data/iam/security-credentials/ first. It seems that using Webmock may not be the best way to mock this functionality. Working in RSpec. 回答1: There are a lot of ways to mock requests in the AWS SDK for Ruby . Trevor Rowe recently posted an article on using the SDK's native support

Mocking a method to throw an exception (moq), but otherwise act like the mocked object?

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a Transfer class, simplified it looks like this: public class Transfer { public virtual IFileConnection source { get ; set ; } public virtual IFileConnection destination { get ; set ; } public virtual void GetFile ( IFileConnection connection , string remoteFilename , string localFilename ) { connection . Get ( remoteFilename , localFilename ); } public virtual void PutFile ( IFileConnection connection , string localFilename , string remoteFilename ) { connection . Get ( remoteFilename , localFilename ); } public virtual

How do I mock $window injected manually in provider private function?

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following provider: angular.module('MyApp').provider('MyDevice', function () { var ngInjector = angular.injector(['ng']), $window = ngInjector.get('$window'); function isMobileDevice () { return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/) .test($window.navigator.userAgent || $window.navigator.vendor || $window.opera); } this.$get = function () { return { isDesktop: function () { return !isMobileDevice(); }, isMobile: function () { return isMobileDevice(); } }; }; }); And the following test spec: describe(