Skip to content

Commit

Permalink
Add test for new target
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwiebell committed Mar 18, 2021
1 parent 8440cb6 commit 1eac198
Showing 1 changed file with 47 additions and 0 deletions.
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} />",
]
`);
});

0 comments on commit 1eac198

Please sign in to comment.