我有一个测试,让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();
});
这就是错误:
我做了一项研究,但没有发现任何与这个问题有关的信息。