Integration with test frameworks Download code

Ogma can work with the most testing frameworks out there. But in order to make it run in headless mode, you need to make the node-canvas or canvas-prebuilt library available to it, to mock the rendering.

Mocha

 npm install --save-dev mocha chai canvas
 mocha tests/**/*.test.js
const Ogma = require('@linkurious/ogma');
const { assert } = require('chai');

describe ('dummy suite', () => {

  it ('dummy test', () => {
    const ogma = new Ogma();
    return ogma.setGraph({
      nodes: [{ id: 0 }, { id: 1 }],
      edges: [{ source: 0, target: 1 }]
    }).then(() => {
      assert.equal(ogma.getNodes().size, 2);
    });
  });
});

Jest

 npm i --save-dev jest canvas
 jest

Alternatively, you can use other canvas-mock library, like jest-canvas-mock, and set it up to be included in the setup.

const Ogma = require('@linkurious/ogma');

describe ('dummy suite', () => {

  test ('dummy test', () => {
    const ogma = new Ogma();
    return ogma.setGraph({
      nodes: [{ id: 0 }, { id: 1 }],
      edges: [{ source: 0, target: 1 }]
    }).then(() => {
      expect(ogma.getNodes().size).toBe(2);
    });
  });
});

Jasmine

 npm i --save-dev jasmine
 jasmine
const Ogma = require('@linkurious/ogma');

describe ('dummy suite', () => {

  it ('dummy test', () => {
    const ogma = new Ogma();
    return ogma.setGraph({
      nodes: [{ id: 0 }, { id: 1 }],
      edges: [{ source: 0, target: 1 }]
    }).then(() => {
      expect(ogma.getNodes().size).toBe(2);
    });
  });
});