How to use lolex - 10 common examples

To help you get started, we’ve selected a few lolex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scality / Arsenal / tests / unit / auth / v4 / headerAuthCheck.js View on Github external
it('should successfully return v4 and no error', done => {
        // Freezes time so date created within function will be Feb 8, 2016
        const clock = lolex.install(1454962445000);
        const res = headerAuthCheck(request, log);
        clock.uninstall();
        assert.strictEqual(res.err, null);
        assert.strictEqual(res.params.version, 4);
        done();
    });
});
github szmarczak / http2-wrapper / test / helpers / server.js View on Github external
return async (t, run) => {
		const create = (options && options.createServer) || createServer;

		const clock = options && options.lolex ? lolex.install() : lolex.createClock();

		const server = await create(options);
		await server.listen();

		// Useful to fix uncaught exceptions:
		// console.log(`${server.options.port} - ${t.title}`);

		try {
			await run(t, server, clock);
		} finally {
			if (options && options.beforeServerClose) {
				options.beforeServerClose();
			}

			clock.runAll();
github mcibique / vue-testing-examples / src / views / Login.vue.spec.js View on Github external
beforeEach(function () {
    this.axios = new AxiosMockAdapter(axios);

    this.localVue = createLocalVue();
    this.store = createStore(this.localVue);
    container.bind(STORE_ID).toConstantValue(this.store);

    this.router = createRouter(this.localVue);
    container.bind(ROUTER_ID).toConstantValue(this.router);

    // mocking setTimeout, clearTimeout global function and enable time traveling
    let globalMock = {};
    this.clock = lolex.install({ target: globalMock, toFake: ['setTimeout', 'clearTimeout'] });
    container.rebind(GLOBAL_ID).toConstantValue(globalMock);

    this.mountLoginView = function (options) {
      let wrapper = mount(LoginView, { localVue: this.localVue, router: this.router, store: this.store, ...options });
      return new LoginViewPageObj(wrapper);
    };

    this.router.push({ name: 'login' });

    return flushPromises();
  });
github ealmansi / set-interval-async / test / dynamic.js View on Github external
beforeEach(async () => {
    clock = lolex.install()
    Promise = BluebirdPromise
    Promise.setScheduler((fn) => fn())
  })
github moleculerjs / moleculer / test / unit / metrics / reporters / event.spec.js View on Github external
beforeAll(() => {
			clock = lolex.install({ now: 12345678000 });

			broker = new ServiceBroker({
				logger: false,
				nodeID: "node-123",
				metrics: {
					reporter: {
						type: "Event",
						options: {
							eventName: "$metrics.custom",
							interval: 0,
							onlyChanges: true,
							broadcast: true,
							excludes: ["moleculer.node.versions.moleculer"]
						}
					}
				}
github ampproject / amphtml / test / unit / test-cookies.js View on Github external
beforeEach(() => {
    win = env.win;
    doc = win.document;
    clock = lolex.install({
      target: window,
      now: new Date('2018-01-01T08:00:00Z'),
    });
  });
github ampproject / amphtml / test / unit / test-render-delaying-services.js View on Github external
return createIframePromise().then(iframe => {
      win = iframe.win;
      clock = lolex.install({target: win});
    });
  });
github novemberborn / buoyant / test / lib / helpers / stub-helpers.js View on Github external
function stubTimers () {
  const timers = new Timers()
  const clock = installClock(timers, 0, ['clearInterval', 'setInterval', 'clearTimeout', 'setTimeout'])
  return { clock, timers }
}

lolex

Fake JavaScript timers

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

64 / 100
Full package analysis