Skip to content

Instantly share code, notes, and snippets.

@fanzeyi
Created July 14, 2017 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanzeyi/a12b4cbfa23c9505f3a29eb69814e740 to your computer and use it in GitHub Desktop.
Save fanzeyi/a12b4cbfa23c9505f3a29eb69814e740 to your computer and use it in GitHub Desktop.
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