unit-testing

Testing anonymous function equality with Jest

故事扮演 提交于 2021-02-04 11:49:39
问题 Is there a way to test anonymous function equality with jest@20 ? I am trying to pass a test similar to: const foo = i => j => {return i*j} const bar = () => {baz:foo(2), boz:1} describe('Test anonymous function equality',()=>{ it('+++ foo', () => { const obj = foo(2) expect(obj).toBe(foo(2)) }); it('+++ bar', () => { const obj = bar() expect(obj).toEqual({baz:foo(2), boz:1}) }); }); which currently yields: ● >>>Test anonymous function equality › +++ foo expect(received).toBe(expected)

How to test JavaScript minification output

我的未来我决定 提交于 2021-02-04 11:19:51
问题 We recently upgraded to a newer build of a JavaScript minification library. After a significant amount of quality assurance work by the testing team, it was discovered that the new version of our minifier had an issue that changed the intention and meaning behind a block of code. (Life lesson: don't upgrade JS minifiers unless you are really convinced you need the new version.) The minifier is used for client side JavaScript code with a heavy emphasis on DOM related activity, not nearly as

assertAlmostEqual in Python unit-test for collections of floats

纵然是瞬间 提交于 2021-02-04 09:31:05
问题 The assertAlmostEqual(x, y) method in Python's unit testing framework tests whether x and y are approximately equal assuming they are floats. The problem with assertAlmostEqual() is that it only works on floats. I'm looking for a method like assertAlmostEqual() which works on lists of floats, sets of floats, dictionaries of floats, tuples of floats, lists of tuples of floats, sets of lists of floats, etc. For instance, let x = 0.1234567890 , y = 0.1234567891 . x and y are almost equal because

Moq - What happens when using It.IsAny in a setup's return?

ⅰ亾dé卋堺 提交于 2021-02-04 07:29:45
问题 I am performing unit tests in C# using Moq. One test in particular I have created an interface wrapper over System.Net.Mail.SmtpClient so that it can be mocked. public class SmtpClient : ISmtpClient { public string Host { get; set; } public int Port { get; set; } public ICredentialsByHost Credentials { get; set; } public bool EnableSsl { get; set; } public void Send(MailMessage mail) { var smtpClient = new System.Net.Mail.SmtpClient { Host = Host, Port = Port, Credentials = Credentials,

How to unit test a web scraping service php unit

こ雲淡風輕ζ 提交于 2021-01-29 22:56:28
问题 I am currently developing a project in PHP + Laravel that needs to scrape data from two different websites. I am using the Goutte Scraping Library. I have 10 integration tests, where I use the Crawler object that Goutte's Client provide in order to get the specific data I want to scrape from each website. The tests work just fine (I even used infection library for mutant testing)... But the thing is that I thik there could be a way to unit test all the functions (therefore, the tests would

How to unit test a web scraping service php unit

廉价感情. 提交于 2021-01-29 22:35:01
问题 I am currently developing a project in PHP + Laravel that needs to scrape data from two different websites. I am using the Goutte Scraping Library. I have 10 integration tests, where I use the Crawler object that Goutte's Client provide in order to get the specific data I want to scrape from each website. The tests work just fine (I even used infection library for mutant testing)... But the thing is that I thik there could be a way to unit test all the functions (therefore, the tests would

How to mock module in different ways in different tests in the same test file in Jest?

我怕爱的太早我们不能终老 提交于 2021-01-29 22:19:13
问题 Currently I have this: jest.mock('my/hook', () => () => false) I want my custom React hook module to return false in every test by default, but in a few tests I want it to return true. The hook is implemented essentially like this: function useMyHook(key) { switch (key) { case 'foo': case 'bar': return true default: return false } } I am using the hook several times in my component, once for the foo key and once for the bar key. I want it to return false for both keys by default. But for a

How to mock module in different ways in different tests in the same test file in Jest?

喜你入骨 提交于 2021-01-29 21:56:41
问题 Currently I have this: jest.mock('my/hook', () => () => false) I want my custom React hook module to return false in every test by default, but in a few tests I want it to return true. The hook is implemented essentially like this: function useMyHook(key) { switch (key) { case 'foo': case 'bar': return true default: return false } } I am using the hook several times in my component, once for the foo key and once for the bar key. I want it to return false for both keys by default. But for a

Cast exception when mocking kotlin lambda callbacks in Mockk

青春壹個敷衍的年華 提交于 2021-01-29 18:54:26
问题 I am having some trouble mocking callback functions with Mockk. I am trying to mock a task success listener that is called like this: collection .add(Item()) .addOnSuccessListener { update(collection.document(it.id)) } Where the java signature for the callback would look like this: public interface OnSuccessListener<T> { void onSuccess(T var1); } and the signature for addOnSuccessListener looks like this public abstract Task<DocumentReference> addOnSuccessListener(@NonNull OnSuccessListener

EasyMock - override an object creation

喜夏-厌秋 提交于 2021-01-29 18:06:19
问题 How can I override an object creation inside a method? public class ClassToTest { public Object testMethod() { ... code ... Object result; try { result = new ClassToMock(someParam).execute(); } catch (Exception e) { // handle error } return result; } } How can my test override the "execute" method of ClassToMock? I will be happy for code examples with EasyMock. I want to test "testMethod", something like: @Test public void testMethodTest(){ ClassToTest tested = new ClassToTest(); // Mock