substantial / sinon-stub-promise

Synchronous Promise stubbing for Sinon.JS
MIT License
85 stars 11 forks source link

Module doesn't load correctly when run through Karma in environments that aren't browsers. Window variable is not defined. #14

Closed Astridax closed 8 years ago

Astridax commented 8 years ago

The global window variable doesn't necessarily exist in all environments, for example Nativescript where Karma runs tests in a non-browser environment.

Offending code:

if (typeof module !== 'undefined' && module.exports) {
  module.exports = setup;
} else if (window.sinon) {
  setup(window.sinon);
}

Proposed change

if (typeof module !== 'undefined' && module.exports) {
  module.exports = setup;
} else if (typeof window !== 'undefined') {
    if(typeof window.sinon !== 'undefined') setup(window.sinon);
} else {
    if(typeof this.sinon !== 'undefined') setup(this.sinon);
}

I have implemented a code fix that I will submit as a pull request soon.

a-b-r-o-w-n commented 8 years ago

Sounds good. Look forward to the PR.