mardi 9 février 2016

How to spy third-party library in sinon?

I am using third-party library to generate qrcodes. http://ift.tt/14uC5LL

I have a component, that adds div and runs javascript as stated in the docs: (I am using Ember, but I guess it doesn't matter)

new QRCode(document.querySelector(`#${this.elementId} .qrcode`), {
  text: url,
  height: height,
  width: height,
  correctLevel : QRCode.CorrectLevel.L 
});

And I want to test, if we are passing correctLevel. So in my test, I am doing as follows:

var spy = sinon.spy(QRCode);
//this.render(hbs`{{qrcode-image}}`);
new QRCode(document.querySelector(`.qrcode`),"http://ift.tt/1isBSQw");
assert.equal(spy.calledOnce, true);

I can comment line 3 and uncomment line 4, and my test still fails. spy is not called. (I added line 3 to better debug, it shows that there is something wrong in my spy declaration)

How should I spy this library?




Aucun commentaire:

Enregistrer un commentaire