作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的单元测试有问题 <ion-item-sliding>
ionic2 成分。我在下面附上了我的组件、测试和错误
组件
import {Component,Input} from 'angular2/core'
import {IONIC_DIRECTIVES} from 'ionic-angular'
@Component({
selector: 'my-item',
// template: `<ion-item>{{name}}</ion-item>`, //<ion-item> is working
template: `<ion-item-sliding>{{name}}</ion-item-sliding>`, //<ion-item-sliding> is not working and throws the error;
directives:[IONIC_DIRECTIVES]
})
export class MyIonic2Component {
public name:string;
}
测试
import {describe, it, expect, beforeEach,beforeEachProviders,inject,injectAsync,TestComponentBuilder,ComponentFixture} from 'angular2/testing';
import {provide} from 'angular2/core'
import {MyIonic2Component} from '../../app/test'
//Required for compiling ionic components
import {Form, IonicApp, Config, ClickBlock, List, ItemSliding} from 'ionic-angular'
import {ElementRef, NgZone} from 'angular2/core';
describe('basics', function(){
let component:any;
beforeEachProviders(() => [
provide( Config, {useValue: new Config()} ),
Form, IonicApp, ClickBlock, ElementRef,
provide( NgZone, {useValue: new NgZone({enableLongStackTrace : false})} ),
List, ItemSliding
] );
beforeEach(injectAsync([TestComponentBuilder], tcb => {
return tcb.createAsync( MyIonic2Component )
.then(f => {
let myIonic2Component : MyIonic2Component = f.componentInstance;
myIonic2Component.name = 'Mark';
f.detectChanges();
component = f.debugElement.nativeElement;
console.log(component);
});
}));
it('should have a valid object as the component', function() {
expect(component).toBeDefined();
});
});
这是我在模板包含 <ion-item-sliding>
时遇到的错误,但我没有收到其他 ionic 组件的任何错误。
Failed: EXCEPTION: Error during instantiation of List! (ItemSliding -> List)
.
ORIGINAL EXCEPTION: unimplemented
ERROR CONTEXT:
[object Object]
_instantiate@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11742:87 <-
webpack:///~/angular2/src/core/di/injector.js:841:0
_instantiateProvider@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:1161
6:38 <- webpack:///~/angular2/src/core/di/injector.js:715:0
_new@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11605:42 <- webpack:
///~/angular2/src/core/di/injector.js:704:0
getObjByKeyId@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11215:55 <-
webpack:///~/angular2/src/core/di/injector.js:314:0
_getByKeyDefault@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11822:51
<- webpack:///~/angular2/src/core/di/injector.js:921:0
_getByKey@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11768:42 <- web
pack:///~/angular2/src/core/di/injector.js:867:0
_getByDependency@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11754:35
<- webpack:///~/angular2/src/core/di/injector.js:853:0
_instantiate@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11644:53 <-
webpack:///~/angular2/src/core/di/injector.js:743:0
_instantiateProvider@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:1161
6:38 <- webpack:///~/angular2/src/core/di/injector.js:715:0
_new@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11605:42 <- webpack:
///~/angular2/src/core/di/injector.js:704:0
instantiateProvider@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:11105
:35 <- webpack:///~/angular2/src/core/di/injector.js:204:0
init@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:23955:44 <- webpack:
///~/angular2/src/core/linker/element.js:558:0
AppElement@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:23632:33 <- we
bpack:///~/angular2/src/core/linker/element.js:235:0
viewFactory_MyIonic2Component0
viewFactory_HostMyIonic2Component0
createRootHostView@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:25002:
48 <- webpack:///~/angular2/src/core/linker/view_manager.js:93:0
C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:22960:69 <- webpack:///~/
angular2/src/core/linker/dynamic_component_loader.js:102:0
run@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:6777:30 <- webpack://
/~/zone.js/dist/zone-microtask.js:1217:0
zoneBoundFn@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:6754:30 <- we
bpack:///~/zone.js/dist/zone-microtask.js:1194:0
lib$es6$promise$$internal$$tryCatch@C:/Users/MARK/ionic2project/test/spec/spec
-bundle.js:6002:26 <- webpack:///~/zone.js/dist/zone-microtask.js:442:0
lib$es6$promise$$internal$$invokeCallback@C:/Users/MARK/ionic2project/test/spe
c/spec-bundle.js:6014:54 <- webpack:///~/zone.js/dist/zone-microtask.js:454:0
lib$es6$promise$$internal$$publish@C:/Users/MARK/ionic2project/test/spec/spec-
bundle.js:5985:54 <- webpack:///~/zone.js/dist/zone-microtask.js:425:0
C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:5657:13 <- webpack:///~/z
one.js/dist/zone-microtask.js:97:0
run@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:6777:30 <- webpack://
/~/zone.js/dist/zone-microtask.js:1217:0
zoneBoundFn@C:/Users/MARK/ionic2project/test/spec/spec-bundle.js:6754:30 <- we
bpack:///~/zone.js/dist/zone-microtask.js:1194:0
lib$es6$promise$asap$$flush@C:/Users/MARK/ionic2project/test/spec/spec-bundle.
js:5796:19 <- webpack:///~/zone.js/dist/zone-microtask.js:236:0
这是我得到的控制台日志,如果我输入 <ion-item>
而不是 <ion-item-sliding>
<div id="root0">
<ion-item class="item">
<div class="item-inner">
<!--template bindings={}-->
<ion-label>Mark</ion-label>
</div>
<ion-button-effect></ion-button-effect>
</ion-item>
</div>
最佳答案
来自 ionic 文档要使用滑动项,请添加 <ion-item-sliding>
列表中的组件。接下来,在滑动项内添加一个组件以包含按钮。
请将滑动项目包裹在列表中。
template: `<ion-list><ion-item-sliding>{{name}}</ion-item-sliding></ion-list>`
你的模板结构应该是这样的
<ion-list>
<ion-item-sliding>
<ion-item>
</ion-item>
<ion-item-options>
</ion-item-options>
</ion-item-sliding>
</ion-list>
关于jasmine - List 实例化期间出错! (ItemSliding -> List),使用 TestComponentBuilder 对 ionic2 组件进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125705/
你能告诉我为什么我看不到 Me 按钮吗?我用过ItemSliding 这是 stackblitz .请查看 home 文件夹。 我想创建以下类型的列表: 用户界面 .html
我想要一个可以滑动以显示archive 按钮的列表项。 图标应位于文本的左侧。 我在这里关注文档(按钮布局):https://ionicframework.com/docs/api/component
我的单元测试有问题 ionic2 成分。我在下面附上了我的组件、测试和错误 组件 import {Component,Input} from 'angular2/core' import {IONI
我是一名优秀的程序员,十分优秀!