I'm setting up test for my nodejs-cli app, and there's two tests, when I invoke function, which returns a object and do a destructuring assignment in one case it works properly in other in returns a object.
describe('a credential manager', () => {
var creds
before(() => {
creds = new CredentialManger('twitup-test')
})
context('with no existing credentials', () => {
it('should prompt the user', async () => {
sinon.stub(inquirer, 'prompt').resolves({key: 'foo', secret: 'bar', accessSecret: 'shot', accessToken: 'batch'})
let [key, secret, accessSecret, accessToken] = await creds.getKeyAndSecret() // HERE IT IS
expect(key).to.equal('foo')
expect(secret).to.equal('bar')
expect(accessSecret).to.equal('shot')
expect(accessToken).to.equal('batch')
expect(inquirer.prompt.calledOnce).to.be.true
inquirer.prompt.restore()
})
})
context('with existing credentials', () => {
it('should just return them', async () => {
let [key, secret, accessSecret, accessToken] = await creds.getKeyAndSecret() // AND THERE IS NOT
expect(key).to.equal('foo')
expect(secret).to.equal('bar')
expect(accessSecret).to.equal('shot')
expect(accessToken).to.equal('batch')
})
})
Output
a credential manager
with no existing credentials
✓ should prompt the user (61ms)
with existing credentials
1) should just return them
1 passing (271ms)
1 failing
1) a credential manager
with existing credentials
should just return them:
AssertionError: expected { Object (key, secret, ...) } to equal 'foo'
at Context.<anonymous> (test/credential-manager.js:27:28)
It is works fine then I destructure an array of one object in second context
let [{key, secret, accessSecret, accessToken}] = await creds.getKeyAndSecret()
Why this is happening? What the difference between those calls?
Aucun commentaire:
Enregistrer un commentaire