angular - 角度测试用例变量使用没有问题
问题描述
我是 angular 新手,对 ismobile 方法的测试有一些疑问。以下是 homecompoonent.ts 上的部分代码:
ngOnInit(): void {
this.mapService.mapLoaded$.subscribe(
state => {
this.loadingState = state;
}
);
if (!this.isMobile || this.selectedView === 'map') {
this.mapService.canLoadMap$.next(true);
} else { this.mapService.triggerMapLoadedTransition(); }
this.filterService.canLoadFilter$.next(true);
}
I am trying to test the partialMapService to return to true when !ismobile but couldn't make it work. here's the code so far:
fit(`should push a true value in the partialMapService`, () => {
!(component.isMobile);
fixture.detectChanges();
partialMapService.canLoadMap$.subscribe((val) => {
expect(val).toEqual(true);
})
});
I'm not sure !(component.isMobile) is not the way to put it there but it's expecting null value which is not correct. what is the right way to test ismobile to return canLoadMap to true?
解决方案
推荐阅读
- python - 如何在python中使用shapefile重叠(马赫)和剪辑雷达图像
- docker - 如何通过 PPP 而不是 veth 将两个 netns 连接在一起?
- javascript - Next.js“out”文件夹 html 文件缺少一些组件
- r - 无法安装 R 包 FIRM
- laravel - {{ auth()->user()->email }} / {{ Auth::user()->email }} 在 x 组件中不起作用
- python - 数据框中的下一项列表
- javascript - 表示输出图像的 JavaScript 或 HTML 的数据 URI?
- php - 如何让 $_GET 使用你想要的值?
- java - 从 InputStream Java 中读取和写入未压缩的 Zip 数据
- node.js - 是否可以在 Microsoft Teams 的轮播中使用全宽自适应卡片?