Open stroiman opened 8 years ago
I'm seeing this issue when implementing Mocha's shared behaviors. However, I also have the issue when I use dispatch:mocha
as the driver-package.
Hello @PeteProgrammer I was able to reproduce the problem only in the server, but something interesting happen when I used the arrow function ( () =>{}
) instead of the normal function, It works as expected, so as a workaround you can try use the arrow function (even so the official mocha documentation says no).
This is working for me:
beforeEach(() => {
this.sinon = sinon.sandbox.create();
});
afterEach(() => {
this.sinon.restore(); // here this.sinon is undefined
});
it('does something with sinon', =>() {
this.sinon.mock(obj).expect("foo"); // here this.sinon is undefined
});
Maybe the next release is going to be fixed.
When adding data to mocha's context, the data disappears, or the context is reset. For example, I commonly use this pattern when testing node.js code, but it doesn't work in meteor: