Skip to content

Commit

Permalink
chore: Went half way through the test for the entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
orangevolon committed Jan 13, 2025
1 parent 9abf2ce commit aae87eb
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/converter/test/generate-test-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { readFileSync, writeFileSync } from 'fs';
import { describe, test, expect, beforeAll, beforeEach, vi } from 'vitest';
import { convertToSelectorUtil } from '../convert-to-selectors';
import { generateTestUtils } from '../generate-test-utils';
import { ComponentMetadata } from '../interfaces';

vi.mock('fs');
vi.mock('../convert-to-selectors');

const mockComponents: ComponentMetadata[] = [
{
name: 'Alert',
pluralName: 'Alerts',
testUtilsFolderName: '../test-utils',
},
];

describe(`${generateTestUtils.name}`, () => {
beforeAll(() => {
vi.mocked(readFileSync).mockReturnValue('file content');
vi.mocked(convertToSelectorUtil).mockImplementation(input => input);
});

beforeEach(() => {
vi.clearAllMocks();
});

test('generates the selector utils for the given dom utils', () => {
generateTestUtils({
components: mockComponents,
testUtilsPath: './test/mock-test-utils',
});

expect(convertToSelectorUtil).toHaveBeenCalledWith('file content');
});

const testUtilsType = ['dom', 'selectors'] as const;
test.each(testUtilsType)('generates the index file for %s test utils', testUtilType => {
generateTestUtils({
components: mockComponents,
testUtilsPath: './test/mock-test-utils',
});

const testUtilsFilePartialContent = 'ElementWrapper.prototype.findAlert';

expect(writeFileSync).toHaveBeenCalledWith(
`test/mock-test-utils/${testUtilType}/index.ts`,
expect.stringMatching(testUtilsFilePartialContent)
);
});
});

0 comments on commit aae87eb

Please sign in to comment.