You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

75 lines
2.3 KiB

import { messageProcessor } from "./main.js";
import { jest } from '@jest/globals'
test('should fire error message with empty message', () => {
console.error = jest.fn();
var errorMessage = "Got mallformed message:";
var errorParams = { action: undefined, data: undefined };
messageProcessor.processMessage();
expect(console.error).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should fire error message with empty string', () => {
console.error = jest.fn();
var errorMessage = "Got mallformed message:";
var errorParams = { action: undefined, data: undefined };
messageProcessor.processMessage("");
expect(console.error).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should fire error message with null', () => {
console.error = jest.fn();
var errorMessage = "Got mallformed message:";
var errorParams = { action: undefined, data: undefined };
messageProcessor.processMessage(null);
expect(console.error).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should fire error message with undefined', () => {
console.error = jest.fn();
var errorMessage = "Got mallformed message:";
var errorParams = { action: undefined, data: undefined };
messageProcessor.processMessage(undefined);
expect(console.error).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should fire error message about mallformed message', () => {
console.error = jest.fn();
var message = {};
var errorMessage = "Got mallformed message:";
var errorParams = { action: undefined, data: undefined };
messageProcessor.processMessage(message);
expect(console.error).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should fire log message if no action presents', () => {
console.log = jest.fn();
var message = { action: "do something" };
var errorMessage = "No actions for message:";
var errorParams = { action: "do something", data: undefined };
messageProcessor.processMessage(message);
expect(console.log).toHaveBeenCalledWith(errorMessage, errorParams);
});
test('should call action', () => {
var result = 0;
var message = {
action: "do something"
};
messageProcessor.actions = {
"do something": function() {
result = 1;
}
};
messageProcessor.processMessage(message);
expect(result).toBe(1);
});