I'm new to testing with sinon, and I'm a little bit confused here on how I could test all three types of the return values (Moto
, Sedan
, and Vehicle
) with stub or maybe less preferrably spy. Could anybody help me on this ?
transportType.js
export function transportType() {
if (isMoto()) {
return 'Moto';
} else if (isSedan()) {
return 'Sedan';
} else {
return 'Vehicle';
}
}
function isMoto() {
return window.matchMedia('only screen and (max-device-width: 700px)').matches;
}
function isSedan() {
return window.matchMedia(
'only screen and (min-device-width: 800px) and (max-device-width: 1000px)'
).matches;
}
carType_test.js
import {assert} from 'chai';
import sinon from 'sinon';
import * as transportTypes from './transportType';
describe('transportType', () => {
it('returns "Moto" if width matches', () => {
sinon.stub(transportTypes, 'transportType')
})
})