Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-06-2021 01:42 AM
What is the recommended way to mock a database session in a node unit test? It needs to be very light weight to work with CI.
04-06-2021 03:27 AM
I'm currently writing a Graph App with Angular and the JS Driver.
I ended up writing this piece of code to mock the driver, session and transaction function:
const stubReactiveSession = <T>(results: Observable<T>): [jasmine.SpyObj<Driver>, jasmine.SpyObj<RxSession>] => {
const driverSpy = jasmine.createSpyObj('driver', ['rxSession']);
const rxSessionSpy = jasmine.createSpyObj('rxSession', ['readTransaction', 'close']);
rxSessionSpy.readTransaction.and.returnValue(results);
rxSessionSpy.close.and.stub();
driverSpy.rxSession.and.returnValue(rxSessionSpy);
return [driverSpy, rxSessionSpy];
};
I use it as such:
import {Observable, of} from 'rxjs';
[...]
let driverSpy: jasmine.SpyObj<Driver>;
let rxSessionSpy: jasmine.SpyObj<RxSession>;
[...]
[driverSpy, rxSessionSpy] = stubReactiveSession(of(new MyObject(...)));
That's more concise than I expected and works well in our case.
04-07-2021 12:33 AM
Not bad Thanks @florent.biville1!
I suppose I could do a similar thing in ava using sinon...
06-09-2021 06:20 AM
I have just released a package on npm that makes mocking neo4j-driver
really easy in node: neo-forgery.
You can (in your code with console statements or in the data browser) capture query results and then set up a mock Session
object that you can use in testing.
@William_Lyon / @william.lyon and @michael.hunger please check it out!
All the sessions of the conference are now available online