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
String
required
addPlugin
, addLayout
, addErrorLayout
, addServerMiddleware
and requireModule
args
optional
method
Expect 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
String
required
addPlugin
, addLayout
, addErrorLayout
, addServerMiddleware
and requireModule
args
optional
method
Expect a specific method not to be triggered while installing a module.
test('should inject plugin', () => {
expectModuleNotToBeCalledWith('addLayout')
})