How to use the lolex.install function in lolex

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 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 }
}
github derhuerst / inspect-code / index.js View on Github external
if (expressions[i]) {
			const result = Object.create(expressions[i])
			result.value = value
			result.isException = false
			result.when = Date.now()
			results.push(result);
		}
		return value
	}



	const ctx = sandbox()
	ctx[nameOfSpy] = spy

	const clock = lolex.install({
		target: ctx,
		now: Date.now(),
		toFake: [
			'setTimeout', 'clearTimeout',
			'setInterval', 'clearInterval',
			'setImmediate', 'clearImmediate',
			'Date'
		],
		loopLimit: 100
	})

	const instrumented = generate(ast)

	try {
		const script = new vm.Script(instrumented, {filename: 'inspect-code'})
		script.runInContext(vm.createContext(ctx))

lolex

Fake JavaScript timers

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis