Skip to content

Commit

Permalink
fix: properties accessed on singleton now reflect current state of in…
Browse files Browse the repository at this point in the history
…stance (#1366)
  • Loading branch information
mleguen authored and bcoe committed Jul 13, 2019
1 parent 308b6a5 commit 409d35b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -25,8 +25,10 @@ function singletonify (inst) {
Object.keys(inst).forEach((key) => {
if (key === 'argv') {
Argv.__defineGetter__(key, inst.__lookupGetter__(key))
} else if (typeof inst[key] === 'function') {
Argv[key] = inst[key].bind(inst)
} else {
Argv[key] = typeof inst[key] === 'function' ? inst[key].bind(inst) : inst[key]
Argv.__defineGetter__(key, () => inst[key])
}
})
}
11 changes: 11 additions & 0 deletions test/yargs.js
Expand Up @@ -837,6 +837,17 @@ describe('yargs dsl tests', () => {
})
})

describe('parsed', () => {
it('should be false before parsing', () => {
yargs.parsed.should.equal(false)
})

it('should not be false after parsing', () => {
yargs.parse()
yargs.parsed.should.not.equal(false)
})
})

// yargs.parse(['foo', '--bar'], function (err, argv, output) {}
context('function passed as second argument to parse', () => {
it('does not print to stdout', () => {
Expand Down

0 comments on commit 409d35b

Please sign in to comment.