Installations
npm install nuxt-test-utils
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.16.3
NPM Version
6.14.4
Score
41
Supply Chain
84.5
Quality
67.2
Maintenance
50
Vulnerability
94.1
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
richardeschloss
Download Statistics
Total Downloads
3,277
Last Day
1
Last Week
2
Last Month
27
Last Year
423
GitHub Statistics
4 Stars
17 Commits
1 Forks
1 Watching
3 Branches
2 Contributors
Bundle Size
5.46 kB
Minified
2.28 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.1
Package Id
nuxt-test-utils@0.0.1
Unpacked Size
11.05 kB
Size
4.55 kB
File Count
8
NPM Version
6.14.4
Node Version
12.16.3
Total Downloads
Cumulative downloads
Total Downloads
3,277
Last day
0%
1
Compared to previous day
Last week
-91.3%
2
Compared to previous week
Last month
80%
27
Compared to previous month
Last year
27.4%
423
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
nuxt-test-utils
Nuxt testing utils (a single home for all your favorite testing utils).
Some of these utils may help your tests shave off many minutes of run time!
Installation
npm i -D nuxt-test-utils
- Module Utilities
getModuleOptions
ModuleContext
- Plugin Utilities
compilePlugin
PluginContext
- Wait Utilities
delay
nextTickP
watchP
This package will come with:
- Required dependencies:
- lodash.template - to compile ERB templates
- serialize-javascript - also for compiling ERB templates; alternative to JSON.stringify. Only used if your plugin uses
serialize
.
- Optional dependencies: (but highly recommended!)
- @nuxtjs/module-test-utils - Additional testing utilities for modules
- @vue/test-utils - Test utils for Vue components
- jsdom-global - Required by @vue/test-utils
- jsdom-global - Required by @vue/test-utils
- browser-env - Usually required when it is desired to have a browser-like environment in Node.js.
Usage
Suppose your nuxt.config is set up like this:
1module.exports = { 2 modules: ['./lib/module.js'], 3 myModOpts: { } // NOTE: example purposes only! Use a name best suited for *your* module! 4}
1import TestUtils from 'nuxt-test-utils' 2// or, just pick the utils you need 3import { getModuleOptions, ModuleContext, PluginContext } from 'nuxt-test-utils' 4import config from '@/nuxt.config' // optional, but useful for utilities. 5import path from 'path' 6import Module from '@/lib/module' 7 8const ctx = new ModuleContext({ 9 options: getModuleOptions(config, 'myModOpts'), 10 module: Module, 11 compileOpts: { 12 src: path.resolve('./lib/plugin.js'), 13 tmpFile: path.resolve('./lib/plugin.compiled.js'), 14 overwrite: true 15 } 16}) 17 18// Finally, load the module 19ctx.registerModule() 20 21// Check if the plugin got added: 22t.truthy(ctx.pluginAdded) // ava 23expect(ctx.pluginAdded).toBeTruthy() // jest
Utilities
Module Utilities
getModuleOptions(config, moduleName, optsContainer)
:
- Params:
- config: Object - provide nuxt.config
- moduleName: String
- optsContainer: Object - specify the container holding your options. defaults to moduleName. Options will be searched in this order: buildModules, then modules, then your optsContainer. As options are found, they'll be merged in.
- Returns: module options
ModuleContext({ options, module, compileOpts })
:
- Params:
- options: Object - module options
- module: Object - module instance
- compileOpts: Object - compile options to be used for adding the plugin (see plugin utils)
- Actions:
- addTemplate: If
this.addTemplate
were used by the module, this simply mocks the function. It setsthis.templateAdded
with the template options provided. addPlugin
: Ifthis.addPlugin
were used by the module, this actually compiles the plugin using the compileOpts provided toModuleContext
. It also setsthis.pluginAdded
with the plugin options provided.compilePlugin
: it also wires up compilePlugin to the ModuleContext, in case you need to use it yourselfregisterModule
: It registers the module with the providedoptions
toModuleContext
.
- addTemplate: If
Plugin Utilities
compilePlugin({ src, tmpFile, options, overwrite })
- Params:
src
: String - plugin source filenametmpFile
: String - filename to save the compiled plugin tooptions
: Object - plugin options; i.e., where <%= JSON.stringify(options) %> exists, that will be replaced by the options specified here.overwrite
: Boolean - overwrite the compiled plugin if it already exists. Default:false
.
- Returns: none
PluginContext(Plugin)
- Params:
Plugin
- Object - plugin function, usually the export default from your plugin.js file. It usually wraps around an injector.
- Actions:
- Plugin context is instantiated with the
new
operator - If the plugin.js calls
inject
, a mockinject
will be called and setthis.injected[label]
to the object that the plugin is injecting.
- Plugin context is instantiated with the
Wait utilities
delay(ms)
- promisified delay...nothing fancy, just a wrapper aroundsetTimeout
that you canawait
on.nextTickP(ctx)
- promisified wrapper aroundctx.$nextTick
. Lets you doawait nextTickP(ctx)
for cleaner code.watchP(ctx, prop, changesFn)
- promisified wrapper aroundctx.$watch
so you canawait watchP(ctx, 'someData', () => { ctx.someData = 123 })
. It will resolve once the data has changed.
Suggested Prep and Reading
Getting your test environment set up correctly for Nuxt is more than half the battle. Even though test environment is technically beyond the scope of this repo, to avoid having issues being opened on this topic, here are some bullets that may help:
-
When you first create a Nuxt app using create-nuxt-app, you are asked for choice of test framework. Try running that sample code first before proceeding. If you skipped the test framework selection, you can have a look at their templates and start with those, most likely for ava or jest.
-
Alternatively, you may find it just as useful to clone Vinayak's repo: https://github.com/vinayakkulkarni/nuxt-ava-e2e-unit-testing
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 1/15 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
1.7
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to nuxt-test-utils
@nuxt/test-utils
Test utilities for Nuxt
@nuxt/test-utils-edge
[![Nuxt banner](./.github/assets/banner.svg)](https://nuxt.com)
@nuxt/test-utils-nightly
Test utilities for Nuxt
nuxt-i18n-micro-test-utils
This is a utility library designed to facilitate testing for Nuxt.js applications that use the `nuxt-i18n-micro-core` package. It provides helper functions to handle translations, formatting, and locale switching, simplifying the process of testing intern