Add a custom resolver so that we can require our own project files
ADD
jest-cordova-resolver.js
+var Resolver = require('jest-resolve');
+var path = require('path');
+var fs = require('fs');
+
+var pluginModuleRegex = /^cordova-plugin-googlemaps\.(.*)/;
+var pathBrowser = './src/browser';
+var pathWww = './www';
+
+module.exports = function(moduleId, options) {
+ if (pluginModuleRegex.test(moduleId)) {
+ var fileName = moduleId.match(pluginModuleRegex)[1] + '.js';
+ if (fs.existsSync(path.resolve(pathBrowser, fileName))) {
+ return path.resolve(pathBrowser, fileName);
+ }
+ if (fs.existsSync(path.resolve(pathWww, fileName))) {
+ return path.resolve(pathWww, fileName);
+ }
+
+ throw new Error(moduleId + 'could not be located');
+ }
+ return Resolver.findNodeModule(moduleId, options);
+};

MODIFY
jest.config.js
jest.config.js
@@ -2,6 +2,7 @@ module.exports = {
moduleNameMapper: {
'^cordova/(.*)$': '<rootDir>/node_modules/cordova-js/src/common/$1',
},
+ resolver: './jest-cordova-resolver.js',
globals: {
cordova: {},
},

ADD
src/browser/__test__/PluginMap.spec.js
+const PluginMap = require('../PluginMap');
+
+describe('PluginMap', () => {
+ it('should exist', () => {
+ expect(PluginMap).toBeDefined();
+ });
+
+ describe('toDataURL', () => {
+ afterEach(() => {
+ document.body.innerHTML = '';
+ });
+
+ it('should exist', () => {
+ var mapId = 'map';
+ document.body.innerHTML = '<div __pluginMapId="' + mapId + '"></div>';
+ expect(new PluginMap(mapId, {}).toDataURL).toBeDefined();
+ });
+ });
+});

Add a custom resolver so that we can require our own project files