unit-testing

How to test async function with spyOn?

半腔热情 提交于 2021-02-19 02:57:09
问题 I am trying to test an async function in a react native app. class myClass extends React.Component { ... closeModal = async () => { if (someCondition) { await myFunction1(); } else { await myFunction2(); } this.props.navigation.state.params.onGoBack(); this.props.navigation.navigate('Main'); }; ... } This is my test: const navigation = { navigate: jest.fn(), state: { params: { onGoBack: jest.fn() } }, }; const renderComponent = overrides => { props = { navigation, ...overrides, }; return

How to test async function with spyOn?

别来无恙 提交于 2021-02-19 02:57:09
问题 I am trying to test an async function in a react native app. class myClass extends React.Component { ... closeModal = async () => { if (someCondition) { await myFunction1(); } else { await myFunction2(); } this.props.navigation.state.params.onGoBack(); this.props.navigation.navigate('Main'); }; ... } This is my test: const navigation = { navigate: jest.fn(), state: { params: { onGoBack: jest.fn() } }, }; const renderComponent = overrides => { props = { navigation, ...overrides, }; return

Spring: unit test for class that has both field & constructor injection

好久不见. 提交于 2021-02-19 02:46:05
问题 I have below setup of classes. class Base { @Autowired private BaseService service; //No getters & setters .... } @Component class Child extends Base { private final SomeOtherService otherService; @Autowired Child(SomeOtherService otherService) { this.otherService = otherService; } } I am writing a unit test for the Child class. If I use @InjectMocks then the otherService comes out to be null. If I use, the constructor of Child class in the setup of the test, then the fields in Base class

Laravel PHPUnit mock Request

泄露秘密 提交于 2021-02-19 02:04:12
问题 I'm doing a PHPUnit on my controller and I can't seem to mock the Request right. Here's the Controller: use Illuminate\Http\Request; public function insert(Request $request) { // ... some codes here if ($request->has('username')) { $userEmail = $request->get('username'); } else if ($request->has('email')) { $userEmail = $request->get('email'); } // ... some codes here } Then on the unit test, public function testIndex() { // ... some codes here $requestParams = [ 'username' => 'test', 'email'

Are there Parameterized Test Fixtures for xunit?

风格不统一 提交于 2021-02-18 22:15:45
问题 Does xunit.net support "Parameterized Test Fixtures" like nunit (see example code below). Note I'm not looking for IUseFixture<T> or [Theory] because these do not provide the same functionality as Parameterized Test Fixtures [TestFixture("hello", "hello", "goodbye")] [TestFixture("zip", "zip")] [TestFixture(42, 42, 99)] public class ParameterizedTestFixture { private string eq1; private string eq2; private string neq; public ParameterizedTestFixture(string eq1, string eq2, string neq) { this

Testing WeakReference

帅比萌擦擦* 提交于 2021-02-18 21:29:32
问题 What is the proper approach to testing a weak reference in Java? My initial idea is to do the following: public class WeakReferenceTest { public class Target{ private String value; public Target(String value){ this.value = value; } public String toString(){ return value; } } public class UsesWeakReference{ WeakReference<Target> reference; public UsesWeakReference(Target test){ reference = new WeakReference<Target>(test); } public String call(){ Target test = reference.get(); if(test != null){

Testing WeakReference

隐身守侯 提交于 2021-02-18 21:29:06
问题 What is the proper approach to testing a weak reference in Java? My initial idea is to do the following: public class WeakReferenceTest { public class Target{ private String value; public Target(String value){ this.value = value; } public String toString(){ return value; } } public class UsesWeakReference{ WeakReference<Target> reference; public UsesWeakReference(Target test){ reference = new WeakReference<Target>(test); } public String call(){ Target test = reference.get(); if(test != null){

No value accessor for form control with name… for mat-select controls

坚强是说给别人听的谎言 提交于 2021-02-18 20:09:24
问题 I am making some unit test with jasmine and karma for an angular 6 app that validate if a formGroup field is valid. I am experiencing problems with mat-select control. when I run the test case, Karma fires me an error saying Error: No value accessor for form control with name: 'importId' . By the way, the component works fine as I expected. This is my component: import {Component, Inject, OnInit} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material"; import

Android Studio Robotium Recorder Plugin Compatibility issue

好久不见. 提交于 2021-02-18 18:53:35
问题 I have Android API Levels 15,19,20,21 and Android Studio 1.0.1. Robotium Recorder needs API 15 or higher version. Information about Robotium API support I follow that guide from Robotium's page and also I tried many things like those (all following steps were tested separately from each other); I created emulators that's API level 15 and 19, Than I tried to start Robotium,It did not work. I connected my Android phone which is API level 19,that did not work again. I started Android Studio with

Jest error when set or assign window.location

扶醉桌前 提交于 2021-02-18 12:38:08
问题 Upgraded Jest library on v25 and all unit tests that were checking location change are failing. I checked a couple of issues opened on jest repo but I didn't actually understood how can this be fixed. The code that calls location.assign breaks with following error: Error: Not implemented: navigation (except hash changes) 69 | // window.location.href = url; > 70 | window.location.assign(url); I suppose that Jest jsdom window object shouldn't be treated anymore like a real browser window in