@webext-core/fake-browser does not depend on a specific testing framework, it will work with all of them.
Setup is simple: import @webext-core/fake-browser/auto before importing the webextension-polyfill. No need to mock any modules!
import '@webext-core/fake-browser/auto';
@webext-core/fake-browser/auto just assigns the global chrome and browser variables to fakeBrowser. This is enough to make the polyfill think it's already in a browser environment with a browser variable, making the polyfill a noop.
Below are some examples for how to do this in major testing frameworks.
Add @webext-core/fake-browser/auto to your vitest.config.ts file as a setup file:
// vitest.config.ts
export default defineConfig({
test: {
setupFiles: ['@webext-core/fake-browser/auto'],
},
});
Add @webext-core/fake-browser/auto to your jest.config.js file as a setup file:
// jest.config.js
module.exports = {
setupFiles: ['@webext-core/fake-browser/auto'],
};
Add @webext-core/fake-browser/auto to your bunfig.toml as a preload file:
[test]
preload = ['@webext-core/fake-browser/auto']