Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { createElement } from '@lwc/engine-dom';
import LscMobileInline_SimpleWidget from 'c/lscMobileInline_SimpleWidget';

// Mock the lightning/barcodeScanner module
jest.mock('lightning/barcodeScanner', () => {
// Mock the lightning/mobileCapabilities module (the component imports getBarcodeScanner from it)
jest.mock('lightning/mobileCapabilities', () => {
return {
scan: jest.fn().mockImplementation(() => Promise.resolve({ value: '12345' })),
BarcodeScanner: jest.fn()
getBarcodeScanner: jest.fn().mockImplementation(() => ({
isAvailable: jest.fn().mockReturnValue(false),
beginCapture: jest.fn().mockImplementation(() => Promise.resolve({ value: '12345' })),
endCapture: jest.fn()
}))
};
}, { virtual: true });

Expand Down
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config');

module.exports = {
...jestConfig,
modulePathIgnorePatterns: ['<rootDir>/.localdevserver']
modulePathIgnorePatterns: ['<rootDir>/.localdevserver'],
// Components live under PackageComponents/lwc, which is not a sfdx-project.json
// packageDirectory, so the default resolver can't map `c/*` imports to them.
moduleNameMapper: {
...(jestConfig.moduleNameMapper || {}),
'^c/(.+)$': '<rootDir>/PackageComponents/lwc/$1/$1'
}
};