我正在为一个使用browserify管理的模块编写测试。这是我想要测试的模块(具体来说,我想要测试calculateData
函数):
require('mapbox.js');
var utils = require('./src/chart_utils');
var dashboard = {
calculateData: function(data) {
// functions to test
}
};
我已经开始写一个像这样的测试:
我已开始编写以下测试:
var expect = require('chai').expect;
var Dashboard = require('../dashboard');
// describe('Dashboard', function () {
// describe('#convertData', function () {
// it('should calculate the x and y value', function () {
// var combinedData = [];
// var data = Dashboard.convertData(combinedData);
// expect(data.length).to.equal(2); // etc
// });
// });
// });
但是即使前两行也给我一个错误:
node_modules/mapbox.js/node_modules/leaflet/dist/leaflet-src.js:513
ua = navigator.userAgent.toLowerCase(),
^
ReferenceError: navigator is not defined
看起来它正在测试所有包含的模块文件,并找到了一个错误。
有没有办法绕过这个问题,只测试dashboard
中的函数?
navigator
对象(默认附加到全局window
对象上)。 - MarcoL