2016-07-28 113 views
0

對於我的測試,Am使用mocha,enzyme,sinon用於存根,chai用於斷言,mockery用於嘲諷模塊。用於單元測試的RN中的嘲諷導航器

現在什麼是最好的機制來模擬導航地理定位。我嘗試從https://github.com/jhnns/rewirerewire注入我的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

回答

0

而不是mocha-jsdom一個錯誤,我用this.jsdom = require('jsdom-global')() 那似乎修復它。