Testing modules

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.

Methods

expectModuleToBeCalledWith(method, ...args)

  • method
    • Type: String
    • required
    • Available values are addPlugin, addLayout, addErrorLayout, addServerMiddleware and requireModule
  • args
    • optional
    • Additional parameters that are expected to be passed to the tested 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
    • Type: String
    • required
    • Available values are addPlugin, addLayout, addErrorLayout, addServerMiddleware and requireModule
  • args
    • optional
    • Additional parameters that are expected to be passed to the tested method

Expect a specific method not to be triggered while installing a module.

test('should inject plugin', () => {
  expectModuleNotToBeCalledWith('addLayout')
})