fix unit tests
This commit is contained in:
parent
ca7506c5f0
commit
40af664c50
@ -2,7 +2,7 @@ import CommandsManager from './CommandsManager.js';
|
|||||||
import HotkeysManager from './HotkeysManager.js';
|
import HotkeysManager from './HotkeysManager.js';
|
||||||
import hotkeys from './../utils/hotkeys';
|
import hotkeys from './../utils/hotkeys';
|
||||||
import log from './../log.js';
|
import log from './../log.js';
|
||||||
import objectHash from "object-hash";
|
import objectHash from 'object-hash';
|
||||||
|
|
||||||
jest.mock('./CommandsManager.js');
|
jest.mock('./CommandsManager.js');
|
||||||
jest.mock('./../utils/hotkeys');
|
jest.mock('./../utils/hotkeys');
|
||||||
@ -10,6 +10,9 @@ jest.mock('./../log.js');
|
|||||||
|
|
||||||
describe('HotkeysManager', () => {
|
describe('HotkeysManager', () => {
|
||||||
let hotkeysManager, commandsManager;
|
let hotkeysManager, commandsManager;
|
||||||
|
beforeAll(() => {
|
||||||
|
hotkeys.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
commandsManager = new CommandsManager();
|
commandsManager = new CommandsManager();
|
||||||
@ -19,7 +22,6 @@ describe('HotkeysManager', () => {
|
|||||||
log.warn.mockClear();
|
log.warn.mockClear();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has expected properties', () => {
|
it('has expected properties', () => {
|
||||||
const allProperties = Object.keys(hotkeysManager);
|
const allProperties = Object.keys(hotkeysManager);
|
||||||
const expectedProprties = [
|
const expectedProprties = [
|
||||||
@ -122,11 +124,16 @@ describe('HotkeysManager', () => {
|
|||||||
const definition = { commandName: undefined, keys: '+' };
|
const definition = { commandName: undefined, keys: '+' };
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
hotkeysManager.registerHotkeys(definition)
|
hotkeysManager.registerHotkeys(definition);
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it('updates hotkeyDefinitions property with registered keys', () => {
|
it('updates hotkeyDefinitions property with registered keys', () => {
|
||||||
const definition = { commandName: 'dance', commandOptions: {}, label: 'hello', keys: '+', };
|
const definition = {
|
||||||
|
commandName: 'dance',
|
||||||
|
commandOptions: {},
|
||||||
|
label: 'hello',
|
||||||
|
keys: '+',
|
||||||
|
};
|
||||||
|
|
||||||
hotkeysManager.registerHotkeys(definition);
|
hotkeysManager.registerHotkeys(definition);
|
||||||
|
|
||||||
@ -136,13 +143,15 @@ describe('HotkeysManager', () => {
|
|||||||
|
|
||||||
const commandHash = objectHash({
|
const commandHash = objectHash({
|
||||||
commandName: definition.commandName,
|
commandName: definition.commandName,
|
||||||
commandOptions: definition.commandOptions
|
commandOptions: definition.commandOptions,
|
||||||
});
|
});
|
||||||
const hotkeyDefinitionForRegisteredCommand =
|
const hotkeyDefinitionForRegisteredCommand =
|
||||||
hotkeysManager.hotkeyDefinitions[commandHash];
|
hotkeysManager.hotkeyDefinitions[commandHash];
|
||||||
|
|
||||||
expect(numOfHotkeyDefinitions).toBe(1);
|
expect(numOfHotkeyDefinitions).toBe(1);
|
||||||
expect(Object.keys(hotkeysManager.hotkeyDefinitions)[0]).toEqual(commandHash);
|
expect(Object.keys(hotkeysManager.hotkeyDefinitions)[0]).toEqual(
|
||||||
|
commandHash
|
||||||
|
);
|
||||||
expect(hotkeyDefinitionForRegisteredCommand).toEqual(definition);
|
expect(hotkeyDefinitionForRegisteredCommand).toEqual(definition);
|
||||||
});
|
});
|
||||||
it('calls hotkeys.bind for the group of keys', () => {
|
it('calls hotkeys.bind for the group of keys', () => {
|
||||||
|
|||||||
@ -11,4 +11,21 @@ Mousetrap.initialize = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// These are only here so that Jest mocks them properly before .initialize() is called
|
||||||
|
Mousetrap.handleKey = () =>
|
||||||
|
console.debug('Mousetrap recordPlugin not yet initialized');
|
||||||
|
Mousetrap.startRecording = () =>
|
||||||
|
console.debug('Mousetrap recordPlugin not yet initialized');
|
||||||
|
Mousetrap.stopRecording = () =>
|
||||||
|
console.debug('Mousetrap recordPlugin not yet initialized');
|
||||||
|
Mousetrap.record = () =>
|
||||||
|
console.debug('Mousetrap recordPlugin not yet initialized');
|
||||||
|
|
||||||
|
Mousetrap.stopCallback = () =>
|
||||||
|
console.debug('Mousetrap pausePlugin not yet initialized');
|
||||||
|
Mousetrap.pause = () =>
|
||||||
|
console.debug('Mousetrap pausePlugin not yet initialized');
|
||||||
|
Mousetrap.unpause = () =>
|
||||||
|
console.debug('Mousetrap pausePlugin not yet initialized');
|
||||||
|
|
||||||
export default Mousetrap;
|
export default Mousetrap;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user