Skip to content

Commit

Permalink
refactor: remove redundant mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GDamyanov committed Jan 31, 2025
1 parent 01e1b3c commit b189be9
Showing 1 changed file with 0 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type UI5Element from 'sap/ui/core/Element';
import { validateBindingModel } from '../../../../src/cpe/changes/validator';
import { getTextBundle } from '../../../../src/i18n';

jest.mock('../../../../src/i18n');

describe('vaildateBindingModel', () => {
const mockModifiedcontrol = {
Expand All @@ -15,38 +12,19 @@ describe('vaildateBindingModel', () => {
})
};

let getTextMock: jest.Mock;

beforeEach(() => {
getTextMock = jest.fn();

(getTextBundle as jest.Mock).mockResolvedValue({
hasText: jest.fn().mockReturnValue(true),
getText: getTextMock
});
});

afterEach(() => {
getTextMock.mockClear();
})

test('should throw when invalid binding model string is provided', async () => {
getTextMock.mockReturnValue('Invalid binding string.');
await expect(() => validateBindingModel(mockModifiedcontrol as unknown as UI5Element, '{}')).rejects.toThrow('Invalid binding string.');
});

test('should throw when invalid binding string for i18n model is provided', async () => {
getTextMock.mockReturnValue('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
await expect(() => validateBindingModel(mockModifiedcontrol as unknown as UI5Element, '{ i18n }')).rejects.toThrow('Invalid binding string. Supported value pattern is {i18n>YOUR_KEY}');
});

test('should throw when the provided key does not exist in i18n.properties', async () => {
getTextMock.mockReturnValue('Invalid key in the binding string. Supported value pattern is {i18n>YOUR_KEY}. Check if the key already exists in i18n.properties.If not, add the key in the i18n.properties file and reload the editor for the new key to take effect.');
await expect(() => validateBindingModel(mockModifiedcontrol as unknown as UI5Element, '{ i18n>test }')).rejects.toThrow('Invalid key in the binding string. Supported value pattern is {i18n>YOUR_KEY}. Check if the key already exists in i18n.properties.If not, add the key in the i18n.properties file and reload the editor for the new key to take effect.');
});

test('should throw error when invalid binding model is provided', async () => {
getTextMock.mockReturnValue('Invalid binding model.');
const control = {
getModel: jest.fn().mockReturnValue(undefined)
};
Expand Down

0 comments on commit b189be9

Please sign in to comment.