I am trying to test a FromEvent(rxjs) with socket.io
and in the fromEvent i got always the following data:
["some message","undefined"]
whatever I did it always send the undefined message
its works good when I use the server.on instaed of fromEvent
my FromEvent code:
onStudent(): Observable<Student> {
return fromEvent<Student>(this.server, 'students').pipe(map(student => someFunc(student));
}
someFunc(student:Student){
here i got the undefined wired message from student var
["some message","undefined"]
}
also happen for sample one:
onTest(): Observable<any> {
return fromEvent(this.server, 'test1')
}
the return is ['message',undefined]
my test code
import SocketMock from 'socket.io-mock';
it.only('should emit and recivie', async done => {
const studentObsService = //...getStudentService
const socket = new SocketMock();
socketMock.getSocket = jest.fn(() => Promise.resolve(socket));
await studentObsService.init();
let count = 0;
studentObsService.onStudent().subscribe((value: Student) => {
console.log(value) // should compare the value with what we sent
expect(true).toEqual(true);
});
await socket.socketClient.emit('students', 'some message');
await new Promise(resolve => setTimeout(resolve, 1000));
done();
});
Aucun commentaire:
Enregistrer un commentaire