How to use simple-mock - 10 common examples

To help you get started, we’ve selected a few simple-mock 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 GoogleChromeLabs / gulliver / test / app / lib / tasks.js View on Github external
it('push a task', () => {
      // Mock bd to avoid making real calls
      simpleMock.mock(db, 'update').resolveWith(task);
      simpleMock.mock(libTasks, 'db').returnWith(db);
      return libTasks.push(task).should.be.fulfilled.then(savedTask => {
        assert.equal(savedTask.pwaId, 123456789);
        assert.equal(db.update.callCount, 1);
      });
    });
  });
github GoogleChromeLabs / gulliver / test / app / lib / tasks.js View on Github external
it('push a task', () => {
      // Mock bd to avoid making real calls
      simpleMock.mock(db, 'update').resolveWith(task);
      simpleMock.mock(libTasks, 'db').returnWith(db);
      return libTasks.push(task).should.be.fulfilled.then(savedTask => {
        assert.equal(savedTask.pwaId, 123456789);
        assert.equal(db.update.callCount, 1);
      });
    });
  });
github tcdl / msb / test / unit / support / serviceDetails.ts View on Github external
it("should handle a valid package.json without version and name fields", function (done) {
    let path = join(__dirname, "..", "_fixtures", "package.json");
    let pkg = require(path);

    simple.mock(pkg, "name", undefined);
    simple.mock(pkg, "version", undefined);

    simple.mock(process, "mainModule", {paths: [path]});

    serviceDetails = require(serviceDetailsModulePath);

    expect(serviceDetails.name).equals(undefined);
    expect(serviceDetails.version).equals(undefined);
    expect(serviceDetails.instanceId).length(24);

    done();
  });
github tcdl / msb / test / unit / support / serviceDetails.ts View on Github external
it("should handle a valid package.json without version and name fields", function (done) {
    let path = join(__dirname, "..", "_fixtures", "package.json");
    let pkg = require(path);

    simple.mock(pkg, "name", undefined);
    simple.mock(pkg, "version", undefined);

    simple.mock(process, "mainModule", {paths: [path]});

    serviceDetails = require(serviceDetailsModulePath);

    expect(serviceDetails.name).equals(undefined);
    expect(serviceDetails.version).equals(undefined);
    expect(serviceDetails.instanceId).length(24);

    done();
  });
github tcdl / msb / test / unit / support / serviceDetails.ts View on Github external
it("should set some of serviceDetails by environment variables", function (done) {
    simple.mock(process, "mainModule", {paths: [join(__dirname, "_fixtures", "package.json")]});

    simple.mock(process.env, "MSB_SERVICE_NAME", "special-name");
    simple.mock(process.env, "MSB_SERVICE_VERSION", "999");
    simple.mock(process.env, "MSB_SERVICE_INSTANCE_ID", "abc123");

    serviceDetails = require(serviceDetailsModulePath);

    expect(serviceDetails.name).equals("special-name");
    expect(serviceDetails.version).equals("999");
    expect(serviceDetails.instanceId).equals("abc123");

    done();
  });
});
github tcdl / msb / test / unit / support / serviceDetails.ts View on Github external
it("should set some of serviceDetails by environment variables", function (done) {
    simple.mock(process, "mainModule", {paths: [join(__dirname, "_fixtures", "package.json")]});

    simple.mock(process.env, "MSB_SERVICE_NAME", "special-name");
    simple.mock(process.env, "MSB_SERVICE_VERSION", "999");
    simple.mock(process.env, "MSB_SERVICE_INSTANCE_ID", "abc123");

    serviceDetails = require(serviceDetailsModulePath);

    expect(serviceDetails.name).equals("special-name");
    expect(serviceDetails.version).equals("999");
    expect(serviceDetails.instanceId).equals("abc123");

    done();
  });
});
github tcdl / msb / test / unit / config.ts View on Github external
it("should load JSON config file", function (done) {
        simple.mock(process.env, "MSB_CONFIG_PATH", join(__dirname, "_fixtures", "sample_config.json"));

        config._init();

        expect(config.configurationTestValue).equals(12345);

        done();
      });
github GoogleChromeLabs / gulliver / test / app / controllers / tasks.js View on Github external
it('respond with 200 when X-Appengine-Cron is present', done => {
      simpleMock.mock(tasksLib, 'push').resolveWith(null);
      simpleMock.mock(pwaLib, 'list').resolveWith(listPwas);
      request(app)
        .get('/updateunscored')
        .set(APP_ENGINE_CRON, true)
        .expect(200).should.be.fulfilled.then(_ => {
          assert.equal(pwaLib.list.callCount, 1);
          assert.equal(tasksLib.push.callCount, 1);
          done();
        });
    });
  });
github GoogleChromeLabs / gulliver / test / app / lib / tasks.js View on Github external
it('execute a task', () => {
      const modulePath = require.resolve('../../../lib/pwa');
      const task = new Task(987654321, modulePath, 'createOrUpdatePwa', 1);
      simpleMock.mock(libPwa, 'find').resolveWith(pwa);
      simpleMock.mock(libPwa, 'createOrUpdatePwa').resolveWith(pwa);
      simpleMock.mock(libTasks, 'push').resolveWith(task);
      return libTasks.executePwaTask(task).should.be.fulfilled.then(executedTask => {
        assert.equal(libPwa.find.callCount, 1);
        assert.equal(libPwa.createOrUpdatePwa.callCount, 1);
        assert.equal(executedTask.pwaId, 987654321);
        assert.equal(libTasks.push.callCount, 0);
        assert.equal(executedTask.retries, 1);
      });
    });
    it('retry a task', () => {
github GoogleChromeLabs / gulliver / test / app / controllers / cache.js View on Github external
it('Page from cache', done => {
      simpleMock.mock(libCache, 'get').resolveWith('PageFromCache');
      simpleMock.mock(libCache, 'set').resolveWith();
      request(app)
        .get('/')
        .expect(200).should.be.fulfilled.then(res => {
          assert.equal(libCache.get.callCount, 1);
          assert.equal(res.text, 'PageFromCache');
          done();
        });
    });

simple-mock

Super simple stubs and spies with 1-step sandbox restore

MIT
Latest version published 8 years ago

Package Health Score

50 / 100
Full package analysis

Popular simple-mock functions