Skip to content

Commit

Permalink
Mock ComunicaUpdateEngine.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Feb 8, 2019
1 parent 653d9bb commit e807c45
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 0 additions & 2 deletions test/ComunicaUpdateEngine-test.js
Expand Up @@ -7,8 +7,6 @@ describe('a ComunicaUpdateEngine instance', () => {

it('does not yet support source objects', () => {
engine = new ComunicaUpdateEngine('http://example.org', { dummy: 'source' });
// parameter doesn't get added due to mocks
engine._source = { dummy: 'source' };
expect(() => engine.executeUpdate('')).toThrow();
});

Expand Down
1 change: 1 addition & 0 deletions test/SubjectPathResolver-test.js
Expand Up @@ -3,6 +3,7 @@ import SubjectPathResolver from '../src/SubjectPathResolver';
import ComunicaUpdateEngine from '../src/ComunicaUpdateEngine';

jest.mock('ldflex');
jest.mock('../src/ComunicaUpdateEngine');

describe('a SubjectPathResolver', () => {
const source = {};
Expand Down
13 changes: 8 additions & 5 deletions test/__mocks__/ldflex-comunica.js
@@ -1,6 +1,9 @@
const ComunicaEngine = jest.genMockFromModule('ldflex-comunica').default;
export default class ComunicaEngineMock {
constructor(subject, source) {
this._source = source;
}

async function* noResults() { /* empty */ }
ComunicaEngine.prototype.execute.mockReturnValue(noResults());

export default ComunicaEngine;
getDocument() {
return 'https://example.org/';
}
}
10 changes: 7 additions & 3 deletions test/index-test.js
@@ -1,8 +1,12 @@
import data from '../src';
import auth from 'solid-auth-client';
import ComunicaEngine from 'ldflex-comunica';
import ComunicaUpdateEngine from '../src/ComunicaUpdateEngine';
import { namedNode } from '@rdfjs/data-model';

jest.mock('../src/ComunicaUpdateEngine');
async function* noResults() { /* empty */ }
ComunicaUpdateEngine.prototype.execute = jest.fn(noResults);

describe('The @solid/ldflex module', () => {
it('is an ES6 module with a default export', () => {
expect(require('../src').default).toBe(data);
Expand All @@ -19,7 +23,7 @@ describe('The @solid/ldflex module', () => {
});

it('executes the query', () => {
const { constructor, execute } = ComunicaEngine.prototype;
const { constructor, execute } = ComunicaUpdateEngine.prototype;
expect(constructor).toHaveBeenCalledTimes(1);
expect(constructor.mock.calls[0][0]).toEqual(namedNode(url));
expect(execute).toHaveBeenCalledTimes(1);
Expand All @@ -43,7 +47,7 @@ describe('The @solid/ldflex module', () => {
});

it('executes the query', async () => {
const { constructor, execute } = ComunicaEngine.prototype;
const { constructor, execute } = ComunicaUpdateEngine.prototype;
expect(constructor).toHaveBeenCalledTimes(1);
await expect(constructor.mock.calls[0][0]).resolves.toEqual(namedNode(webId));
expect(execute).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit e807c45

Please sign in to comment.