Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using should as function issue #13

Open
killmenot opened this issue Nov 9, 2017 · 1 comment
Open

Using should as function issue #13

killmenot opened this issue Nov 9, 2017 · 1 comment

Comments

@killmenot
Copy link

Hi,

When I use should the following way:

var sinon = require('sinon');
var should = require('should');
require('./should-sinon');

var callback = sinon.spy();
callback.should.not.be.called();

All works as expected. However, when I use should as function, the adapter works not as expected

var sinon = require('sinon');
var should = require('should/as-function');
require('./should-sinon');

var callback = sinon.spy();
should(callback)not.be.called(); // throws callback.called is not a function

The problem is that adapter use should by default here https://github.com/shouldjs/sinon/blob/master/should-sinon.js#L1-L9

@killmenot
Copy link
Author

@btd

I have some ideas how to fix this issue but before creating a PR would like to know your thoughts about it.

  1. The first idea is to switch from:
var sinon = require('sinon');
var should = require('should');
require('should-sinon');

to

var sinon = require('sinon');
var should = require('should');
require('should-sinon')(should);
// or
var sinon = require('sinon');
var should = require('should/as-function');
require('should-sinon')(should);

But, ofc, this is breaking change.

  1. The second idea is to keep using current way but provide developers with ability to call shouldSinon adapter for custom object when it's needed.
// should-sinon
(function (factory) {
  if (typeof define === 'function' && define.amd) {
    define(['should'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(require('should'));
  } else {
    factory(should);
  }
}(function (should) {
  function init (should) => {
     // initialization logic
  };
  
  init(should);
  
  return init;
});
// still work
var sinon = require('sinon');
var should = require('should');
require('should-sinon');

// this also will work
var sinon = require('sinon');
var should = require('should/as-function');
var shouldSinon = require('should-sinon');
shouldSinon(should);

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant