How to change the ua of jsdom in test file in jest

because there is logic in the code to determine whether it is a mobile phone / PC, so you need to change the ua in the test code to test. How can it be implemented?

Apr.18,2022

configure jest config testEnvironmentOptions.userAgent , refer to https://codeshelper.com/q/10.... Or use setupFiles , for example

Object.defineProperty(global.window.navigator, "userAgent", {
  writable: false, 
  value: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.4(0x17000428) NetType/4G Language/zh_CN"
});

I don't know if it's all right, but I haven't tested it.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea98ad-1f69.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea98ad-1f69.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?