我正在爲我的電子js應用程序編寫單元測試,而且我被困在一個地方。如何在電子模擬需求js
例如
比方說我的應用程序代碼是像下面
var app= (function() {
function app() {
var _this = this;
this.open = function (data) {
var deferred = Q.defer();
try {
// some code
}
catch (ex) {
deferred.reject(ex);
}
return deferred.promise;
};
}
}());
exports.app = app
現在,如果我想電子客戶端上運行它,它將會運行完美的罰款作爲電子模塊安裝客戶端的PC上
問題是,當我試圖編寫上述單元測試用例,因爲在下面的開發機器上沒有安裝電子設備
import { app} from '../../app'
import { Rights } from '../../Rights'
describe('app',() => {
let app: app;
beforeEach(() => {
app= new app();
})
it('should call open() and return error for null content', function (done) {
let output = app.open(null);
output
.then((res) => {
//expectation
done();
})
.catch((err)=>{
//expectation
done();
})
})
})
獲得以下錯誤
Error: Cannot find module 'electron'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (<project pat>/app.js:2:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Test failed. See above for more details.
問題
- 如何嘲笑要求對未安裝dev的PC 上,但實際執行所需的任何模塊(安裝在客戶的電腦上) 。
用一些小的變化你的解決方案.. :) –