Move the XRefMock in the unit tests to a central location

This patch helps to avoid code duplication for this mock since more unit
tests are depending on it.
This commit is contained in:
Tim van der Meij 2017-07-29 00:35:10 +02:00
parent 783d42ec2b
commit ab820438ae
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
5 changed files with 39 additions and 80 deletions

View file

@ -16,34 +16,9 @@
import {
Cmd, Dict, isCmd, isDict, isName, isRef, isRefsEqual, Name, Ref, RefSet
} from '../../src/core/primitives';
import { XRefMock } from './test_utils';
describe('primitives', function() {
function XRefMock(array) {
this.map = Object.create(null);
for (var elem in array) {
var obj = array[elem];
var ref = obj.ref, data = obj.data;
this.map[ref.toString()] = data;
}
}
XRefMock.prototype = {
fetch(ref) {
return this.map[ref.toString()];
},
fetchIfRef(obj) {
if (!isRef(obj)) {
return obj;
}
return this.fetch(obj);
},
fetchAsync(ref) {
return Promise.resolve(this.fetch(ref));
},
fetchIfRefAsync(obj) {
return Promise.resolve(this.fetchIfRef(obj));
},
};
describe('Name', function() {
it('should retain the given name', function() {
var givenName = 'Font';