Skip to content

onInitialDrawComplete does not trigger in tests #1511

Open
@schoeneu

Description

@schoeneu

I am trying to test my application which uses vis-timeline and the onInitialDrawComplete configuration option, but the callback is apparently never called.

I can reproduce this within the vis-timeline repro by adapting Timeline.test.js as follows. Running npm test then makes the assertion fail, i.e. the callback is not called. Dependency versions etc: latest master (c653cbc56).

This feels like a bug to me; am I missing something?

import assert from "assert";
import jsdom_global from "jsdom-global";
import { DataSet } from "vis-data/esnext";
import Timeline from "../lib/timeline/Timeline";

const internals = {};

describe("Timeline", () => {
  before(() => {
    internals.jsdom = jsdom_global({
      pretendToBeVisual: true,
    });
    global["Element"] = window.Element;
    global["requestAnimationFrame"] = (cb) => {
      cb();
    };
  });

  after(() => {
    internals.jsdom();
  });

  it("should call the onInitialDrawComplete callback", (done) => {
    let complete = 0;
    const timeline = new Timeline(document.createElement("div"), [], [], {
      onInitialDrawComplete: () => {
        complete = 1;
      },
    });

    const events = [
      { start: new Date(), id: 1 },
      { start: new Date(), id: 2 },
    ];

    timeline.setItems(new DataSet(events));

    setTimeout(() => {
      assert(complete === 1);
      done();
    }, 1000);
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions