0
對於我的測試,Am使用mocha
,enzyme
,sinon
用於存根,chai
用於斷言,mockery
用於嘲諷模塊。用於單元測試的RN中的嘲諷導航器
現在什麼是最好的機制來模擬導航地理定位。我嘗試從https://github.com/jhnns/rewire
rewire
注入我的sinon stubed導航器。這對我來說很有用,但只是覺得設置存根很麻煩。 我喜歡https://github.com/2gis/mock-geolocation,因爲它感覺更自然的嘲笑方式。但不幸的是我無法使用它,因爲它使用window
變量。
我試圖用mocha-jsdom
像
import jsdom from 'mocha-jsdom';
jsdom();
const geolocate = require('mock-geolocation');
但我得到這樣
/..../node_modules/mock-geolocation/src/geolocate.js:225
})(window, navigator);
^
ReferenceError: window is not defined
at Object.<anonymous> (/like
/..../node_modules/mock-geolocation/src/geolocate.js:225:4)
at Module._compile (module.js:409:26)
我跑我的測試是這樣mocha --require react-native-mock/mock --compilers js:babel-register --recursive