-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/venia-ui/lib/targets/__tests__/CategoryListProductAttributes.spec.js
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,47 @@ | ||
const { | ||
mockTargetProvider | ||
} = require('@magento/pwa-buildpack/lib/TestHelpers'); | ||
const TargetableSet = require('@magento/pwa-buildpack/lib/WebpackTools/targetables/TargetableSet'); | ||
|
||
const CategoryListProductAttributes = require('../CategoryListProductAttributes'); | ||
|
||
const targets = mockTargetProvider( | ||
'@magento/venia-ui', | ||
(_, dep) => | ||
({ | ||
'@magento/pwa-buildpack': { | ||
specialFeatures: { | ||
tap: jest.fn() | ||
}, | ||
transformModules: { | ||
tapPromise: jest.fn() | ||
} | ||
} | ||
}[dep]) | ||
); | ||
const targetable = TargetableSet.using(targets); | ||
|
||
const mockImportName = 'ImportedComponent'; | ||
const mockInsertAfterJSX = jest.fn(); | ||
|
||
beforeAll(() => { | ||
jest.spyOn(targetable, 'reactComponent').mockImplementation(() => ({ | ||
addImport: () => mockImportName, | ||
insertAfterJSX: mockInsertAfterJSX | ||
})); | ||
}); | ||
|
||
test('inserts component after provided matcher', () => { | ||
const target = new CategoryListProductAttributes(targetable); | ||
target.insertAfterJSX({ | ||
matcher: 'SomeComponent', | ||
importStatement: 'import Woof from "./dog.js"' | ||
}); | ||
|
||
expect(mockInsertAfterJSX.mock.calls[0]).toMatchInlineSnapshot(` | ||
Array [ | ||
"SomeComponent", | ||
"<ImportedComponent item={props.item} />", | ||
] | ||
`); | ||
}); |