Authored by 周奇琪

base.js的单元测试

... ... @@ -13,6 +13,8 @@ sdk.start({
group: 1,
inventoryTime: 400, //设置盘点时长
power: [15, 0, 0, 0] //功率设置
}, function(connected, data) {
console.log(data);
}, function(err, connected, data) {
if (connected) {
console.log(data);
}
});
\ No newline at end of file
... ...
import expect from 'expect.js';
import muk from 'muk';
import Base from '../../src/lib/directive/base';
import rewire from 'rewire';
describe('base.js', function() {
describe('init', function() {
it();
it('init expect have reproc & proc', function() {
let base = new Base()
expect(base.reproc).to.eql({});
expect(base.proc).to.eql({});
});
});
describe('send', function() {
it();
it('input find expect OK', function(done) {
let base = new Base();
base.reproc.test = function(callback) {
callback('test');
return 'test';
};
let connect = {
send: function(order) {
return order;
},
client: {
remoteAddress: '1.1.1.1'
}
};
base.send(connect, {
input: 'test'
}, function(order) {
expect(order).to.be('test');
done();
})
});
});
describe('receive', function() {
it();
it('input "" expect undefined ', function() {
let base = new Base();
expect(base.receive('', '')).to.be(undefined);
});
it('input [] epxect undefined', function() {
let base = new Base();
expect(base.receive('', [])).to.be(undefined);
});
it('input [111] expect ok', function() {
let base = new Base();
base.proc.test = function() {
return 'test';
}
Base.__set__('locateOrder', function() {
return {
name: 'test'
}
});
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.receive('', [111])).to.be('test');
});
it('input [111] expect ok', function() {
let base = new Base();
Base.__set__('locateOrder', function() {
return {
name: 'test'
}
});
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.receive('', [111])).to.be('test');
});
});
describe('procFunc', function() {
it();
it('input "" client test expect test', function() {
let base = new Base();
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.procFunc('', {
remoteAddress: '1.1.1.1'
}, 'test')).to.be('test');
});
});
});
\ No newline at end of file
... ...
import expect from 'expect.js';
import muk from 'muk';
import info from '../../src/lib/interface';
import Config from '../../src/lib/directive/Config';
import Config from '../../src/lib/directive/config';
describe('config.js', function() {
describe('init', function() {
... ...