-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Went half way through the test for the entry file
- Loading branch information
1 parent
9abf2ce
commit aae87eb
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
}); | ||
}); |