I'm using SinonJS, Mocha and chai for my unit tests.
I want to know if it's possible to mock the value of a variable or the return of a function with Sinon.
Imagine I have this:
testeA.ts
const getA = () => 20
export function test() {
const valA = getA();
const result = valA * 2;
return result;
}
Is it possible to mock the value returned by getA() and/or valA value inside my tests? Maybe use the mock instead of the actual method.
myTest.spec.ts
import * as test from './testeA'
import * as chai from 'chai'
import * as sinon from 'sinon'
const expect = chai.expect
describe('First Test', () => {
it('should run the test', () => {
const myMock = sinon.mock('test') // Mock the function
// MOck the values somehow
expect(test.test()).to.be.equal(30)
})
})