Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Hello {
constructor(foo, bar) {
this.foo = foo;
this.bar = bar;
}
otherfun() {
return 1;
}
somefun() {
if (this.otherfun() === 1) {
return this.foo;
}
if (Hello.magic() === 2) {
return this.bar;
}
return null;
}
static magic() {
return 2;
}
}
describe('$SUITE$ Hello', () => {
let hello;
let sandbox;
beforeEach(() => {
hello = new Hello('foo', 'bar');
sandbox = sinon.sandbox.create({
useFakeServer: true,
});
});
afterEach(() => {
sandbox.verifyAndRestore();
});
it('other funshould return 1', function() {
assert(hello.otherfun() === 1);
});
it('somefun should return foo', function() {
assert(hello.somefun() === 'foo');
});
it('somefun should return bar', function() {
sandbox.stub(hello, 'otherfun').returns(2);
assert(hello.somefun() === 'bar');
});
it('somefun should return null', () => {
const other = sandbox.stub(hello, 'otherfun').returns(2);
const magic = sandbox.stub(Hello, 'magic').returns(3);
assert(hello.somefun() === null);
sinon.assert.callOrder(other, magic);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.