Skip to content

Commit

Permalink
refactor(review): stub.use withArgs()
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Mar 13, 2024
1 parent 4a2545d commit 86d21a6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
19 changes: 8 additions & 11 deletions test/unit/demutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ describe('DemUtils', function () {
const ELEVATION = 300;

before(function () {
stubSuppFetcher = sinon.stub(supportedFetchers, 'get')
.callsFake((format) => {
if (format === 'image/x-bil;bits=32') {
const floatArray = createBilData(ELEVATION);
stubSuppFetcher = sinon.stub(supportedFetchers, 'get');
stubSuppFetcher.withArgs('image/x-bil;bits=32')
.callsFake(() => {
const floatArray = createBilData(ELEVATION);

const texture = new THREE.DataTexture(floatArray, 256, 256, THREE.RedFormat, THREE.FloatType);
texture.internalFormat = 'R32F';
texture.needsUpdate = false;
return () => Promise.resolve(texture);
} else {
throw new Error(`format (${format}) non supported`);
}
const texture = new THREE.DataTexture(floatArray, 256, 256, THREE.RedFormat, THREE.FloatType);
texture.internalFormat = 'R32F';
texture.needsUpdate = false;
return () => Promise.resolve(texture);
});

const source = new WMTSSource({
Expand Down
11 changes: 3 additions & 8 deletions test/unit/featuregeometrylayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ describe('Layer with Feature process', function () {
let stubSuppFetcher;

before(function () {
stubSuppFetcher = sinon.stub(supportedFetchers, 'get')
.callsFake((format) => {
if (format === 'application/json') {
return () => Promise.resolve(JSON.parse(feature));
} else {
throw new Error(`format (${format}) non supported`);
}
});
stubSuppFetcher = sinon.stub(supportedFetchers, 'get');
stubSuppFetcher.withArgs('application/json')
.callsFake(() => () => Promise.resolve(JSON.parse(feature)));

const source = new FileSource({
url: 'https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/departements/09-ariege/departement-09-ariege.geojson',
Expand Down
11 changes: 3 additions & 8 deletions test/unit/geoidlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ describe('GlobeView', function () {

before(function () {
const buffer = createGtxBuffer(ELEVATION);
stubSuppFetcher = sinon.stub(supportedFetchers, 'get')
.callsFake((format) => {
if (format === 'application/gtx') {
return () => Promise.resolve(buffer);
} else {
throw new Error(`format (${format}) non supported`);
}
});
stubSuppFetcher = sinon.stub(supportedFetchers, 'get');
stubSuppFetcher.withArgs('application/gtx')
.callsFake(() => () => Promise.resolve(buffer));

const url = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/altitude-conversion-grids/RAF20_float.gtx';

Expand Down
11 changes: 3 additions & 8 deletions test/unit/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,9 @@ describe('Sources', function () {
describe('FileSource', function () {
let stubSuppFetcher;
before(function () {
stubSuppFetcher = sinon.stub(supportedFetchers, 'get')
.callsFake((format) => {
if (format === 'application/json') {
return () => Promise.resolve(JSON.parse(fileSource));
} else {
throw new Error(`format (${format}) non supported`);
}
});
stubSuppFetcher = sinon.stub(supportedFetchers, 'get');
stubSuppFetcher.withArgs('application/json')
.callsFake(() => () => Promise.resolve(JSON.parse(fileSource)));
});

after(function () {
Expand Down

0 comments on commit 86d21a6

Please sign in to comment.