How to expect test results
When you write tests for a Nuxt module, you normally expect the module to be installed with certain conditions. Below are some wrapper methods for easily validating module's testing result.
expectModuleToBeCalledWith(method, ...args)method
StringrequiredaddPlugin, addLayout, addErrorLayout, addServerMiddleware and requireModuleargs
optionalmethodExpect a specific method to be triggered while installing a module.
test('should inject plugin', () => {
expectModuleToBeCalledWith('addPlugin', {
src: expect.stringContaining('templates/plugin.js'),
fileName: 'myPlugin.js',
options: getNuxt().options.myModule
})
})
expectModuleNotToBeCalledWith(method, ...args)method
StringrequiredaddPlugin, addLayout, addErrorLayout, addServerMiddleware and requireModuleargs
optionalmethodExpect a specific method not to be triggered while installing a module.
test('should inject plugin', () => {
expectModuleNotToBeCalledWith('addLayout')
})