更新到 Angular 13 后,我的许多单元测试(在 Angular 12 上运行没有问题)现在都失败了。我发现更令人沮丧的是,测试仅在一起运行时才会失败,而当我使用fdescribe
.
我读到,在 Angular 13 中,选项teardown
默认设置为 true,因此我尝试在test.ts
文件中全局选择退出:
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
Run Code Online (Sandbox Code Playgroud)
但这没有用。
我的业力配置:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage'),
require('karma-mocha-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
random: false,
},
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/cockpit'),
reporters: [
{ type: 'html', …
Run Code Online (Sandbox Code Playgroud) 我是Android Architecture Components的新手,并且已经阅读了本教程。我对其中的部分感兴趣:
这样,您就可以拥有一个可以打开同一Activity或Fragment的许多不同实例但具有不同ViewModel信息的应用程序。假设我们扩展了Court-Counter示例,以获取多个篮球比赛的得分。游戏会显示在列表中,然后单击列表中的游戏会打开一个屏幕,该屏幕看起来像我们当前的MainActivity,但我将其称为GameScoreActivity。
假设我有一个ViewModel MyViewModel
。我想创建此视图模型的列表,但是直到运行时我都不知道该列表中的元素数量。在for循环内创建视图模型实例是否方便?我可以创建多少个实例?实例数量会影响性能吗?
我想在我的应用程序中使用屏幕上显示的后退按钮提供正确的导航,而不仅仅是浏览器后退按钮。
现在我在我的应用程序中一般使用 ngrx。我已经检查过他们可能为跟踪路由器提供了什么样的解决方案,当然他们确实提供了一种解决方案,即router-store。
但是,看起来 router-store 只提供有关当前路线的信息,而不提供前一路线的信息。
因此,经过大量搜索后,我找不到任何可能的解决方案,因此我决定实现自己的路由器跟踪状态。它有效,但现在我不能使用routerLink
指令,因为它不会调度我的动作。如果用户直接在 URL 中输入链接,整个状态就会丢失!所以这并不是最好的解决方案。
我可以通过某种方式扩展 router-store 来存储以前的路由数据吗?或者我可以使用我自己的 reducer 来监听路由器存储操作,比如ROUTER_REQUEST
和ROUTER_NAVIGATED
?
我试图在圆圈内绘制一个圆弧来表示温度,但我很难实现这一点.在我的搜索过程中,我发现了这些解
这个我无法理解什么是比例方法,并且正在绘制多个拱门,这让我有点困惑
这篇文章给了它一个固定的大小,我需要在我的XML布局中通过自定义视图控制大小
到目前为止我达到了什么
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int startTop = 0;
int startLeft = 0;
int endBottom = getHeight() / 2;
int endRight = endBottom;// This makes an equal square.
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
int upperEdgeX = (int) (centerX + getWidth() / 2 * Math.cos(270 * Math.PI / 180));
int upperEdgeY = (int) (centerY + getWidth() / 2 * Math.sin(270 * Math.PI / 180));
int bottomEdgeX = …
Run Code Online (Sandbox Code Playgroud) 来自Google的新Geofencing API在应用程序耗尽时不会触发任何事件.我尝试使用PendingIntent.getBroadcast()
,PendingIntent.getService()
但只能在应用程序打开时获得转换事件.
我从代码实验室学习了本教程,但修改了代码以使用新的GeofencingClient
UPDATE
这是我创建待定意图的方式:
private PendingIntent getGeofencePendingIntent() {
if (mGeofencePendingIntent != null) {
Log.d(TAG, "Pending intent is already there");
return mGeofencePendingIntent;
}
Log.d(TAG, "Creating a new pending intent");
// In case I'm using Service, the second parameter will be GeoIntentService.class
Intent mIntent = new Intent(mContext, GeoReceiver.class);
// In case I'm using Service, the method will be getService(...)
mGeofencePendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return mGeofencePendingIntent;
}
Run Code Online (Sandbox Code Playgroud)
我的GeoReceiver onReceive
方法中的代码.在使用Services inside onHandleIntent
方法时,代码类似
@Override …
Run Code Online (Sandbox Code Playgroud) android geofencing android-geofence google-location-services
我是 RxJava 的新手。我的经验主要来自这些教程: here和here。
现在,我发现自己在使用 Retrofit2 进行 API 调用时会返回一个Obesrvable<AccessToken>
. 客户端将调用此服务如下:
public Observable<TokenResult> authenticateWithClientCredentials() {
return authService.authenticate("client_credentials").take(1);
}
Run Code Online (Sandbox Code Playgroud)
Authenticator
调用的类#authenticateWithClientCredentials()
将从客户端调用。
我想要实现的是Observable<Boolean>
从Authenticator
类中返回一个,一旦 API 调用完成,即 insideonComplete()
表示访问令牌已成功获取并保存在Authenticator
类内的缓存中。
我试过defer
接线员,但我还是迷路了。
编辑
我知道我可以在参数中传递一个回调,但是 Rx 的想法不是取代旧的经典回调方法吗?
我有一个元减速器,应该在注销时清除状态。
export function clearState(reducer: ActionReducer<any>): ActionReducer<any> {
return (state, action) => {
if (action.type === AuthActionTypes.UNAUTHENTICATED) {
state = undefined;
}
return reducer(state, action);
};
}
export const metaReducers: MetaReducer<any>[] = [clearState];
Run Code Online (Sandbox Code Playgroud)
我想对这段代码进行单元测试。我之前测试过普通的减速器,但对我来说,在为元减速器编写测试时很难应用相同的技术。并且文档中没有示例。
案例如下:我有两种类型的用户,type1和type2.两者都必须登录才能进入具有导航抽屉的主要活动.导航抽屉中的项目取决于用户的类型.在知道用户类型后,如何在运行时更改导航抽屉的项目.
MainActivity.java
package com.example.motassem.navdrawer;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final String SELECTED_ITEM_ID = "selected_item_id";
private static final String FIRST_TIME = "first_time";
private Toolbar mToolbar;
private NavigationView mDrawer;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private int mSelectedID;
private boolean mUserSawDrawer = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//mMainLayout = …
Run Code Online (Sandbox Code Playgroud) 在 Mithril 中创建新组件vnode.attrs.value
和vnode.state.value
在创建新组件时有什么区别?
android ×6
angular ×3
ngrx ×2
android-architecture-components ×1
geofencing ×1
jasmine ×1
javascript ×1
mithril.js ×1
ondraw ×1
rx-android ×1
rx-java ×1
rx-java2 ×1