【发布时间】:2019-01-21 22:55:00
【问题描述】:
我有一个让 userAgent 检测设备是计算机还是移动设备的测试,但是当我运行测试时出现 CORS 错误。
这是测试代码:
it('should detect if device is mobile', () => {
// Custom user agent
window.navigator['__defineGetter__']('userAgent', function() {
return 'Mozilla/5.0 (Linux; Android 9; PH-1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Mobile Safari/537.36';
});
// component.getDevice();
// fixture.detectChanges();
const mobile = fixture.debugElement.query(By.css('div.dl-sidebar-backdrop.mobile'));
expect(mobile).toBeTruthy();
});
我进行了研究,但没有找到与此问题相关的任何信息。
【问题讨论】:
标签: angular unit-testing jasmine karma-jasmine angular7