Created
July 14, 2017 02:51
-
-
Save fanzeyi/a12b4cbfa23c9505f3a29eb69814e740 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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