From 8c67c38a4f476ff5be938db6b6b3ee9ac6b44db5 Mon Sep 17 00:00:00 2001 From: nlf Date: Tue, 15 Dec 2020 09:05:59 -0800 Subject: [PATCH] add tests for set command PR-URL: https://github.com/npm/cli/pull/2354 Credit: @nlf Close: #2354 Reviewed-by: @ruyadorno --- test/lib/set.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/lib/set.js diff --git a/test/lib/set.js b/test/lib/set.js new file mode 100644 index 0000000000000..aeb239e9c4e39 --- /dev/null +++ b/test/lib/set.js @@ -0,0 +1,33 @@ +const { test } = require('tap') +const requireInject = require('require-inject') + +let configArgs = null +const npm = { + commands: { + config: (args, cb) => { + configArgs = args + return cb() + }, + }, +} + +const set = requireInject('../../lib/set.js', { + '../../lib/npm.js': npm, +}) + +test('npm set - no args', t => { + return set([], (err) => { + t.match(err, /npm set/, 'prints usage') + t.end() + }) +}) + +test('npm set', t => { + return set(['email', 'me@me.me'], (err) => { + if (err) + throw err + + t.strictSame(configArgs, ['set', 'email', 'me@me.me'], 'passed the correct arguments to config') + t.end() + }) +})