Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

stubbing/testing esm 3.2.4 #728

Closed
jamessouth opened this issue Feb 15, 2019 · 3 comments
Closed

stubbing/testing esm 3.2.4 #728

jamessouth opened this issue Feb 15, 2019 · 3 comments
Labels

Comments

@jamessouth
Copy link

Hello, I've been through #712 and #727, but I can't fix my testing issue. It seems similar, except I'm using a default export. I have tried to stub but I can't find a way that works. Test repo here

yarn and yarn test, it will fail. comment out the import statement in main.js and it will pass...??? I'm testing main w/o an argument, so it isn't even using the import, just having the import statement causes a fail. How to fix?

main.js

import doSomething from './doSomething'; // comment out to pass, uncomment out to fail

export default async function main(arg) {
  try {
    if (!arg) {
      throw new Error('An arg is needed.');
    }
    console.log(await doSomething(arg));
  } catch (err) {
    console.log(err.message);
  }
}

control.test.js

import test from 'ava';
import sinon from 'sinon';
import main from './main';

function setupSpy() {
  sinon.spy(console, 'log');
}

function tearDownSpy() {
  console.log.restore();
}

test('test main - no arg - log error msg', async t => {
  setupSpy();
  // let stub = sinon.stub(main);
  // await stub();
  await main();
  t.true(console.log.callCount == 1);
  tearDownSpy();
  // stub.restore();
});
@jdalton
Copy link
Member

jdalton commented Feb 15, 2019

Dup of #727.

Follow-up patch: c7dc293; Test ac5752d;

Update:

Thanks for the report @jamessouth!
Fixing #727 plus the follow-up patch should resolve your issue.

@jamessouth
Copy link
Author

ok looking forward to it, thank you so much @jdalton!!! 😊

@jdalton jdalton added bug and removed duplicate labels Feb 16, 2019
@jdalton
Copy link
Member

jdalton commented Feb 16, 2019

v3.2.5 is released 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants