我写了下面的测试。但是当我运行它时,我得到一个错误,说jasmine.createSpy不是一个函数。
import MyNode, {MqttOptions, IMessageReceivedCallBack, MyTopic, MyDataType,MyMessage} from '../../src/main/MyNode';
import {expect} from 'chai';
var mqtt: any = require('mqtt');
var jasmine = require('jasmine');
describe('MyNode Test Suite',() => {
let myNode: MyNode;
let mqttOptions: MqttOptions;
let messageReceivedCallBack: IMessageReceivedCallBack;
let willMessage = {
topic: 'WillMessage',
payload: 'This is the last will message',
qos: 2,
retain: 'true'
};
mqttOptions = {
clientId: '100',
protocolId: 'MQTT',
protocolVersion: 4,
keepAlive: 1000,
clean: false,
reconnectPeriod: '1000',
will: willMessage
};
messageReceivedCallBack = {
onMessageReceived(message: MyMessage) {
console.log('Message was received :D ' + message.payload);
}
};
it('Should call the connect method when constructor is called', () => {
mqtt.connect = jasmine.createSpy('beforeeachthing');
myNode = new MyNode('tcp://localhost:1883', mqttOptions, messageReceivedCallBack);
jasmine.expect(mqtt.connect).to.have.been.called;
});
});
这里有什么问题?我是新来的。请指教。